Skip to content

Make sankey respect layout.colorway #2277

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 2 commits into from
Jan 22, 2018
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
3 changes: 2 additions & 1 deletion src/traces/sankey/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

var Lib = require('../../lib');
var attributes = require('./attributes');
var colors = require('../../components/color/attributes').defaults;
var Color = require('../../components/color');
var tinycolor = require('tinycolor2');

Expand All @@ -25,6 +24,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('node.line.color');
coerce('node.line.width');

var colors = layout.colorway;

var defaultNodePalette = function(i) {return colors[i % colors.length];};

coerce('node.color', traceOut.node.label.map(function(d, i) {
Expand Down
Binary file modified test/image/baselines/sankey_energy_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 1 addition & 50 deletions test/image/mocks/sankey_energy_dark.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,56 +71,7 @@
"UK land based bioenergy",
"Wave",
"Wind"
],
"color": [
"rgba(31, 119, 180, 0.8)",
"rgba(255, 127, 14, 0.8)",
"rgba(44, 160, 44, 0.8)",
"rgba(214, 39, 40, 0.8)",
"rgba(148, 103, 189, 0.8)",
"rgba(140, 86, 75, 0.8)",
"rgba(227, 119, 194, 0.8)",
"rgba(127, 127, 127, 0.8)",
"rgba(188, 189, 34, 0.8)",
"rgba(23, 190, 207, 0.8)",
"rgba(31, 119, 180, 0.8)",
"rgba(255, 127, 14, 0.8)",
"rgba(44, 160, 44, 0.8)",
"rgba(214, 39, 40, 0.8)",
"rgba(148, 103, 189, 0.8)",
"rgba(140, 86, 75, 0.8)",
"rgba(227, 119, 194, 0.8)",
"rgba(127, 127, 127, 0.8)",
"rgba(188, 189, 34, 0.8)",
"rgba(23, 190, 207, 0.8)",
"rgba(31, 119, 180, 0.8)",
"rgba(255, 127, 14, 0.8)",
"rgba(44, 160, 44, 0.8)",
"rgba(214, 39, 40, 0.8)",
"rgba(148, 103, 189, 0.8)",
"rgba(140, 86, 75, 0.8)",
"rgba(227, 119, 194, 0.8)",
"rgba(127, 127, 127, 0.8)",
"rgba(188, 189, 34, 0.8)",
"rgba(23, 190, 207, 0.8)",
"rgba(31, 119, 180, 0.8)",
"rgba(255, 127, 14, 0.8)",
"rgba(44, 160, 44, 0.8)",
"rgba(214, 39, 40, 0.8)",
"rgba(148, 103, 189, 0.8)",
"magenta",
"rgba(227, 119, 194, 0.8)",
"rgba(127, 127, 127, 0.8)",
"rgba(188, 189, 34, 0.8)",
"rgba(23, 190, 207, 0.8)",
"rgba(31, 119, 180, 0.8)",
"rgba(255, 127, 14, 0.8)",
"rgba(44, 160, 44, 0.8)",
"rgba(214, 39, 40, 0.8)",
"rgba(148, 103, 189, 0.8)",
"rgba(140, 86, 75, 0.8)",
"rgba(227, 119, 194, 0.8)",
"rgba(127, 127, 127, 0.8)"]
]
},
"link": {
"source": [
Expand Down
24 changes: 22 additions & 2 deletions test/jasmine/tests/sankey_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var fail = require('../assets/fail_test');
var mouseEvent = require('../assets/mouse_event');
var assertHoverLabelStyle = require('../assets/custom_assertions').assertHoverLabelStyle;
var supplyAllDefaults = require('../assets/supply_defaults');
var defaultColors = require('@src/components/color/attributes').defaults;

describe('sankey tests', function() {

Expand All @@ -20,7 +21,7 @@ describe('sankey tests', function() {
function _supply(traceIn) {
var traceOut = { visible: true },
defaultColor = '#444',
layout = { };
layout = { colorway: defaultColors };

Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout);

Expand All @@ -31,7 +32,7 @@ describe('sankey tests', function() {
var traceOut = { visible: true },
defaultColor = '#444';

Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout);
Sankey.supplyDefaults(traceIn, traceOut, defaultColor, Lib.extendFlat({colorway: defaultColors}, layout));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be an overly cautious idea, how about using non-default colors for colorwayhere, or just altering a sankey mock to lock in a visible difference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Actually, given that ('color/attributes').defaults no longer appears explicitly in the sankey code, seems to me that an end-to-end test of the full default-color case may be the most useful of all, so I just stripped explicit colors out of the dark mock -> f2ebc79

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense, and works great with a custom colorway too!


return traceOut;
}
Expand Down Expand Up @@ -179,6 +180,25 @@ describe('sankey tests', function() {
});

expect(Lib.isArray(fullTrace.node.color)).toBe(true, 'set up color array');
expect(fullTrace.node.color).toEqual(['rgba(31, 119, 180, 0.8)', 'rgba(255, 127, 14, 0.8)']);

});

it('respects layout.colorway', function() {

var fullTrace = _supplyWithLayout({
node: {
label: ['a', 'b']
},
link: {
source: [0],
target: [1],
value: [1]
}
}, {colorway: ['rgb(255, 0, 0)', 'rgb(0, 0, 255)']});

expect(Lib.isArray(fullTrace.node.color)).toBe(true, 'set up color array');
expect(fullTrace.node.color).toEqual(['rgba(255, 0, 0, 0.8)', 'rgba(0, 0, 255, 0.8)']);

});

Expand Down