Skip to content

Commit e234827

Browse files
committed
fixes #1873 - apply transform on <clipPath> child
- instead of on <clipPath> element itself - see https://codepen.io/etpinard/pen/eRbxrp for more info on the problem - lock down this rule by adding condition in strict-d3.js
1 parent e84701f commit e234827

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/plots/cartesian/dragbox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ module.exports = function dragBox(gd, plotinfo, x, y, w, h, ns, ew) {
743743
var plotDx = xa2._offset - clipDx / xScaleFactor2,
744744
plotDy = ya2._offset - clipDy / yScaleFactor2;
745745

746-
fullLayout._defs.selectAll('#' + subplot.clipId)
746+
fullLayout._defs.select('#' + subplot.clipId + '> rect')
747747
.call(Drawing.setTranslate, clipDx, clipDy)
748748
.call(Drawing.setScale, xScaleFactor2, yScaleFactor2);
749749

src/plots/cartesian/transition_axes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
137137
var xa2 = subplot.xaxis;
138138
var ya2 = subplot.yaxis;
139139

140-
fullLayout._defs.selectAll('#' + subplot.clipId)
140+
fullLayout._defs.select('#' + subplot.clipId + '> rect')
141141
.call(Drawing.setTranslate, 0, 0)
142142
.call(Drawing.setScale, 1, 1);
143143

@@ -221,7 +221,7 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
221221
var plotDx = xa2._offset - fracDx,
222222
plotDy = ya2._offset - fracDy;
223223

224-
fullLayout._defs.selectAll('#' + subplot.clipId)
224+
fullLayout._defs.select('#' + subplot.clipId + '> rect')
225225
.call(Drawing.setTranslate, clipDx, clipDy)
226226
.call(Drawing.setScale, 1 / xScaleFactor, 1 / yScaleFactor);
227227

src/plots/ternary/ternary.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ proto.adjustLayout = function(ternaryLayout, graphSize) {
292292
_this.plotContainer.selectAll('.scatterlayer,.maplayer')
293293
.attr('transform', plotTransform);
294294

295-
_this.clipDefRelative.attr('transform', null);
295+
_this.clipDefRelative.select('path').attr('transform', null);
296296

297297
// TODO: shift axes to accommodate linewidth*sin(30) tick mark angle
298298

@@ -619,7 +619,7 @@ proto.initInteractions = function() {
619619
.attr('transform', plotTransform);
620620

621621
var plotTransform2 = 'translate(' + -dx + ',' + -dy + ')';
622-
_this.clipDefRelative.attr('transform', plotTransform2);
622+
_this.clipDefRelative.select('path').attr('transform', plotTransform2);
623623

624624
// move the ticks
625625
_this.aaxis.range = [mins.a, _this.sum - mins.b - mins.c];

test/image/strict-d3.js

+24
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,24 @@ var d3 = require('d3');
88
var isNumeric = require('fast-isnumeric');
99

1010
var selProto = d3.selection.prototype;
11+
var originalSelAttr = selProto.attr;
1112
var originalSelStyle = selProto.style;
1213

14+
selProto.attr = function() {
15+
var sel = this;
16+
var obj = arguments[0];
17+
18+
if(sel.size()) {
19+
if(typeof obj === 'string') {
20+
checkAttrVal(sel, obj, arguments[1]);
21+
} else {
22+
Object.keys(obj).forEach(function(key) { checkAttrVal(sel, key, obj[key]); });
23+
}
24+
}
25+
26+
return originalSelAttr.apply(sel, arguments);
27+
};
28+
1329
selProto.style = function() {
1430
var sel = this;
1531
var obj = arguments[0];
@@ -25,6 +41,14 @@ selProto.style = function() {
2541
return originalSelStyle.apply(sel, arguments);
2642
};
2743

44+
function checkAttrVal(sel, key) {
45+
// setting the transform attribute on a <clipPath> does not
46+
// work in Chrome, IE and Edge
47+
if(sel.node().nodeName === 'clipPath' && key === 'transform') {
48+
throw new Error('d3 selection.attr called with key \'transform\' on a clipPath node');
49+
}
50+
}
51+
2852
function checkStyleVal(sel, key, val) {
2953
if(typeof val === 'string') {
3054
// in case of multipart styles (stroke-dasharray, margins, etc)

0 commit comments

Comments
 (0)