Skip to content

Commit 217c0f4

Browse files
committedSep 24, 2019
revisit sunburst and treemap percentages
1 parent 1309bfd commit 217c0f4

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed
 

‎src/traces/sunburst/fx.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ module.exports = function attachFxHandlers(sliceTop, entry, gd, cd, opts) {
7575
var thisText = [];
7676
var hasFlag = function(flag) { return parts.indexOf(flag) !== -1; };
7777
var getVal = function(d) {
78-
if(d.hasOwnProperty('hierarchy')) return d.hierarchy.value;
79-
return d.hasOwnProperty('v') ? d.v : d.value;
78+
var result = d.hasOwnProperty('v') ? d.v : d.value;
79+
return result !== undefined ? result : hierarchy.value;
8080
};
8181

8282
if(hoverinfo) {

‎src/traces/sunburst/plot.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,15 @@ exports.formatSliceLabel = function(pt, entry, trace, cd, fullLayout) {
493493

494494
var ref;
495495
var getLabel = function(d) {
496-
if(d.hasOwnProperty('hierarchy')) return d.hierarchy.label;
497-
if(!(d.data && d.data.data)) return '';
498-
var id = helpers.getPtId(d);
496+
var id = d.id;
497+
if(d.data) {
498+
id = d.data.id;
499+
if(d.data.data) {
500+
id = d.data.data.id;
501+
}
502+
}
503+
if(!id) return '';
504+
499505
for(var q = 0; q < cd.length; q++) {
500506
if(cd[q].label === id) {
501507
return id;
-46 Bytes
Loading

‎test/jasmine/tests/sunburst_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ describe('Test sunburst texttemplate without `values` should work:', function()
13441344
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
13451345
['%{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']],
13461346
['%{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']],
1347-
['%{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']],
1347+
['%{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']],
13481348
[
13491349
[
13501350
'label: %{label}',
@@ -1387,7 +1387,7 @@ describe('Test sunburst texttemplate with *total* `values` should work:', functi
13871387
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
13881388
['%{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']],
13891389
['%{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']],
1390-
['%{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']],
1390+
['%{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']],
13911391
[
13921392
[
13931393
'label: %{label}',
@@ -1430,7 +1430,7 @@ describe('Test sunburst texttemplate with *remainder* `values` should work:', fu
14301430
['text: %{text}', ['text: sixty-five', 'text: fourteen', 'text: twelve', 'text: ten', 'text: two', 'text: six', 'text: six', 'text: one', 'text: four']],
14311431
['%{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']],
14321432
['%{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']],
1433-
['%{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']],
1433+
['%{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']],
14341434
[
14351435
[
14361436
'label: %{label}',

0 commit comments

Comments
 (0)
Please sign in to comment.