Skip to content

Commit e88656c

Browse files
committed
add test for components on category axes zoom/pan
1 parent b5da4fb commit e88656c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/jasmine/tests/plot_api_test.js

+78
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var subroutines = require('@src/plot_api/subroutines');
1010
var helpers = require('@src/plot_api/helpers');
1111

1212
var d3 = require('d3');
13+
var customMatchers = require('../assets/custom_matchers');
1314
var createGraphDiv = require('../assets/create_graph_div');
1415
var destroyGraphDiv = require('../assets/destroy_graph_div');
1516
var fail = require('../assets/fail_test');
@@ -105,6 +106,10 @@ describe('Test plot api', function() {
105106
describe('Plotly.relayout', function() {
106107
var gd;
107108

109+
beforeAll(function() {
110+
jasmine.addMatchers(customMatchers);
111+
});
112+
108113
beforeEach(function() {
109114
gd = createGraphDiv();
110115
});
@@ -252,6 +257,79 @@ describe('Test plot api', function() {
252257
.catch(fail)
253258
.then(done);
254259
});
260+
261+
it('annotations, shapes and images linked to category axes should update properly on zoom/pan', function(done) {
262+
var jsLogo = 'https://images.plot.ly/language-icons/api-home/js-logo.png';
263+
264+
function getPos(sel) {
265+
var rect = sel.node().getBoundingClientRect();
266+
return [rect.left, rect.bottom];
267+
}
268+
269+
function getAnnotationPos() {
270+
return getPos(d3.select('.annotation'));
271+
}
272+
273+
function getShapePos() {
274+
return getPos(d3.select('.layer-above').select('.shapelayer').select('path'));
275+
}
276+
277+
function getImagePos() {
278+
return getPos(d3.select('.layer-above').select('.imagelayer').select('image'));
279+
}
280+
281+
Plotly.plot(gd, [{
282+
x: ['a', 'b', 'c'],
283+
y: [1, 2, 1]
284+
}], {
285+
xaxis: {range: [-1, 5]},
286+
annotations: [{
287+
xref: 'x',
288+
yref: 'y',
289+
x: 'b',
290+
y: 2
291+
}],
292+
shapes: [{
293+
xref: 'x',
294+
yref: 'y',
295+
type: 'line',
296+
x0: 'c',
297+
x1: 'c',
298+
y0: -1,
299+
y1: 4
300+
}],
301+
images: [{
302+
xref: 'x',
303+
yref: 'y',
304+
source: jsLogo,
305+
x: 'a',
306+
y: 1,
307+
sizex: 0.2,
308+
sizey: 0.2
309+
}]
310+
})
311+
.then(function() {
312+
expect(getAnnotationPos()).toBeCloseToArray([247.5, 210.1]);
313+
expect(getShapePos()).toBeCloseToArray([350, 369]);
314+
expect(getImagePos()).toBeCloseToArray([170, 272.52]);
315+
316+
return Plotly.relayout(gd, 'xaxis.range', [0, 2]);
317+
})
318+
.then(function() {
319+
expect(getAnnotationPos()).toBeCloseToArray([337.5, 210.1]);
320+
expect(getShapePos()).toBeCloseToArray([620, 369]);
321+
expect(getImagePos()).toBeCloseToArray([80, 272.52]);
322+
323+
return Plotly.relayout(gd, 'xaxis.range', [-1, 5]);
324+
})
325+
.then(function() {
326+
expect(getAnnotationPos()).toBeCloseToArray([247.5, 210.1]);
327+
expect(getShapePos()).toBeCloseToArray([350, 369]);
328+
expect(getImagePos()).toBeCloseToArray([170, 272.52]);
329+
})
330+
.catch(fail)
331+
.then(done);
332+
});
255333
});
256334

257335
describe('Plotly.restyle subroutines switchboard', function() {

0 commit comments

Comments
 (0)