Skip to content

Fix annotations SVG errors on trace-less subplots #3534

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
merged 3 commits into from
Feb 12, 2019
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
3 changes: 3 additions & 0 deletions src/components/annotations/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ function drawOne(gd, index) {
var xa = Axes.getFromId(gd, options.xref);
var ya = Axes.getFromId(gd, options.yref);

if(xa) xa.setScale();
if(ya) ya.setScale();

drawRaw(gd, options, index, false, xa, ya);
}

Expand Down
29 changes: 27 additions & 2 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,29 @@ function computeTraceBounds(scene, trace, bounds) {
}
}

function computeAnnotationBounds(scene, bounds) {
var sceneLayout = scene.fullSceneLayout;
var annotations = sceneLayout.annotations || [];

for(var d = 0; d < 3; d++) {
var axisName = axisProperties[d];
var axLetter = axisName.charAt(0);
var ax = sceneLayout[axisName];

for(var j = 0; j < annotations.length; j++) {
var ann = annotations[j];

if(ann.visible) {
var pos = ax.r2l(ann[axLetter]);
if(!isNaN(pos) && isFinite(pos)) {
bounds[0][d] = Math.min(bounds[0][d], pos);
bounds[1][d] = Math.max(bounds[1][d], pos);
}
}
}
}
}

proto.plot = function(sceneData, fullLayout, layout) {
// Save parameters
this.plotArgs = [sceneData, fullLayout, layout];
Expand Down Expand Up @@ -443,18 +466,20 @@ proto.plot = function(sceneData, fullLayout, layout) {
[Infinity, Infinity, Infinity],
[-Infinity, -Infinity, -Infinity]
];

for(i = 0; i < sceneData.length; ++i) {
data = sceneData[i];
if(data.visible !== true) continue;

computeTraceBounds(this, data, dataBounds);
}
computeAnnotationBounds(this, dataBounds);

var dataScale = [1, 1, 1];
for(j = 0; j < 3; ++j) {
if(dataBounds[1][j] === dataBounds[0][j]) {
dataScale[j] = 1.0;
}
else {
} else {
dataScale[j] = 1.0 / (dataBounds[1][j] - dataBounds[0][j]);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/image/strict-d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ function checkAttrVal(sel, key, val) {
if(/--/.test(val) && isNumeric(val.split('--')[1].charAt(0))) {
throw new Error('d3 selection.attr called with value ' + val + ' which includes a double negative');
}

if(/transform/.test(key) && /NaN/.test(val)) {
throw new Error('d3 selection.attr called with ' + key + ' ' + val + ' containing a NaN');
}
}

function checkStyleVal(sel, key, val) {
Expand Down
22 changes: 22 additions & 0 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,28 @@ describe('annotations autorange', function() {
.catch(failTest)
.then(done);
});

it('should not error out on subplots w/o visible traces', function(done) {
Plotly.plot(gd, [{}], {
annotations: [{
x: 0.1,
y: 0.1,
text: 't',
showarrow: false
}, {
x: 0.2,
y: 0.3,
text: 'a'
}]
})
.then(function() {
expect(gd._fullLayout.xaxis.range).toBeCloseToArray([0.099, 0.201], 1, 'x rng');
expect(gd._fullLayout.yaxis.range).toBeCloseToArray([0.091, 0.335], 1, 'y rng');
assertVisible([0, 1]);
})
.catch(failTest)
.then(done);
});
});

describe('annotation clicktoshow', function() {
Expand Down