Skip to content

Fix issue #611 (exception thrown if shapes and an overlaid axis) #612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions src/components/shapes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ function updateShape(gd, index, opt, value) {
plotinfo = plots[subplots[i]];
clipAxes = subplots[i];

if(isShapeInSubplot(gd, options, plotinfo.id)) {
if(isShapeInSubplot(gd, options, plotinfo)) {
drawShape(plotinfo.shapelayer);
}
}
Expand Down Expand Up @@ -362,10 +362,13 @@ function getShapeLayer(gd, index) {
return shapeLayer;
}

function isShapeInSubplot(gd, shape, subplot) {
var xa = Plotly.Axes.getFromId(gd, subplot, 'x')._id,
ya = Plotly.Axes.getFromId(gd, subplot, 'y')._id;
return shape.layer === 'below' && (xa === shape.xref || ya === shape.yref);
function isShapeInSubplot(gd, shape, plotinfo) {
var xa = Plotly.Axes.getFromId(gd, plotinfo.id, 'x')._id,
ya = Plotly.Axes.getFromId(gd, plotinfo.id, 'y')._id,
isBelow = shape.layer === 'below',
inSuplotAxis = (xa === shape.xref || ya === shape.yref),
isNotAnOverlaidSubplot = !!plotinfo.shapelayer;
return isBelow && inSuplotAxis && isNotAnOverlaidSubplot;
}

function decodeDate(convertToPx) {
Expand Down
46 changes: 46 additions & 0 deletions test/jasmine/tests/shapes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,49 @@ describe('Test shapes:', function() {
});
});
});

describe('Test shapes: a plot with shapes and an overlaid axis', function() {
'use strict';

var gd, data, layout;

beforeEach(function() {
gd = createGraphDiv();

data = [{
'y': [1934.5, 1932.3, 1930.3],
'x': ['1947-01-01', '1947-04-01', '1948-07-01'],
'type': 'scatter'
}];

layout = {
'yaxis': {
'type': 'linear'
},
'xaxis': {
'type': 'date'
},
'yaxis2': {
'side': 'right',
'overlaying': 'y'
},
'shapes': [{
'fillcolor': '#ccc',
'type': 'rect',
'x0': '1947-01-01',
'x1': '1947-04-01',
'xref': 'x',
'y0': 0,
'y1': 1,
'yref': 'paper',
'layer': 'below'
}]
};
});

afterEach(destroyGraphDiv);

it('should not throw an exception', function(done) {
Plotly.plot(gd, data, layout).then(done);
});
});