Skip to content

Commit

Permalink
revisit sunburst and treemap percentages
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Sep 24, 2019
1 parent 1309bfd commit 217c0f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/traces/sunburst/fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ module.exports = function attachFxHandlers(sliceTop, entry, gd, cd, opts) {
var thisText = [];
var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };
var getVal = function(d) {
if(d.hasOwnProperty('hierarchy')) return d.hierarchy.value;
return d.hasOwnProperty('v') ? d.v : d.value;
var result = d.hasOwnProperty('v') ? d.v : d.value;
return result !== undefined ? result : hierarchy.value;
};

if(hoverinfo) {
Expand Down
12 changes: 9 additions & 3 deletions src/traces/sunburst/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,15 @@ exports.formatSliceLabel = function(pt, entry, trace, cd, fullLayout) {

var ref;
var getLabel = function(d) {
if(d.hasOwnProperty('hierarchy')) return d.hierarchy.label;
if(!(d.data && d.data.data)) return '';
var id = helpers.getPtId(d);
var id = d.id;
if(d.data) {
id = d.data.id;
if(d.data.data) {
id = d.data.data.id;
}
}
if(!id) return '';

for(var q = 0; q < cd.length; q++) {
if(cd[q].label === id) {
return id;
Expand Down
Binary file modified test/image/baselines/treemap_level-depth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions test/jasmine/tests/sunburst_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ describe('Test sunburst texttemplate without `values` should work:', function()
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
['%{percentRoot} of %{root}', ['100% of Eve', '33% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve']],
['%{percentEntry} of %{entry}', ['100% of Eve', '33% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve']],
['%{percentParent} of %{parent}', ['100% of "root"', '100% of Seth', '33% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '50% of Seth', '100% of Awan']],
['%{percentParent} of %{parent}', ['100% of Eve', '100% of Seth', '33% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '50% of Seth', '100% of Awan']],
[
[
'label: %{label}',
Expand Down Expand Up @@ -1387,7 +1387,7 @@ describe('Test sunburst texttemplate with *total* `values` should work:', functi
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
['%{percentRoot} of %{root}', ['100% of Eve', '22% of Eve', '18% of Eve', '9% of Eve', '9% of Eve', '6% of Eve', '15% of Eve', '3% of Eve', '2% of Eve']],
['%{percentEntry} of %{entry}', ['100% of Eve', '22% of Eve', '18% of Eve', '9% of Eve', '9% of Eve', '6% of Eve', '15% of Eve', '3% of Eve', '2% of Eve']],
['%{percentParent} of %{parent}', ['100% of "root"', '22% of Eve', '18% of Eve', '9% of Eve', '9% of Eve', '6% of Eve', '83% of Seth', '17% of Seth', '17% of Awan']],
['%{percentParent} of %{parent}', ['100% of Eve', '22% of Eve', '18% of Eve', '9% of Eve', '9% of Eve', '6% of Eve', '83% of Seth', '17% of Seth', '17% of Awan']],
[
[
'label: %{label}',
Expand Down Expand Up @@ -1430,7 +1430,7 @@ describe('Test sunburst texttemplate with *remainder* `values` should work:', fu
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
['%{percentRoot} of %{root}', ['54% of Eve', '10% of Eve', '12% of Eve', '5% of Eve', '5% of Eve', '3% of Eve', '8% of Eve', '2% of Eve', '1% of Eve']],
['%{percentEntry} of %{entry}', ['54% of Eve', '10% of Eve', '12% of Eve', '5% of Eve', '5% of Eve', '3% of Eve', '8% of Eve', '2% of Eve', '1% of Eve']],
['%{percentParent} of %{parent}', ['100% of "root"', '10% of Eve', '12% of Eve', '5% of Eve', '5% of Eve', '3% of Eve', '42% of Seth', '8% of Seth', '14% of Awan']],
['%{percentParent} of %{parent}', ['100% of Eve', '10% of Eve', '12% of Eve', '5% of Eve', '5% of Eve', '3% of Eve', '42% of Seth', '8% of Seth', '14% of Awan']],
[
[
'label: %{label}',
Expand Down

0 comments on commit 217c0f4

Please sign in to comment.