Skip to content

Commit

Permalink
Merge pull request #5330 from plotly/fix5328-pick-trace-root-color
Browse files Browse the repository at this point in the history
Pick root.color from treemap/sunburst trace
  • Loading branch information
archmoj authored Dec 8, 2020
2 parents 0dd5467 + 085064e commit 04966b7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/traces/sunburst/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ exports._runCrossTraceCalc = function(desiredType, gd) {
}
var dfltColorCount = 0;

var rootColor;
function pickColor(d) {
var cdi = d.data.data;
var id = cdi.id;
Expand All @@ -277,7 +278,7 @@ exports._runCrossTraceCalc = function(desiredType, gd) {
}
} else {
// set root color. no coloring by default.
cdi.color = cdi.trace.root.color;
cdi.color = rootColor;
}
}
}
Expand All @@ -286,6 +287,7 @@ exports._runCrossTraceCalc = function(desiredType, gd) {
var cd = calcdata[i];
var cd0 = cd[0];
if(cd0.trace.type === desiredType && cd0.hierarchy) {
rootColor = cd0.trace.root.color;
cd0.hierarchy.each(pickColor);
}
}
Expand Down
Binary file added test/image/baselines/treemap_root-color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/image/compare_pixels_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ if(allMock || argv.filter) {

var FLAKY_LIST = [
'treemap_coffee',
'treemap_sunburst_marker_colors',
'treemap_textposition',
'treemap_with-without_values',
'gl3d_directions-streamtube1',
Expand Down
96 changes: 96 additions & 0 deletions test/image/mocks/treemap_root-color.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"data": [
{
"hovertemplate": "labels=%{label}<br>sales=%{value}<br>parent=%{parent}<br>id=%{id}<extra></extra>",
"ids": [
"all/North/Tech/A",
"all/North/Tech/B",
"all/North/Finance/C",
"all/North/Finance/D",
"all/South/Tech/E",
"all/South/Tech/F",
"all/South/Finance/G",
"all/South/Finance/H",
"all/North/Finance",
"all/South/Finance",
"all/North/Other",
"all/South/Other",
"all/North/Tech",
"all/South/Tech",
"all/North",
"all/South",
"all"
],
"labels": [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"Finance",
"Finance",
"Other",
"Other",
"Tech",
"Tech",
"North",
"South",
"all"
],
"name": "",
"parents": [
"all/North/Tech",
"all/North/Tech",
"all/North/Finance",
"all/North/Finance",
"all/South/Tech",
"all/South/Tech",
"all/South/Finance",
"all/South/Finance",
"all/North",
"all/South",
"all/North",
"all/South",
"all/North",
"all/South",
"all",
"all",
""
],
"type": "treemap",
"branchvalues": "total",
"values": [
1,
3,
2,
4,
2,
2,
1,
4,
6,
5,
1,
1,
4,
4,
11,
10,
21
]
}
],
"layout": {
"width": 320,
"height": 200,
"margin": {
"t": 20,
"l": 20,
"r": 20,
"b": 20
}
}
}
2 changes: 2 additions & 0 deletions test/jasmine/tests/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ var list = [
'treemap_packings',
'treemap_pad_mirror',
'treemap_pad_transpose',
'treemap_root-color',
'treemap_sunburst_basic',
'treemap_sunburst_marker_colors',
'treemap_textfit',
Expand Down Expand Up @@ -2077,6 +2078,7 @@ figs['treemap_packages_colorscale_novalue'] = require('@mocks/treemap_packages_c
figs['treemap_packings'] = require('@mocks/treemap_packings');
figs['treemap_pad_mirror'] = require('@mocks/treemap_pad_mirror');
figs['treemap_pad_transpose'] = require('@mocks/treemap_pad_transpose');
figs['treemap_root-color'] = require('@mocks/treemap_root-color');
figs['treemap_sunburst_basic'] = require('@mocks/treemap_sunburst_basic');
figs['treemap_sunburst_marker_colors'] = require('@mocks/treemap_sunburst_marker_colors');
figs['treemap_textfit'] = require('@mocks/treemap_textfit');
Expand Down

0 comments on commit 04966b7

Please sign in to comment.