Skip to content

Commit

Permalink
Merge pull request #2277 from plotly/sankey-colorway
Browse files Browse the repository at this point in the history
Make sankey respect layout.colorway
  • Loading branch information
alexcjohnson authored Jan 22, 2018
2 parents d9cf4a5 + f2ebc79 commit e701b5e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 53 deletions.
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));

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

0 comments on commit e701b5e

Please sign in to comment.