Skip to content

Commit fbae9e7

Browse files
committed
pass 'gd' to Drawing.setClipUrl
- pass it as third argument, to keep setClipUrl compatible with `selection.call(method, ...args)` - needed to pass gd to ErrorBars.plot to clip errorbars
1 parent 695f311 commit fbae9e7

File tree

19 files changed

+61
-49
lines changed

19 files changed

+61
-49
lines changed

src/components/annotations/draw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
411411
x: borderfull + xShift - 1,
412412
y: borderfull + yShift
413413
})
414-
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
414+
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
415415
}
416416
else {
417417
var texty = borderfull + yShift - anntextBB.top;
418418
var textx = borderfull + xShift - anntextBB.left;
419419

420420
annText.call(svgTextUtils.positionText, textx, texty)
421-
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
421+
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
422422
}
423423

424424
annTextClip.select('rect').call(Drawing.setRect, borderfull, borderfull,

src/components/errorbars/plot.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var isNumeric = require('fast-isnumeric');
1515
var Drawing = require('../drawing');
1616
var subTypes = require('../../traces/scatter/subtypes');
1717

18-
module.exports = function plot(traces, plotinfo, transitionOpts) {
18+
module.exports = function plot(gd, traces, plotinfo, transitionOpts) {
1919
var isNew;
2020

2121
var xa = plotinfo.xaxis;
@@ -66,7 +66,7 @@ module.exports = function plot(traces, plotinfo, transitionOpts) {
6666
.style('opacity', 1);
6767
}
6868

69-
Drawing.setClipUrl(errorbars, plotinfo.layerClipId);
69+
Drawing.setClipUrl(errorbars, plotinfo.layerClipId, gd);
7070

7171
errorbars.each(function(d) {
7272
var errorbar = d3.select(this);

src/components/images/draw.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ module.exports = function draw(gd) {
168168
yId = ya ? ya._id : '',
169169
clipAxes = xId + yId;
170170

171-
thisImage.call(Drawing.setClipUrl, clipAxes ?
172-
('clip' + fullLayout._uid + clipAxes) :
173-
null
171+
Drawing.setClipUrl(
172+
thisImage,
173+
clipAxes ? ('clip' + fullLayout._uid + clipAxes) : null,
174+
gd
174175
);
175176
}
176177

src/components/legend/draw.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ module.exports = function draw(gd) {
224224
y: opts.borderwidth
225225
});
226226

227-
Drawing.setClipUrl(scrollBox, clipId);
227+
Drawing.setClipUrl(scrollBox, clipId, gd);
228228

229229
Drawing.setRect(scrollBar, 0, 0, 0, 0);
230230
delete opts._scrollY;
@@ -262,7 +262,7 @@ module.exports = function draw(gd) {
262262
y: opts.borderwidth + scrollBoxY
263263
});
264264

265-
Drawing.setClipUrl(scrollBox, clipId);
265+
Drawing.setClipUrl(scrollBox, clipId, gd);
266266

267267
scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
268268

src/components/rangeslider/draw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
401401

402402
rangePlots.enter().append('g')
403403
.attr('class', function(id) { return constants.rangePlotClassName + ' ' + id; })
404-
.call(Drawing.setClipUrl, opts._clipId);
404+
.call(Drawing.setClipUrl, opts._clipId, gd);
405405

406406
rangePlots.order();
407407

src/components/shapes/draw.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@ function setClipPath(shapePath, gd, shapeOptions) {
120120
// spans two subplots. See https://github.com/plotly/plotly.js/issues/1452
121121
var clipAxes = (shapeOptions.xref + shapeOptions.yref).replace(/paper/g, '');
122122

123-
shapePath.call(Drawing.setClipUrl, clipAxes ?
124-
('clip' + gd._fullLayout._uid + clipAxes) :
125-
null
123+
Drawing.setClipUrl(
124+
shapePath,
125+
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
126+
gd
126127
);
127128
}
128129

@@ -493,9 +494,10 @@ function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) {
493494
if(xref !== 'paper' && !xa.autorange) clipAxes += xref;
494495
if(yref !== 'paper' && !ya.autorange) clipAxes += yref;
495496

496-
shapePath.call(Drawing.setClipUrl, clipAxes ?
497-
'clip' + gd._fullLayout._uid + clipAxes :
498-
null
497+
Drawing.setClipUrl(
498+
shapePath,
499+
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
500+
gd
499501
);
500502
}
501503
}

src/components/updatemenus/scrollbox.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
254254
height: Math.ceil(clipB) - Math.floor(clipT)
255255
});
256256

257-
this.container.call(Drawing.setClipUrl, clipId);
257+
this.container.call(Drawing.setClipUrl, clipId, this.gd);
258258

259259
this.bg.attr({
260260
x: l,

src/plot_api/subroutines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function lsInner(gd) {
224224
layerClipId = null;
225225
}
226226

227-
Drawing.setClipUrl(plotinfo.plot, plotClipId);
227+
Drawing.setClipUrl(plotinfo.plot, plotClipId, gd);
228228

229229
// stash layer clipId value (null or same as clipId)
230230
// to DRY up Drawing.setClipUrl calls on trace-module and trace layers

src/plots/cartesian/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
262262

263263
// layers that allow `cliponaxis: false`
264264
if(className !== 'scatterlayer' && className !== 'barlayer') {
265-
Drawing.setClipUrl(sel, plotinfo.layerClipId);
265+
Drawing.setClipUrl(sel, plotinfo.layerClipId, gd);
266266
}
267267
});
268268

src/plots/geo/geo.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ proto.updateFx = function(fullLayout, geoLayout) {
470470

471471
proto.makeFramework = function() {
472472
var _this = this;
473-
var fullLayout = _this.graphDiv._fullLayout;
473+
var gd = _this.graphDiv;
474+
var fullLayout = gd._fullLayout;
474475
var clipId = 'clip' + fullLayout._uid + _this.id;
475476

476477
_this.clipDef = fullLayout._clips.append('clipPath')
@@ -480,7 +481,7 @@ proto.makeFramework = function() {
480481

481482
_this.framework = d3.select(_this.container).append('g')
482483
.attr('class', 'geo ' + _this.id)
483-
.call(Drawing.setClipUrl, clipId);
484+
.call(Drawing.setClipUrl, clipId, gd);
484485

485486
// sane lonlat to px
486487
_this.project = function(v) {

src/plots/polar/polar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ proto.updateLayout = function(fullLayout, polarLayout) {
290290

291291
layers.frontplot
292292
.attr('transform', strTranslate(xOffset2, yOffset2))
293-
.call(Drawing.setClipUrl, _this._hasClipOnAxisFalse ? null : _this.clipIds.forTraces);
293+
.call(Drawing.setClipUrl, _this._hasClipOnAxisFalse ? null : _this.clipIds.forTraces, _this.gd);
294294

295295
layers.bg
296296
.attr('d', dPath)

src/plots/ternary/ternary.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ proto.plot = function(ternaryCalcData, fullLayout) {
7777

7878
proto.makeFramework = function(fullLayout) {
7979
var _this = this;
80+
var gd = _this.graphDiv;
8081
var ternaryLayout = fullLayout[_this.id];
8182

8283
var clipId = _this.clipId = 'clip' + _this.layoutId + _this.id;
@@ -96,8 +97,8 @@ proto.makeFramework = function(fullLayout) {
9697
_this.plotContainer = Lib.ensureSingle(_this.container, 'g', _this.id);
9798
_this.updateLayers(ternaryLayout);
9899

99-
Drawing.setClipUrl(_this.layers.backplot, clipId);
100-
Drawing.setClipUrl(_this.layers.grids, clipId);
100+
Drawing.setClipUrl(_this.layers.backplot, clipId, gd);
101+
Drawing.setClipUrl(_this.layers.grids, clipId, gd);
101102
};
102103

103104
proto.updateLayers = function(ternaryLayout) {
@@ -345,7 +346,8 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
345346

346347
Drawing.setClipUrl(
347348
_this.layers.frontplot,
348-
_this._hasClipOnAxisFalse ? null : _this.clipId
349+
_this._hasClipOnAxisFalse ? null : _this.clipId,
350+
_this.graphDiv
349351
);
350352
};
351353

src/traces/bar/plot.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
124124
.style('vector-effect', 'non-scaling-stroke')
125125
.attr('d',
126126
'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
127-
.call(Drawing.setClipUrl, plotinfo.layerClipId);
127+
.call(Drawing.setClipUrl, plotinfo.layerClipId, gd);
128128

129129
appendBarText(gd, bar, cd, i, x0, x1, y0, y1);
130130

@@ -136,11 +136,11 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
136136
// lastly, clip points groups of `cliponaxis !== false` traces
137137
// on `plotinfo._hasClipOnAxisFalse === true` subplots
138138
var hasClipOnAxisFalse = cd0.trace.cliponaxis === false;
139-
Drawing.setClipUrl(plotGroup, hasClipOnAxisFalse ? null : plotinfo.layerClipId);
139+
Drawing.setClipUrl(plotGroup, hasClipOnAxisFalse ? null : plotinfo.layerClipId, gd);
140140
});
141141

142142
// error bars are on the top
143-
Registry.getComponentMethod('errorbars', 'plot')(bartraces, plotinfo);
143+
Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo);
144144
};
145145

146146
function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {

src/traces/barpolar/plot.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ module.exports = function plot(gd, subplot, cdbar) {
6969
});
7070

7171
// clip plotGroup, when trace layer isn't clipped
72-
Drawing.setClipUrl(plotGroup, subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null);
72+
Drawing.setClipUrl(
73+
plotGroup,
74+
subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null,
75+
gd
76+
);
7377
});
7478
};
7579

src/traces/contour/plot.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var costConstants = constants.LABELOPTIMIZER;
2929
exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
3030
var xa = plotinfo.xaxis;
3131
var ya = plotinfo.yaxis;
32-
var fullLayout = gd._fullLayout;
3332

3433
Lib.makeTraceGroups(contourLayer, cdcontours, 'contour').each(function(cd) {
3534
var plotGroup = d3.select(this);
@@ -78,7 +77,7 @@ exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
7877
makeBackground(plotGroup, perimeter, contours);
7978
makeFills(plotGroup, fillPathinfo, perimeter, contours);
8079
makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, perimeter);
81-
clipGaps(plotGroup, plotinfo, fullLayout._clips, cd0, perimeter);
80+
clipGaps(plotGroup, plotinfo, gd, cd0, perimeter);
8281
});
8382
};
8483

@@ -230,8 +229,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
230229
// In this case we'll remove the lines after making the labels.
231230
var linegroup = exports.createLines(lineContainer, showLines || showLabels, pathinfo);
232231

233-
var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels,
234-
gd._fullLayout._clips, cd0.trace.uid);
232+
var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);
235233

