Skip to content

Commit 7d85bfe

Browse files
committed
Ensure shapes use the right clip-path
* Fixed bug that caused shapes drawn in a subplot to extend beyond the limits of the subplot. * Fixed issues with code styling.
1 parent a8aa194 commit 7d85bfe

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

src/components/shapes/index.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function insertShape(gd, index, newShape) {
215215
}
216216

217217
function updateShape(gd, index, opt, value) {
218-
var i;
218+
var i, n;
219219

220220
// remove the existing shape if there is one
221221
getShapeLayer(gd, index)
@@ -298,25 +298,33 @@ function updateShape(gd, index, opt, value) {
298298
'fill-rule': 'evenodd',
299299
d: shapePath(gd, options)
300300
},
301-
clipAxes = (options.xref + options.yref).replace(/paper/g, '');
301+
clipAxes;
302302

303303
var lineColor = options.line.width ? options.line.color : 'rgba(0,0,0,0)';
304304

305305
if(options.layer !== 'below') {
306+
clipAxes = (options.xref + options.yref).replace(/paper/g, '');
306307
drawShape(gd._fullLayout._shapeUpperLayer);
307308
}
308309
else if(options.xref === 'paper' && options.yref === 'paper') {
310+
clipAxes = '';
309311
drawShape(gd._fullLayout._shapeLowerLayer);
310-
} else {
311-
forEachSubplot(gd, function(plotinfo) {
312+
}
313+
else {
314+
var plots = gd._fullLayout._plots || {},
315+
subplots = Object.keys(plots),
316+
plotinfo;
317+
318+
for(i = 0, n = subplots.length; i < n; i++) {
319+
plotinfo = plots[subplots[i]];
320+
clipAxes = subplots[i];
321+
312322
if(isShapeInSubplot(gd, options, plotinfo.id)) {
313323
drawShape(plotinfo.shapelayer);
314324
}
315-
});
325+
}
316326
}
317327

318-
return;
319-
320328
function drawShape(shapeLayer) {
321329
var path = shapeLayer.append('path')
322330
.attr(attrs)
@@ -354,15 +362,6 @@ function isShapeInSubplot(gd, shape, subplot) {
354362
return shape.layer === 'below' && (xa === shape.xref || ya === shape.yref);
355363
}
356364

357-
function forEachSubplot(gd, fn) {
358-
var plots = gd._fullLayout._plots || {},
359-
subplots = Object.getOwnPropertyNames(plots);
360-
361-
for(var i = 0, n = subplots.length; i < n; i++) {
362-
fn(plots[subplots[i]]);
363-
}
364-
}
365-
366365
function decodeDate(convertToPx) {
367366
return function(v) { return convertToPx(v.replace('_', ' ')); };
368367
}

test/jasmine/tests/shapes_test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Test shapes:', function() {
6262
}
6363

6464
function countSubplots(gd) {
65-
return Object.getOwnPropertyNames(gd._fullLayout._plots || {}).length;
65+
return Object.keys(gd._fullLayout._plots || {}).length;
6666
}
6767

6868
function countShapePathsInLowerLayer() {
@@ -163,8 +163,7 @@ describe('Test shapes:', function() {
163163
var index = countShapes(gd);
164164
var shape = getRandomShape();
165165

166-
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function()
167-
{
166+
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() {
168167
expect(countShapePathsInUpperLayer()).toEqual(pathCount + 1);
169168
expect(getLastShape(gd)).toEqual(shape);
170169
expect(countShapes(gd)).toEqual(index + 1);
@@ -176,8 +175,7 @@ describe('Test shapes:', function() {
176175
var index = countShapes(gd);
177176
var shape = getRandomShape();
178177

179-
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function()
180-
{
178+
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() {
181179
expect(countShapePathsInUpperLayer()).toEqual(pathCount + 1);
182180
expect(getLastShape(gd)).toEqual(shape);
183181
expect(countShapes(gd)).toEqual(index + 1);

0 commit comments

Comments
 (0)