Skip to content

Commit 54360be

Browse files
committed
handle parent of root special case - combine two treemap hovertemplate tests
1 parent df5e121 commit 54360be

File tree

3 files changed

+28
-69
lines changed

3 files changed

+28
-69
lines changed

src/traces/sunburst/plot.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ exports.formatSliceLabel = function(pt, entry, trace, cd, fullLayout) {
564564
obj.percentParentLabel = helpers.formatPercent(
565565
obj.percentParent, separators
566566
);
567-
obj.parent = helpers.getPtLabel(parent);
567+
obj.parent = helpers.isHierarchyRoot(pt) ? '' : helpers.getPtLabel(parent);
568568

569569
obj.percentEntry = val / helpers.getValue(entry);
570570
obj.percentEntryLabel = helpers.formatPercent(

test/jasmine/tests/sunburst_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ describe('Test sunburst texttemplate without `values` should work at root level:
13451345
['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']],
13461346
['%{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']],
13471347
['%{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']],
1348-
['%{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']],
1348+
['%{percentParent} of %{parent}', ['100% of ', '100% of Seth', '33% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '17% of Eve', '50% of Seth', '100% of Awan']],
13491349
[
13501350
[
13511351
'label: %{label}',
@@ -1389,7 +1389,7 @@ describe('Test sunburst texttemplate with *total* `values` should work at root l
13891389
['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']],
13901390
['%{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']],
13911391
['%{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']],
1392-
['%{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']],
1392+
['%{percentParent} of %{parent}', ['100% of ', '22% of Eve', '18% of Eve', '9% of Eve', '9% of Eve', '6% of Eve', '83% of Seth', '17% of Seth', '17% of Awan']],
13931393
[
13941394
[
13951395
'label: %{label}',
@@ -1433,7 +1433,7 @@ describe('Test sunburst texttemplate with *remainder* `values` should work at ro
14331433
['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']],
14341434
['%{percentRoot} of %{root}', ['100% of Eve', '20% of Eve', '12% of Eve', '6% of Eve', '5% of Eve', '3% of Eve', '8% of Eve', '2% of Eve', '1% of Eve']],
14351435
['%{percentEntry} of %{entry}', ['100% of Eve', '20% of Eve', '12% of Eve', '6% of Eve', '5% of Eve', '3% of Eve', '8% of Eve', '2% of Eve', '1% of Eve']],
1436-
['%{percentParent} of %{parent}', ['100% of Eve', '20% of Eve', '12% of Eve', '6% of Eve', '5% of Eve', '3% of Eve', '42% of Seth', '8% of Seth', '14% of Awan']],
1436+
['%{percentParent} of %{parent}', ['100% of ', '20% of Eve', '12% of Eve', '6% of Eve', '5% of Eve', '3% of Eve', '42% of Seth', '8% of Seth', '14% of Awan']],
14371437
[
14381438
[
14391439
'label: %{label}',

test/jasmine/tests/treemap_test.js

+24-65
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ describe('Test treemap hover:', function() {
629629
});
630630
});
631631

632-
describe('Test treemap hover with levels', function() {
632+
describe('Test treemap hover with and without levels', function() {
633633
var gd;
634634

635635
var labels0 = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel', 'India', 'Juliet', 'Kilo', 'Lima', 'Mike', 'November', 'Oscar', 'Papa', 'Quebec', 'Romeo', 'Sierra', 'Tango', 'Uniform', 'Victor', 'Whiskey', 'X ray', 'Yankee', 'Zulu'];
@@ -646,7 +646,7 @@ describe('Test treemap hover with levels', function() {
646646
t.type = 'treemap';
647647
t.text = text0;
648648
t.values = values0;
649-
t.level = 'Oscar';
649+
t.level = spec.level;
650650
t.branchvalues = 'total';
651651
t.hovertemplate = 'path = %{currentPath}<br>label = %{label}<br>text = %{text}<br>value = %{value}<br>ratio to %{parent} = %{percentParent}<br>ratio to %{entry} = %{percentEntry}<br>ratio to %{root} = %{percentRoot}';
652652

@@ -685,6 +685,23 @@ describe('Test treemap hover with levels', function() {
685685

686686
[{
687687
desc: 'entry',
688+
level: 'X ray',
689+
pos: 0,
690+
exp: {
691+
label: {
692+
name: 'trace 0',
693+
nums: 'path = Alpha/Charlie/Foxtrot/Juliet/Oscar/Uniform/\nlabel = X ray\ntext = two\nvalue = 2\nratio to Uniform = 0.2\nratio to X ray = 1\nratio to Alpha = 0.05',
694+
},
695+
ptData: {
696+
curveNumber: 0,
697+
pointNumber: 23,
698+
label: 'X ray',
699+
parent: 'Uniform'
700+
}
701+
}
702+
}, {
703+
desc: 'entry',
704+
level: 'Oscar',
688705
pos: 0,
689706
exp: {
690707
label: {
@@ -700,6 +717,7 @@ describe('Test treemap hover with levels', function() {
700717
}
701718
}, {
702719
desc: 'leaf',
720+
level: 'Oscar',
703721
pos: 10,
704722
exp: {
705723
label: {
@@ -713,69 +731,9 @@ describe('Test treemap hover with levels', function() {
713731
parent: 'Uniform'
714732
}
715733
}
716-
}]
717-
.forEach(function(spec) {
718-
it('should generate correct hover labels and event data - ' + spec.desc, function(done) {
719-
run(spec).catch(failTest).then(done);
720-
});
721-
});
722-
});
723-
724-
describe('Test treemap hover at root level', function() {
725-
var gd;
726-
727-
var labels0 = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel', 'India', 'Juliet', 'Kilo', 'Lima', 'Mike', 'November', 'Oscar', 'Papa', 'Quebec', 'Romeo', 'Sierra', 'Tango', 'Uniform', 'Victor', 'Whiskey', 'X ray', 'Yankee', 'Zulu'];
728-
var parents0 = ['', 'Alpha', 'Alpha', 'Charlie', 'Charlie', 'Charlie', 'Foxtrot', 'Foxtrot', 'Foxtrot', 'Foxtrot', 'Juliet', 'Juliet', 'Juliet', 'Juliet', 'Juliet', 'Oscar', 'Oscar', 'Oscar', 'Oscar', 'Oscar', 'Oscar', 'Uniform', 'Uniform', 'Uniform', 'Uniform', 'Uniform', 'Uniform'];
729-
var values0 = [40, 2, 38, 1.5, 2.5, 34, 1, 2, 3, 28, 1.25, 1.75, 2.25, 2.75, 20, 1, 1.5, 2, 2.5, 3, 10, 1, 1.5, 2, 2.5, 3];
730-
var text0 = ['forty', 'two', 'thirty-eight', 'one and a half', 'two and a half', 'thirty-four', 'one', 'two', 'three', 'twenty-eight', 'one and twenty-five hundredths', 'one and seventy-five hundredths', 'two and twenty-five hundredths', 'two and seventy-five hundredths', 'twenty', 'one', 'one and a half', 'two', 'two and a half', 'three', 'ten', 'one', 'one and a half', 'two', 'two and a half', 'three'];
731-
732-
afterEach(destroyGraphDiv);
733-
734-
function run(spec) {
735-
gd = createGraphDiv();
736-
737-
var data = (spec.traces || [{}]).map(function(t) {
738-
t.type = 'treemap';
739-
t.text = text0;
740-
t.values = values0;
741-
t.branchvalues = 'total';
742-
t.hovertemplate = 'path = %{currentPath}<br>label = %{label}<br>text = %{text}<br>value = %{value}<br>ratio to %{parent} = %{percentParent}<br>ratio to %{entry} = %{percentEntry}<br>ratio to %{root} = %{percentRoot}';
743-
744-
if(!t.labels) t.labels = labels0.slice();
745-
if(!t.parents) t.parents = parents0.slice();
746-
return t;
747-
});
748-
749-
var layout = Lib.extendFlat({
750-
width: 500,
751-
height: 500,
752-
margin: {t: 0, b: 0, l: 0, r: 0, pad: 0}
753-
}, spec.layout || {});
754-
755-
var exp = spec.exp || {};
756-
var ptData = null;
757-
758-
return Plotly.plot(gd, data, layout)
759-
.then(function() {
760-
gd.once('plotly_hover', function(d) { ptData = d.points[0]; });
761-
})
762-
.then(hover(gd, spec.pos))
763-
.then(function() {
764-
assertHoverLabelContent(exp.label);
765-
766-
for(var k in exp.ptData) {
767-
expect(ptData[k]).toBe(exp.ptData[k], 'pt event data key ' + k);
768-
}
769-
770-
if(exp.style) {
771-
var gd3 = d3.select(gd);
772-
assertHoverLabelStyle(gd3.select('.hovertext'), exp.style);
773-
}
774-
});
775-
}
776-
777-
[{
734+
}, {
778735
desc: 'entry',
736+
level: undefined, // root
779737
pos: 0,
780738
exp: {
781739
label: {
@@ -791,6 +749,7 @@ describe('Test treemap hover at root level', function() {
791749
}
792750
}, {
793751
desc: 'leaf',
752+
level: undefined, // root
794753
pos: 10,
795754
exp: {
796755
label: {
@@ -806,7 +765,7 @@ describe('Test treemap hover at root level', function() {
806765
}
807766
}]
808767
.forEach(function(spec) {
809-
it('should generate correct hover labels and event data - ' + spec.desc, function(done) {
768+
it('should generate correct hover labels and event data - ' + spec.desc + ' with level:' + spec.level, function(done) {
810769
run(spec).catch(failTest).then(done);
811770
});
812771
});

0 commit comments

Comments
 (0)