236234
var labelGroup = plotgroup.selectAll('g.contourlabels')
237235
.data(showLabels ? [0] : []);
@@ -353,7 +351,8 @@ exports.createLines = function(lineContainer, makeLines, pathinfo) {
353351
return linegroup;
354352
};
355353

356-
exports.createLineClip = function(lineContainer, clipLinesForLabels, clips, uid) {
354+
exports.createLineClip = function(lineContainer, clipLinesForLabels, gd, uid) {
355+
var clips = gd._fullLayout._clips;
357356
var clipId = clipLinesForLabels ? ('clipline' + uid) : null;
358357

359358
var lineClip = clips.selectAll('#' + clipId)
@@ -364,7 +363,7 @@ exports.createLineClip = function(lineContainer, clipLinesForLabels, clips, uid)
364363
.classed('contourlineclip', true)
365364
.attr('id', clipId);
366365

367-
Drawing.setClipUrl(lineContainer, clipId);
366+
Drawing.setClipUrl(lineContainer, clipId, gd);
368367

369368
return lineClip;
370369
};
@@ -595,7 +594,8 @@ exports.drawLabels = function(labelGroup, labelData, gd, lineClip, labelClipPath
595594
}
596595
};
597596

598-
function clipGaps(plotGroup, plotinfo, clips, cd0, perimeter) {
597+
function clipGaps(plotGroup, plotinfo, gd, cd0, perimeter) {
598+
var clips = gd._fullLayout._clips;
599599
var clipId = 'clip' + cd0.trace.uid;
600600

601601
var clipPath = clips.selectAll('#' + clipId)
@@ -634,7 +634,7 @@ function clipGaps(plotGroup, plotinfo, clips, cd0, perimeter) {
634634
}
635635
else clipId = null;
636636

637-
plotGroup.call(Drawing.setClipUrl, clipId);
637+
Drawing.setClipUrl(plotGroup, clipId, gd);
638638
}
639639

640640
function makeClipMask(cd0) {

src/traces/contourcarpet/plot.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ module.exports = function plot(gd, plotinfo, cdcontours, contourcarpetLayer) {
113113
makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, plotinfo, carpet);
114114

115115
// Clip the boundary of the plot
116-
Drawing.setClipUrl(plotGroup, carpet._clipPathId);
116+
Drawing.setClipUrl(plotGroup, carpet._clipPathId, gd);
117117
});
118118
};
119119

