Skip to content

Commit 8e6032d

Browse files
committed
bring back d3-esque method chains
... even though don't look bad to etpinard's 👀
1 parent e810c1e commit 8e6032d

File tree

9 files changed

+82
-69
lines changed

9 files changed

+82
-69
lines changed

src/components/colorbar/draw.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -246,18 +246,18 @@ module.exports = function draw(gd, id) {
246246

247247
// now draw the elements
248248
var container = Lib.ensureSingle(fullLayout._infolayer, 'g', id, function(s) {
249-
s.classed(cn.colorbar, true);
250-
s.each(function() {
251-
var s = d3.select(this);
252-
s.append('rect').classed(cn.cbbg, true);
253-
s.append('g').classed(cn.cbfills, true);
254-
s.append('g').classed(cn.cblines, true);
255-
s.append('g').classed(cn.cbaxis, true).classed(cn.crisp, true);
256-
s.append('g').classed(cn.cbtitleunshift, true)
257-
.append('g').classed(cn.cbtitle, true);
258-
s.append('rect').classed(cn.cboutline, true);
259-
s.select('.cbtitle').datum(0);
260-
});
249+
s.classed(cn.colorbar, true)
250+
.each(function() {
251+
var s = d3.select(this);
252+
s.append('rect').classed(cn.cbbg, true);
253+
s.append('g').classed(cn.cbfills, true);
254+
s.append('g').classed(cn.cblines, true);
255+
s.append('g').classed(cn.cbaxis, true).classed(cn.crisp, true);
256+
s.append('g').classed(cn.cbtitleunshift, true)
257+
.append('g').classed(cn.cbtitle, true);
258+
s.append('rect').classed(cn.cboutline, true);
259+
s.select('.cbtitle').datum(0);
260+
});
261261
});
262262

263263
container.attr('transform', 'translate(' + Math.round(gs.l) +

src/components/drawing/index.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -728,26 +728,26 @@ drawing.steps = function(shape) {
728728
// uses the id 'js-plotly-tester' and stores it in drawing.tester
729729
drawing.makeTester = function() {
730730
var tester = Lib.ensureSingleById(d3.select('body'), 'svg', 'js-plotly-tester', function(s) {
731-
s.attr(xmlnsNamespaces.svgAttrs);
732-
s.style({
733-
position: 'absolute',
734-
left: '-10000px',
735-
top: '-10000px',
736-
width: '9000px',
737-
height: '9000px',
738-
'z-index': '1'
739-
});
731+
s.attr(xmlnsNamespaces.svgAttrs)
732+
.style({
733+
position: 'absolute',
734+
left: '-10000px',
735+
top: '-10000px',
736+
width: '9000px',
737+
height: '9000px',
738+
'z-index': '1'
739+
});
740740
});
741741

742742
// browsers differ on how they describe the bounding rect of
743743
// the svg if its contents spill over... so make a 1x1px
744744
// reference point we can measure off of.
745745
var testref = Lib.ensureSingle(tester, 'path', 'js-reference-point', function(s) {
746-
s.attr('d', 'M0,0H1V1H0Z');
747-
s.style({
748-
'stroke-width': 0,
749-
fill: 'black'
750-
});
746+
s.attr('d', 'M0,0H1V1H0Z')
747+
.style({
748+
'stroke-width': 0,
749+
fill: 'black'
750+
});
751751
});
752752

753753
drawing.tester = tester;

src/components/legend/draw.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ module.exports = function draw(gd) {
7979
ry: 3,
8080
width: 0,
8181
height: 0
82-
});
83-
s.call(Color.fill, '#808BA4');
82+
})
83+
.call(Color.fill, '#808BA4');
8484
});
8585

