Skip to content

Commit ed83238

Browse files
committed
Test images and shapes
1 parent f587772 commit ed83238

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

src/plots/cartesian/transition_axes.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
101101
var affectedSubplots = computeAffectedSubplots(fullLayout, updatedAxisIds, updates);
102102

103103
function updateLayoutObjs() {
104-
function redrawObjs(objArray, method) {
104+
function redrawObjs(objArray, method, shortCircuit) {
105105
for(var i = 0; i < objArray.length; i++) {
106106
method(gd, i);
107+
108+
// once is enough for images (which doesn't use the `i` arg anyway)
109+
if(shortCircuit) return;
107110
}
108111
}
109112

110113
redrawObjs(fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
111114
redrawObjs(fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
112-
redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'));
115+
redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
113116
}
114117

115118
if(!affectedSubplots.length) {
@@ -127,23 +130,23 @@ module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCo
127130
Axes.doTicks(gd, activeAxIds[i], true);
128131
}
129132

130-
function redrawObjs(objArray, method) {
133+
function redrawObjs(objArray, method, shortCircuit) {
131134
for(i = 0; i < objArray.length; i++) {
132135
var obji = objArray[i];
133136

134137
if((activeAxIds.indexOf(obji.xref) !== -1) ||
135138
(activeAxIds.indexOf(obji.yref) !== -1)) {
136139
method(gd, i);
137140
}
141+
142+
// once is enough for images (which doesn't use the `i` arg anyway)
143+
if(shortCircuit) return;
138144
}
139145
}
140146

141-
// annotations and shapes 'draw' method is slow,
142-
// use the finer-grained 'drawOne' method instead
143-
144147
redrawObjs(fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
145148
redrawObjs(fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
146-
redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'));
149+
redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
147150
}
148151

149152
function unsetSubplotTransform(subplot) {

test/jasmine/tests/annotations_test.js

+45-3
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,10 @@ describe('annotation effects', function() {
13481348
describe('animating annotations', function() {
13491349
var gd;
13501350

1351+
// Two slightly different 1x1 pngs:
1352+
var img1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4z/C/HgAGfgJ+p8YU1AAAAABJRU5ErkJggg==';
1353+
var img2 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQYV2P4//9/PQAJewN9w0ic/wAAAABJRU5ErkJggg==';
1354+
13511355
beforeEach(function() {
13521356
gd = createGraphDiv();
13531357
});
@@ -1360,24 +1364,62 @@ describe('animating annotations', function() {
13601364
var texts = Plotly.d3.select(gd).selectAll('.annotation .annotation-text');
13611365
expect(expected.length).toEqual(texts.size());
13621366

1363-
texts.each(function(i) {
1367+
texts.each(function(d, i) {
13641368
expect(Plotly.d3.select(this).text()).toEqual(expected[i]);
13651369
});
13661370
}
13671371

1372+
function assertShapes(expected) {
1373+
var paths = Plotly.d3.select(gd).selectAll('.shapelayer path');
1374+
1375+
expect(expected.length).toEqual(paths.size());
1376+
1377+
paths.each(function(d, i) {
1378+
expect(Plotly.d3.select(this).style('fill')).toEqual(expected[i]);
1379+
});
1380+
}
1381+
1382+
function assertImages(expected) {
1383+
var imgs = Plotly.d3.select(gd).selectAll('.imagelayer image');
1384+
1385+
expect(expected.length).toEqual(imgs.size());
1386+
1387+
imgs.each(function(d, i) {
1388+
expect(Plotly.d3.select(this).attr('href')).toEqual(expected[i]);
1389+
});
1390+
}
1391+
13681392
Plotly.plot(gd,
13691393
[{y: [1, 2, 3]}],
1370-
{annotations: [{text: 'hello'}]}
1394+
{
1395+
annotations: [{text: 'hello'}],
1396+
shapes: [{fillcolor: 'rgb(170, 170, 170)'}],
1397+
images: [{source: img1}]
1398+
}
13711399
).then(function() {
13721400
assertAnnotations(['hello']);
1401+
assertShapes(['rgb(170, 170, 170)']);
1402+
assertImages([img1]);
13731403

13741404
return Plotly.animate(gd, [{
1375-
layout: {annotations: [{text: 'hi'}]}
1405+
layout: {
1406+
annotations: [{text: 'hi'}],
1407+
shapes: [
1408+
{fillcolor: 'rgb(171, 171, 171)'},
1409+
{fillcolor: 'rgb(172, 172, 172)'}
1410+
],
1411+
images: [{source: img2}]
1412+
}
13761413
}], {
13771414
frame: {redraw: false, duration: 0}
13781415
});
13791416
}).then(function() {
13801417
assertAnnotations(['hi']);
1418+
assertShapes([
1419+
'rgb(171, 171, 171)',
1420+
'rgb(172, 172, 172)'
1421+
]);
1422+
assertImages([img2]);
13811423

13821424
}).catch(failTest).then(done);
13831425
});

0 commit comments

Comments
 (0)