Skip to content

Commit e701b5e

Browse files
authored
Merge pull request #2277 from plotly/sankey-colorway
Make sankey respect layout.colorway
2 parents d9cf4a5 + f2ebc79 commit e701b5e

File tree

4 files changed

+25
-53
lines changed

4 files changed

+25
-53
lines changed

src/traces/sankey/defaults.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
var Lib = require('../../lib');
1212
var attributes = require('./attributes');
13-
var colors = require('../../components/color/attributes').defaults;
1413
var Color = require('../../components/color');
1514
var tinycolor = require('tinycolor2');
1615

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

27+
var colors = layout.colorway;
28+
2829
var defaultNodePalette = function(i) {return colors[i % colors.length];};
2930

3031
coerce('node.color', traceOut.node.label.map(function(d, i) {
80 Bytes
Loading

test/image/mocks/sankey_energy_dark.json

+1-50
Original file line numberDiff line numberDiff line change
@@ -71,56 +71,7 @@
7171
"UK land based bioenergy",
7272
"Wave",
7373
"Wind"
74-
],
75-
"color": [
76-
"rgba(31, 119, 180, 0.8)",
77-
"rgba(255, 127, 14, 0.8)",
78-
"rgba(44, 160, 44, 0.8)",
79-
"rgba(214, 39, 40, 0.8)",
80-
"rgba(148, 103, 189, 0.8)",
81-
"rgba(140, 86, 75, 0.8)",
82-
"rgba(227, 119, 194, 0.8)",
83-
"rgba(127, 127, 127, 0.8)",
84-
"rgba(188, 189, 34, 0.8)",
85-
"rgba(23, 190, 207, 0.8)",
86-
"rgba(31, 119, 180, 0.8)",
87-
"rgba(255, 127, 14, 0.8)",
88-
"rgba(44, 160, 44, 0.8)",
89-
"rgba(214, 39, 40, 0.8)",
90-
"rgba(148, 103, 189, 0.8)",
91-
"rgba(140, 86, 75, 0.8)",
92-
"rgba(227, 119, 194, 0.8)",
93-
"rgba(127, 127, 127, 0.8)",
94-
"rgba(188, 189, 34, 0.8)",
95-
"rgba(23, 190, 207, 0.8)",
96-
"rgba(31, 119, 180, 0.8)",
97-
"rgba(255, 127, 14, 0.8)",
98-
"rgba(44, 160, 44, 0.8)",
99-
"rgba(214, 39, 40, 0.8)",
100-
"rgba(148, 103, 189, 0.8)",
101-
"rgba(140, 86, 75, 0.8)",
102-
"rgba(227, 119, 194, 0.8)",
103-
"rgba(127, 127, 127, 0.8)",
104-
"rgba(188, 189, 34, 0.8)",
105-
"rgba(23, 190, 207, 0.8)",
106-
"rgba(31, 119, 180, 0.8)",
107-
"rgba(255, 127, 14, 0.8)",
108-
"rgba(44, 160, 44, 0.8)",
109-
"rgba(214, 39, 40, 0.8)",
110-
"rgba(148, 103, 189, 0.8)",
111-
"magenta",
112-
"rgba(227, 119, 194, 0.8)",
113-
"rgba(127, 127, 127, 0.8)",
114-
"rgba(188, 189, 34, 0.8)",
115-
"rgba(23, 190, 207, 0.8)",
116-
"rgba(31, 119, 180, 0.8)",
117-
"rgba(255, 127, 14, 0.8)",
118-
"rgba(44, 160, 44, 0.8)",
119-
"rgba(214, 39, 40, 0.8)",
120-
"rgba(148, 103, 189, 0.8)",
121-
"rgba(140, 86, 75, 0.8)",
122-
"rgba(227, 119, 194, 0.8)",
123-
"rgba(127, 127, 127, 0.8)"]
74+
]
12475
},
12576
"link": {
12677
"source": [

test/jasmine/tests/sankey_test.js

+22-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var fail = require('../assets/fail_test');
1212
var mouseEvent = require('../assets/mouse_event');
1313
var assertHoverLabelStyle = require('../assets/custom_assertions').assertHoverLabelStyle;
1414
var supplyAllDefaults = require('../assets/supply_defaults');
15+
var defaultColors = require('@src/components/color/attributes').defaults;
1516

1617
describe('sankey tests', function() {
1718

@@ -20,7 +21,7 @@ describe('sankey tests', function() {
2021
function _supply(traceIn) {
2122
var traceOut = { visible: true },
2223
defaultColor = '#444',
23-
layout = { };
24+
layout = { colorway: defaultColors };
2425

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

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

34-
Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout);
35+
Sankey.supplyDefaults(traceIn, traceOut, defaultColor, Lib.extendFlat({colorway: defaultColors}, layout));
3536

3637
return traceOut;
3738
}
@@ -179,6 +180,25 @@ describe('sankey tests', function() {
179180
});
180181

181182
expect(Lib.isArray(fullTrace.node.color)).toBe(true, 'set up color array');
183+
expect(fullTrace.node.color).toEqual(['rgba(31, 119, 180, 0.8)', 'rgba(255, 127, 14, 0.8)']);
184+
185+
});
186+
187+
it('respects layout.colorway', function() {
188+
189+
var fullTrace = _supplyWithLayout({
190+
node: {
191+
label: ['a', 'b']
192+
},
193+
link: {
194+
source: [0],
195+
target: [1],
196+
value: [1]
197+
}
198+
}, {colorway: ['rgb(255, 0, 0)', 'rgb(0, 0, 255)']});
199+
200+
expect(Lib.isArray(fullTrace.node.color)).toBe(true, 'set up color array');
201+
expect(fullTrace.node.color).toEqual(['rgba(255, 0, 0, 0.8)', 'rgba(0, 0, 255, 0.8)']);
182202

183203
});
184204

0 commit comments

Comments
 (0)