Skip to content
Open
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
1 change: 1 addition & 0 deletions draftlogs/8197_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix transitions completing early when another graph starts one [[#8197](https://github.com/plotly/plotly.js/pull/8197)]
2 changes: 1 addition & 1 deletion src/traces/quiver/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/traces/treemap/draw.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(); })
Expand Down
71 changes: 71 additions & 0 deletions test/jasmine/tests/transition_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});