Skip to content

Commit 21b0341

Browse files
committed
Merge pull request #612 from n-riesco/fix-issue-611-exception-with-shapes-and-two-y-axes
Fix issue #611 (exception thrown if shapes and an overlaid axis)
2 parents ff3f572 + be61173 commit 21b0341

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

src/components/shapes/index.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function updateShape(gd, index, opt, value) {
325325
plotinfo = plots[subplots[i]];
326326
clipAxes = subplots[i];
327327

328-
if(isShapeInSubplot(gd, options, plotinfo.id)) {
328+
if(isShapeInSubplot(gd, options, plotinfo)) {
329329
drawShape(plotinfo.shapelayer);
330330
}
331331
}
@@ -362,10 +362,13 @@ function getShapeLayer(gd, index) {
362362
return shapeLayer;
363363
}
364364

365-
function isShapeInSubplot(gd, shape, subplot) {
366-
var xa = Plotly.Axes.getFromId(gd, subplot, 'x')._id,
367-
ya = Plotly.Axes.getFromId(gd, subplot, 'y')._id;
368-
return shape.layer === 'below' && (xa === shape.xref || ya === shape.yref);
365+
function isShapeInSubplot(gd, shape, plotinfo) {
366+
var xa = Plotly.Axes.getFromId(gd, plotinfo.id, 'x')._id,
367+
ya = Plotly.Axes.getFromId(gd, plotinfo.id, 'y')._id,
368+
isBelow = shape.layer === 'below',
369+
inSuplotAxis = (xa === shape.xref || ya === shape.yref),
370+
isNotAnOverlaidSubplot = !!plotinfo.shapelayer;
371+
return isBelow && inSuplotAxis && isNotAnOverlaidSubplot;
369372
}
370373

371374
function decodeDate(convertToPx) {

test/jasmine/tests/shapes_test.js

+46
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,49 @@ describe('Test shapes:', function() {
236236
});
237237
});
238238
});
239+
240+
describe('Test shapes: a plot with shapes and an overlaid axis', function() {
241+
'use strict';
242+
243+
var gd, data, layout;
244+
245+
beforeEach(function() {
246+
gd = createGraphDiv();
247+
248+
data = [{
249+
'y': [1934.5, 1932.3, 1930.3],
250+
'x': ['1947-01-01', '1947-04-01', '1948-07-01'],
251+
'type': 'scatter'
252+
}];
253+
254+
layout = {
255+
'yaxis': {
256+
'type': 'linear'
257+
},
258+
'xaxis': {
259+
'type': 'date'
260+
},
261+
'yaxis2': {
262+
'side': 'right',
263+
'overlaying': 'y'
264+
},
265+
'shapes': [{
266+
'fillcolor': '#ccc',
267+
'type': 'rect',
268+
'x0': '1947-01-01',
269+
'x1': '1947-04-01',
270+
'xref': 'x',
271+
'y0': 0,
272+
'y1': 1,
273+
'yref': 'paper',
274+
'layer': 'below'
275+
}]
276+
};
277+
});
278+
279+
afterEach(destroyGraphDiv);
280+
281+
it('should not throw an exception', function(done) {
282+
Plotly.plot(gd, data, layout).then(done);
283+
});
284+
});

0 commit comments

Comments
 (0)