Skip to content

sankey: support uirevision for node.groups #3750

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 1 commit into from
Apr 9, 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
2 changes: 1 addition & 1 deletion src/plot_api/plot_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ var traceUIControlPatterns = [
// "visible" includes trace.transforms[i].styles[j].value.visible
{pattern: /(^|value\.)visible$/, attr: 'legend.uirevision'},
{pattern: /^dimensions\[\d+\]\.constraintrange/},
{pattern: /^node\.(x|y)/}, // for Sankey nodes
{pattern: /^node\.(x|y|groups)/}, // for Sankey nodes
{pattern: /^level$/}, // for Sunburst traces

// below this you must be in editable: true mode
Expand Down
43 changes: 43 additions & 0 deletions test/jasmine/tests/sankey_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var mockCircular = require('@mocks/sankey_circular.json');
var mockCircularLarge = require('@mocks/sankey_circular_large.json');
var mockXY = require('@mocks/sankey_x_y.json');
var Sankey = require('@src/traces/sankey');
var Registry = require('@src/registry');

var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
Expand Down Expand Up @@ -608,6 +609,48 @@ describe('sankey tests', function() {
.catch(failTest)
.then(done);
});

['0', '1'].forEach(function(finalUIRevision) {
it('on Plotly.react, it preserves the groups depending on layout.uirevision', function(done) {
var uirevisions = ['0', finalUIRevision];

var mockCopy = Lib.extendDeep({}, mockCircular);
mockCopy.layout.uirevision = uirevisions[0];

Plotly.plot(gd, mockCopy)
.then(function() {
// Create a group via guiRestyle
return Registry.call('_guiRestyle', gd, 'node.groups', [[[0, 1]]]);
})
.then(function() {
// Check that the nodes are grouped
expect(gd._fullData[0].node.groups).toEqual([[0, 1]]);

// Change color of nodes
mockCopy = Lib.extendDeep({}, mockCircular);
mockCopy.data[0].node.color = 'orange';
mockCopy.layout.uirevision = uirevisions[1];
return Plotly.react(gd, mockCopy);
})
.then(function() {
if(uirevisions[0] === uirevisions[1]) {
// If uirevision is the same, the groups should stay the same
expect(gd._fullData[0].node.groups).toEqual(
[[0, 1]],
'should stay the same because uirevision did not change'
);
} else {
// If uirevision changed, the groups should be empty as in the figure obj
expect(gd._fullData[0].node.groups).toEqual(
[],
'should go back to its default because uirevision changed'
);
}
})
.catch(failTest)
.then(done);
});
});
});

describe('Test hover/click interactions:', function() {
Expand Down