@@ -129,8 +129,7 @@ function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, plotinfo, ca
129129
// In this case we'll remove the lines after making the labels.
130130
var linegroup = contourPlot.createLines(lineContainer, showLines || showLabels, pathinfo);
131131

132-
var lineClip = contourPlot.createLineClip(lineContainer, clipLinesForLabels,
133-
gd._fullLayout._defs, cd0.trace.uid);
132+
var lineClip = contourPlot.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);
134133

135134
var labelGroup = plotgroup.selectAll('g.contourlabels')
136135
.data(showLabels ? [0] : []);

src/traces/scatter/plot.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition
8888
function createFills(gd, traceJoin, plotinfo) {
8989
traceJoin.each(function(d) {
9090
var fills = ensureSingle(d3.select(this), 'g', 'fills');
91-
Drawing.setClipUrl(fills, plotinfo.layerClipId);
91+
Drawing.setClipUrl(fills, plotinfo.layerClipId, gd);
9292

9393
var trace = d[0].trace;
9494

@@ -140,7 +140,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
140140
var text = ensureSingle(tr, 'g', 'text');
141141

142142
// error bars are at the bottom
143-
Registry.getComponentMethod('errorbars', 'plot')(errorBarGroup, plotinfo, transitionOpts);
143+
Registry.getComponentMethod('errorbars', 'plot')(gd, errorBarGroup, plotinfo, transitionOpts);
144144

145145
if(trace.visible !== true) return;
146146

@@ -295,7 +295,7 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
295295
.call(Drawing.lineGroupStyle)
296296
.each(makeUpdate(true));
297297

298-
Drawing.setClipUrl(lineJoin, plotinfo.layerClipId);
298+
Drawing.setClipUrl(lineJoin, plotinfo.layerClipId, gd);
299299

300300
function clearFill(selection) {
301301
transition(selection).attr('d', 'M0,0Z');
@@ -523,8 +523,8 @@ function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transition
523523
// on `plotinfo._hasClipOnAxisFalse === true` subplots
524524
var hasClipOnAxisFalse = trace.cliponaxis === false;
525525
var clipUrl = hasClipOnAxisFalse ? null : plotinfo.layerClipId;
526-
Drawing.setClipUrl(points, clipUrl);
527-
Drawing.setClipUrl(text, clipUrl);
526+
Drawing.setClipUrl(points, clipUrl, gd);
527+
Drawing.setClipUrl(text, clipUrl, gd);
528528
}
529529

530530
function selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) {

src/traces/scattercarpet/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ module.exports = function plot(gd, plotinfoproxy, data, layer) {
3737
// separately to all scattercarpet traces, but that would require
3838
// lots of reorganization of scatter traces that is otherwise not
3939
// necessary. That makes this a potential optimization.
40-
Drawing.setClipUrl(node, carpet._clipPathId);
40+
Drawing.setClipUrl(node, carpet._clipPathId, gd);
4141
}
4242
};

src/traces/table/plot.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ module.exports = function plot(gd, wrappedTraceHolders) {
8383
.attr('width', function(d) {return d.width;})
8484
.attr('height', function(d) {return d.height;});
8585

86-
tableControlView
87-
.each(function(d) {Drawing.setClipUrl(d3.select(this), scrollAreaBottomClipKey(gd, d));});
86+
tableControlView.each(function(d) {
87+
Drawing.setClipUrl(d3.select(this), scrollAreaBottomClipKey(gd, d), gd);
88+
});
8889

8990
var yColumn = tableControlView.selectAll('.' + c.cn.yColumn)
9091
.data(function(vm) {return vm.columns;}, gup.keyFun);
@@ -137,7 +138,9 @@ module.exports = function plot(gd, wrappedTraceHolders) {
137138
})
138139
);
139140

140-
yColumn.each(function(d) {Drawing.setClipUrl(d3.select(this), columnBoundaryClipKey(gd, d));});
141+
yColumn.each(function(d) {
142+
Drawing.setClipUrl(d3.select(this), columnBoundaryClipKey(gd, d), gd);
143+
});
141144

142145
var columnBlock = yColumn.selectAll('.' + c.cn.columnBlock)
143146
.data(splitData.splitToPanels, gup.keyFun);

0 commit comments

Comments
 (0)