diff --git a/draftlogs/8197_fix.md b/draftlogs/8197_fix.md new file mode 100644 index 00000000000..d8a0e42541f --- /dev/null +++ b/draftlogs/8197_fix.md @@ -0,0 +1 @@ +- Fix transitions completing early when another graph starts one [[#8197](https://github.com/plotly/plotly.js/pull/8197)] diff --git a/src/traces/quiver/plot.js b/src/traces/quiver/plot.js index d59cf616978..727e879f24e 100644 --- a/src/traces/quiver/plot.js +++ b/src/traces/quiver/plot.js @@ -49,7 +49,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition onComplete = makeOnCompleteCallback(); } - var transition = d3.transition() + var transition = scatterLayer.transition() .duration(transitionOpts.duration) .ease(transitionOpts.easing) .each('end', function() { diff --git a/src/traces/scatter/plot.js b/src/traces/scatter/plot.js index 3c9e19df936..c309f38050d 100644 --- a/src/traces/scatter/plot.js +++ b/src/traces/scatter/plot.js @@ -45,7 +45,7 @@ module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transition onComplete = makeOnCompleteCallback(); } - var transition = d3.transition() + var transition = scatterLayer.transition() .duration(transitionOpts.duration) .ease(transitionOpts.easing) .each('end', function() { diff --git a/src/traces/sunburst/plot.js b/src/traces/sunburst/plot.js index 3708e2b8136..dacf7195b20 100644 --- a/src/traces/sunburst/plot.js +++ b/src/traces/sunburst/plot.js @@ -49,7 +49,7 @@ exports.plot = function (gd, cdmodule, transitionOpts, makeOnCompleteCallback) { onComplete = makeOnCompleteCallback(); } - var transition = d3 + var transition = layer .transition() .duration(transitionOpts.duration) .ease(transitionOpts.easing) diff --git a/src/traces/treemap/draw.js b/src/traces/treemap/draw.js index 9fa5a7126c2..2a3930cd320 100644 --- a/src/traces/treemap/draw.js +++ b/src/traces/treemap/draw.js @@ -1,7 +1,5 @@ 'use strict'; -var d3 = require('@plotly/d3'); - var helpers = require('../sunburst/helpers'); var uniformText = require('../bar/uniform_text'); var clearMinTextSize = uniformText.clearMinTextSize; @@ -40,7 +38,7 @@ module.exports = function _plot(gd, cdmodule, transitionOpts, makeOnCompleteCall onComplete = makeOnCompleteCallback(); } - var transition = d3.transition() + var transition = layer.transition() .duration(transitionOpts.duration) .ease(transitionOpts.easing) .each('end', function() { onComplete && onComplete(); }) diff --git a/test/jasmine/tests/transition_test.js b/test/jasmine/tests/transition_test.js index ceba1cc4a66..84a01d6a16c 100644 --- a/test/jasmine/tests/transition_test.js +++ b/test/jasmine/tests/transition_test.js @@ -1183,3 +1183,74 @@ describe('Plotly.react transitions:', function() { .then(done, done.fail); }); }); + +describe('Plotly.react transitions on several graphs:', function() { + var gd, gd2; + + beforeEach(function() { + gd = createGraphDiv(); + gd2 = createGraphDiv('graph2'); + }); + + afterEach(function() { + Plotly.purge(gd); + Plotly.purge(gd2); + document.body.removeChild(gd2); + destroyGraphDiv(); + }); + + it('should not complete a scatter transition when another graph starts one', function(done) { + var duration = 300; + var layout = {transition: {duration: duration}}; + var t0, elapsed; + + Plotly.newPlot(gd, [{y: [1, 2, 1]}], layout) + .then(function() { return Plotly.newPlot(gd2, [{y: [1, 2, 1]}], layout); }) + .then(function() { + t0 = Date.now(); + var first = Plotly.react(gd, [{y: [2, 1, 2]}], layout).then(function() { + elapsed = Date.now() - t0; + }); + var second = Plotly.react(gd2, [{y: [2, 1, 2]}], layout); + return Promise.all([first, second]); + }) + .then(function() { + expect(elapsed).toBeGreaterThan(duration - 50, 'time until the first graph resolved'); + }) + .then(done, done.fail); + }); + + it('should keep a sunburst\'s leaving slices when another graph starts a transition', function(done) { + function makeData(level) { + return [{ + type: 'sunburst', + labels: ['A', 'B', 'C', 'D', 'E'], + parents: ['', 'A', 'A', 'B', 'B'], + level: level + }]; + } + + var layout = {transition: {duration: 300}}; + var promises; + + function countSlices() { return gd.querySelectorAll('.sunburst .slice').length; } + + Plotly.newPlot(gd, makeData(''), layout) + .then(function() { return Plotly.newPlot(gd2, makeData(''), layout); }) + .then(function() { + expect(countSlices()).toBe(5, '# of slices before'); + promises = [Plotly.react(gd, makeData('B'), layout), Plotly.react(gd2, makeData('B'), layout)]; + }) + .then(delay(100)) + .then(function() { + // A and C are leaving; they are removed by the redraw at the end of the transition + expect(countSlices()).toBe(5, '# of slices mid-transition'); + return Promise.all(promises); + }) + .then(delay(50)) + .then(function() { + expect(countSlices()).toBe(3, '# of slices after'); + }) + .then(done, done.fail); + }); +});