Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
x: borderfull + xShift - 1,
y: borderfull + yShift
})
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
}
else {
var texty = borderfull + yShift - anntextBB.top;
var textx = borderfull + xShift - anntextBB.left;

annText.call(svgTextUtils.positionText, textx, texty)
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
.call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null, gd);
}

annTextClip.select('rect').call(Drawing.setRect, borderfull, borderfull,
Expand Down
19 changes: 4 additions & 15 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,27 +1005,16 @@ function nodeHash(node) {
* note! We'd better not be exporting from a page
* with a <base> or the svg will not be portable!
*/
drawing.setClipUrl = function(s, localId) {
drawing.setClipUrl = function(s, localId, gd) {
if(!localId) {
s.attr('clip-path', null);
return;
}

if(drawing.baseUrl === undefined) {
var base = d3.select('base');
var context = gd._context;
var baseUrl = context.exportedPlot ? '' : (context.baseUrl || '');

// Stash base url once and for all!
// We may have to stash this elsewhere when
// we'll try to support for child windows
// more info -> https://github.com/plotly/plotly.js/issues/702
if(base.size() && base.attr('href')) {
drawing.baseUrl = window.location.href.split('#')[0];
} else {
drawing.baseUrl = '';
}
}

s.attr('clip-path', 'url(' + drawing.baseUrl + '#' + localId + ')');
s.attr('clip-path', 'url(' + baseUrl + '#' + localId + ')');
};

drawing.getTranslate = function(element) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/errorbars/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var isNumeric = require('fast-isnumeric');
var Drawing = require('../drawing');
var subTypes = require('../../traces/scatter/subtypes');

module.exports = function plot(traces, plotinfo, transitionOpts) {
module.exports = function plot(gd, traces, plotinfo, transitionOpts) {
var isNew;

var xa = plotinfo.xaxis;
Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = function plot(traces, plotinfo, transitionOpts) {
.style('opacity', 1);
}

Drawing.setClipUrl(errorbars, plotinfo.layerClipId);
Drawing.setClipUrl(errorbars, plotinfo.layerClipId, gd);

errorbars.each(function(d) {
var errorbar = d3.select(this);
Expand Down
7 changes: 4 additions & 3 deletions src/components/images/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ module.exports = function draw(gd) {
yId = ya ? ya._id : '',
clipAxes = xId + yId;

thisImage.call(Drawing.setClipUrl, clipAxes ?
('clip' + fullLayout._uid + clipAxes) :
null
Drawing.setClipUrl(
thisImage,
clipAxes ? ('clip' + fullLayout._uid + clipAxes) : null,
gd
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/legend/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ module.exports = function draw(gd) {
y: opts.borderwidth
});

Drawing.setClipUrl(scrollBox, clipId);
Drawing.setClipUrl(scrollBox, clipId, gd);

Drawing.setRect(scrollBar, 0, 0, 0, 0);
delete opts._scrollY;
Expand Down Expand Up @@ -262,7 +262,7 @@ module.exports = function draw(gd) {
y: opts.borderwidth + scrollBoxY
});

Drawing.setClipUrl(scrollBox, clipId);
Drawing.setClipUrl(scrollBox, clipId, gd);

scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);

Expand Down
2 changes: 1 addition & 1 deletion src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ function drawRangePlot(rangeSlider, gd, axisOpts, opts) {

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

rangePlots.order();

Expand Down
14 changes: 8 additions & 6 deletions src/components/shapes/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ function setClipPath(shapePath, gd, shapeOptions) {
// spans two subplots. See https://github.com/plotly/plotly.js/issues/1452
var clipAxes = (shapeOptions.xref + shapeOptions.yref).replace(/paper/g, '');

shapePath.call(Drawing.setClipUrl, clipAxes ?
('clip' + gd._fullLayout._uid + clipAxes) :
null
Drawing.setClipUrl(
shapePath,
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
gd
);
}

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

shapePath.call(Drawing.setClipUrl, clipAxes ?
'clip' + gd._fullLayout._uid + clipAxes :
null
Drawing.setClipUrl(
shapePath,
clipAxes ? 'clip' + gd._fullLayout._uid + clipAxes : null,
gd
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/updatemenus/scrollbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
height: Math.ceil(clipB) - Math.floor(clipT)
});

this.container.call(Drawing.setClipUrl, clipId);
this.container.call(Drawing.setClipUrl, clipId, this.gd);

this.bg.attr({
x: l,
Expand Down
14 changes: 10 additions & 4 deletions src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ exports.plot = function(gd, data, layout, config) {
// so we can share cached text across tabs
Drawing.makeTester();

// clear stashed base url
delete Drawing.baseUrl;

// collect promises for any async actions during plotting
// any part of the plotting code can push to gd._promises, then
// before we move to the next step, we check that they're all
Expand Down Expand Up @@ -419,7 +416,16 @@ function opaqueSetBackground(gd, bgColor) {
}

function setPlotContext(gd, config) {
if(!gd._context) gd._context = Lib.extendDeep({}, defaultConfig);
if(!gd._context) {
gd._context = Lib.extendDeep({}, defaultConfig);

// stash <base> href, used to make robust clipPath URLs
var base = d3.select('base');
gd._context.baseUrl = base.size() && base.attr('href') ?
window.location.href.split('#')[0] :
'';
}

var context = gd._context;

var i, keys, key;
Expand Down
2 changes: 1 addition & 1 deletion src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function lsInner(gd) {
layerClipId = null;
}

Drawing.setClipUrl(plotinfo.plot, plotClipId);
Drawing.setClipUrl(plotinfo.plot, plotClipId, gd);

// stash layer clipId value (null or same as clipId)
// to DRY up Drawing.setClipUrl calls on trace-module and trace layers
Expand Down
1 change: 1 addition & 0 deletions src/plot_api/to_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ function toImage(gd, opts) {
// extend config for static plot
var configImage = Lib.extendFlat({}, config, {
staticPlot: true,
exportedPlot: true,
setBackground: setBackground
});

Expand Down
2 changes: 1 addition & 1 deletion src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback

// layers that allow `cliponaxis: false`
if(className !== 'scatterlayer' && className !== 'barlayer') {
Drawing.setClipUrl(sel, plotinfo.layerClipId);
Drawing.setClipUrl(sel, plotinfo.layerClipId, gd);
}
});

Expand Down
5 changes: 3 additions & 2 deletions src/plots/geo/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ proto.updateFx = function(fullLayout, geoLayout) {

proto.makeFramework = function() {
var _this = this;
var fullLayout = _this.graphDiv._fullLayout;
var gd = _this.graphDiv;
var fullLayout = gd._fullLayout;
var clipId = 'clip' + fullLayout._uid + _this.id;

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

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

// sane lonlat to px
_this.project = function(v) {
Expand Down
2 changes: 1 addition & 1 deletion src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ proto.updateLayout = function(fullLayout, polarLayout) {

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

layers.bg
.attr('d', dPath)
Expand Down
8 changes: 5 additions & 3 deletions src/plots/ternary/ternary.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ proto.plot = function(ternaryCalcData, fullLayout) {

proto.makeFramework = function(fullLayout) {
var _this = this;
var gd = _this.graphDiv;
var ternaryLayout = fullLayout[_this.id];

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

Drawing.setClipUrl(_this.layers.backplot, clipId);
Drawing.setClipUrl(_this.layers.grids, clipId);
Drawing.setClipUrl(_this.layers.backplot, clipId, gd);
Drawing.setClipUrl(_this.layers.grids, clipId, gd);
};

proto.updateLayers = function(ternaryLayout) {
Expand Down Expand Up @@ -345,7 +346,8 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {

Drawing.setClipUrl(
_this.layers.frontplot,
_this._hasClipOnAxisFalse ? null : _this.clipId
_this._hasClipOnAxisFalse ? null : _this.clipId,
_this.graphDiv
);
};

Expand Down
6 changes: 3 additions & 3 deletions src/traces/bar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
.style('vector-effect', 'non-scaling-stroke')
.attr('d',
'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
.call(Drawing.setClipUrl, plotinfo.layerClipId);
.call(Drawing.setClipUrl, plotinfo.layerClipId, gd);

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

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

// error bars are on the top
Registry.getComponentMethod('errorbars', 'plot')(bartraces, plotinfo);
Registry.getComponentMethod('errorbars', 'plot')(gd, bartraces, plotinfo);
};

function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
Expand Down
6 changes: 5 additions & 1 deletion src/traces/barpolar/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ module.exports = function plot(gd, subplot, cdbar) {
});

// clip plotGroup, when trace layer isn't clipped
Drawing.setClipUrl(plotGroup, subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null);
Drawing.setClipUrl(
plotGroup,
subplot._hasClipOnAxisFalse ? subplot.clipIds.forTraces : null,
gd
);
});
};

Expand Down
16 changes: 8 additions & 8 deletions src/traces/contour/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var costConstants = constants.LABELOPTIMIZER;
exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var fullLayout = gd._fullLayout;

Lib.makeTraceGroups(contourLayer, cdcontours, 'contour').each(function(cd) {
var plotGroup = d3.select(this);
Expand Down Expand Up @@ -78,7 +77,7 @@ exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
makeBackground(plotGroup, perimeter, contours);
makeFills(plotGroup, fillPathinfo, perimeter, contours);
makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, perimeter);
clipGaps(plotGroup, plotinfo, fullLayout._clips, cd0, perimeter);
clipGaps(plotGroup, plotinfo, gd, cd0, perimeter);
});
};

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

var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels,
gd._fullLayout._clips, cd0.trace.uid);
var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);

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

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

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

Drawing.setClipUrl(lineContainer, clipId);
Drawing.setClipUrl(lineContainer, clipId, gd);

return lineClip;
};
Expand Down Expand Up @@ -595,7 +594,8 @@ exports.drawLabels = function(labelGroup, labelData, gd, lineClip, labelClipPath
}
};

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

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

plotGroup.call(Drawing.setClipUrl, clipId);
Drawing.setClipUrl(plotGroup, clipId, gd);
}

function makeClipMask(cd0) {
Expand Down
5 changes: 2 additions & 3 deletions src/traces/contourcarpet/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = function plot(gd, plotinfo, cdcontours, contourcarpetLayer) {
makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, plotinfo, carpet);

// Clip the boundary of the plot
Drawing.setClipUrl(plotGroup, carpet._clipPathId);
Drawing.setClipUrl(plotGroup, carpet._clipPathId, gd);
});
};

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

var lineClip = contourPlot.createLineClip(lineContainer, clipLinesForLabels,
gd._fullLayout._defs, cd0.trace.uid);
var lineClip = contourPlot.createLineClip(lineContainer, clipLinesForLabels, gd, cd0.trace.uid);

var labelGroup = plotgroup.selectAll('g.contourlabels')
.data(showLabels ? [0] : []);
Expand Down
Loading