8686
var groups = scrollBox.selectAll('g.groups')
@@ -426,9 +426,9 @@ function setupTraceToggle(g, gd) {
426426
numClicks = 1;
427427

428428
var traceToggle = Lib.ensureSingle(g, 'rect', 'legendtoggle', function(s) {
429-
s.style('cursor', 'pointer');
430-
s.attr('pointer-events', 'all');
431-
s.call(Color.fill, 'rgba(0,0,0,0)');
429+
s.style('cursor', 'pointer')
430+
.attr('pointer-events', 'all')
431+
.call(Color.fill, 'rgba(0,0,0,0)');
432432
});
433433

434434
traceToggle.on('mousedown', function() {

src/components/rangeselector/draw.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ function drawButtonText(button, selectorLayout, d, gd) {
148148
}
149149

150150
var text = Lib.ensureSingle(button, 'text', 'selector-text', function(s) {
151-
s.classed('user-select-none', true);
152-
s.attr('text-anchor', 'middle');
151+
s.classed('user-select-none', true)
152+
.attr('text-anchor', 'middle');
153153
});
154154

155155
text.call(Drawing.font, selectorLayout.font)

src/components/rangeslider/draw.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,22 @@ function filterRangePlotCalcData(calcData, subplotId) {
485485

486486
function drawMasks(rangeSlider, gd, axisOpts, opts, oppAxisRangeOpts) {
487487
var maskMin = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinClassName, function(s) {
488-
s.attr({ x: 0, y: 0 });
489-
s.attr('shape-rendering', 'crispEdges');
488+
s.attr({
489+
x: 0,
490+
y: 0,
491+
'shape-rendering': 'crispEdges'
492+
});
490493
});
491494

492495
maskMin
493496
.attr('height', opts._height)
494497
.call(Color.fill, constants.maskColor);
495498

496499
var maskMax = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxClassName, function(s) {
497-
s.attr('y', 0);
498-
s.attr('shape-rendering', 'crispEdges');
500+
s.attr({
501+
y: 0,
502+
'shape-rendering': 'crispEdges'
503+
});
499504
});
500505

501506
maskMax
@@ -505,17 +510,21 @@ function drawMasks(rangeSlider, gd, axisOpts, opts, oppAxisRangeOpts) {
505510
// masks used for oppAxis zoom
506511
if(oppAxisRangeOpts.rangemode !== 'match') {
507512
var maskMinOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinOppAxisClassName, function(s) {
508-
s.attr('y', 0);
509-
s.attr('shape-rendering', 'crispEdges');
513+
s.attr({
514+
y: 0,
515+
'shape-rendering': 'crispEdges'
516+
});
510517
});
511518

512519
maskMinOppAxis
513520
.attr('width', opts._width)
514521
.call(Color.fill, constants.maskOppAxisColor);
515522

516523
var maskMaxOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxOppAxisClassName, function(s) {
517-
s.attr('y', 0);
518-
s.attr('shape-rendering', 'crispEdges');
524+
s.attr({
525+
y: 0,
526+
'shape-rendering': 'crispEdges'
527+
});
519528
});
520529

521530
maskMaxOppAxis
@@ -529,9 +538,11 @@ function drawSlideBox(rangeSlider, gd, axisOpts, opts) {
529538
if(gd._context.staticPlot) return;
530539

531540
var slideBox = Lib.ensureSingle(rangeSlider, 'rect', constants.slideBoxClassName, function(s) {
532-
s.attr('y', 0);
533-
s.attr('cursor', constants.slideBoxCursor);
534-
s.attr('shape-rendering', 'crispEdges');
541+
s.attr({
542+
y: 0,
543+
cursor: constants.slideBoxCursor,
544+
'shape-rendering': 'crispEdges'
545+
});
535546
});
536547

537548
slideBox.attr({

src/components/sliders/draw.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,11 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
284284
}
285285

286286
var text = Lib.ensureSingle(sliderGroup, 'text', constants.labelClass, function(s) {
287-
s.classed('user-select-none', true);
288-
s.attr({
289-
'text-anchor': textAnchor,
290-
'data-notex': 1
291-
});
287+
s.classed('user-select-none', true)
288+
.attr({
289+
'text-anchor': textAnchor,
290+
'data-notex': 1
291+
});
292292
});
293293

294294
var str = sliderOpts.currentvalue.prefix ? sliderOpts.currentvalue.prefix : '';
@@ -320,8 +320,8 @@ function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
320320

321321
function drawGrip(sliderGroup, gd, sliderOpts) {
322322
var grip = Lib.ensureSingle(sliderGroup, 'rect', constants.gripRectClass, function(s) {
323-
s.call(attachGripEvents, gd, sliderGroup, sliderOpts);
324-
s.style('pointer-events', 'all');
323+
s.call(attachGripEvents, gd, sliderGroup, sliderOpts)
324+
.style('pointer-events', 'all');
325325
});
326326

327327
grip.attr({
@@ -337,11 +337,11 @@ function drawGrip(sliderGroup, gd, sliderOpts) {
337337

338338
function drawLabel(item, data, sliderOpts) {
339339
var text = Lib.ensureSingle(item, 'text', constants.labelClass, function(s) {
340-
s.classed('user-select-none', true);
341-
s.attr({
342-
'text-anchor': 'middle',
343-
'data-notex': 1
344-
});
340+
s.classed('user-select-none', true)
341+
.attr({
342+
'text-anchor': 'middle',
343+
'data-notex': 1
344+
});
345345
});
346346

347347
text.call(Drawing.font, sliderOpts.font)
@@ -559,8 +559,8 @@ function positionToNormalizedValue(sliderOpts, position) {
559559
function drawTouchRect(sliderGroup, gd, sliderOpts) {
560560
var dims = sliderOpts._dims;
561561
var rect = Lib.ensureSingle(sliderGroup, 'rect', constants.railTouchRectClass, function(s) {
562-
s.call(attachGripEvents, gd, sliderGroup, sliderOpts);
563-
s.style('pointer-events', 'all');
562+
s.call(attachGripEvents, gd, sliderGroup, sliderOpts)
563+
.style('pointer-events', 'all');
564564
});
565565

566566
rect.attr({

src/components/updatemenus/draw.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ function drawItemRect(item, menuOpts) {
454454

455455
function drawItemText(item, menuOpts, itemOpts, gd) {
456456
var text = Lib.ensureSingle(item, 'text', constants.itemTextClassName, function(s) {
457-
s.classed('user-select-none', true);
458-
s.attr({
459-
'text-anchor': 'start',
460-
'data-notex': 1
461-
});
457+
s.classed('user-select-none', true)
458+
.attr({
459+
'text-anchor': 'start',
460+
'data-notex': 1
461+
});
462462
});
463463

464464
text.call(Drawing.font, menuOpts.font)

src/plot_api/subroutines.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ exports.lsInner = function(gd) {
183183
var clipId = plotinfo.clipId = 'clip' + fullLayout._uid + subplot + 'plot';
184184

185185
var plotClip = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {
186-
s.classed('plotclip', true);
187-
s.append('rect');
186+
s.classed('plotclip', true)
187+
.append('rect');
188188
});
189189

190190
plotClip.select('rect').attr({

src/plots/ternary/ternary.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ proto.makeFramework = function(fullLayout) {
7575
var clipIdRelative = _this.clipIdRelative = 'clip-relative' + _this.layoutId + _this.id;
7676

7777
// clippath for this ternary subplot
78-
_this.clipDef = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId);
79-
_this.clipDef.append('path').attr('d', 'M0,0Z');
78+
_this.clipDef = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {
79+
s.append('path').attr('d', 'M0,0Z');
80+
});
8081

8182
// 'relative' clippath (i.e. no translation) for this ternary subplot
82-
_this.clipDefRelative = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipIdRelative);
83-
_this.clipDefRelative.append('path').attr('d', 'M0,0Z');
83+
_this.clipDefRelative = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipIdRelative, function(s) {
84+
s.clipDefRelative.append('path').attr('d', 'M0,0Z');
85+
});
8486

8587
// container for everything in this ternary subplot
8688
_this.plotContainer = Lib.ensureSingle(_this.container, 'g', _this.id);

0 commit comments

Comments
 (0)