diff --git a/src/traces/sunburst/plot.js b/src/traces/sunburst/plot.js index a6e1a3bdc57..c0f31cd05c5 100644 --- a/src/traces/sunburst/plot.js +++ b/src/traces/sunburst/plot.js @@ -564,7 +564,7 @@ exports.formatSliceLabel = function(pt, entry, trace, cd, fullLayout) { obj.percentParentLabel = helpers.formatPercent( obj.percentParent, separators ); - obj.parent = helpers.getPtLabel(parent); + obj.parent = helpers.isHierarchyRoot(pt) ? '' : helpers.getPtLabel(parent); obj.percentEntry = val / helpers.getValue(entry); obj.percentEntryLabel = helpers.formatPercent( diff --git a/test/jasmine/tests/sunburst_test.js b/test/jasmine/tests/sunburst_test.js index 838ba567363..ff90ea65326 100644 --- a/test/jasmine/tests/sunburst_test.js +++ b/test/jasmine/tests/sunburst_test.js @@ -1345,7 +1345,7 @@ describe('Test sunburst texttemplate without `values` should work at root level: ['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']], ['%{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 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']], + ['%{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']], [ [ 'label: %{label}', @@ -1389,7 +1389,7 @@ describe('Test sunburst texttemplate with *total* `values` should work at root l ['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']], ['%{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 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']], + ['%{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']], [ [ 'label: %{label}', @@ -1433,7 +1433,7 @@ describe('Test sunburst texttemplate with *remainder* `values` should work at ro ['path: %{currentPath}', ['path: /', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve/', 'path: Eve', 'path: Eve/Seth', 'path: Eve/Seth/', 'path: Eve/Awan/']], ['%{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']], ['%{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']], - ['%{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']], + ['%{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']], [ [ 'label: %{label}', diff --git a/test/jasmine/tests/treemap_test.js b/test/jasmine/tests/treemap_test.js index 759b2e3afc4..71158659648 100644 --- a/test/jasmine/tests/treemap_test.js +++ b/test/jasmine/tests/treemap_test.js @@ -629,7 +629,7 @@ describe('Test treemap hover:', function() { }); }); -describe('Test treemap hover with levels', function() { +describe('Test treemap hover with and without levels', function() { var gd; 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() { t.type = 'treemap'; t.text = text0; t.values = values0; - t.level = 'Oscar'; + t.level = spec.level; t.branchvalues = 'total'; t.hovertemplate = 'path = %{currentPath}
label = %{label}
text = %{text}
value = %{value}
ratio to %{parent} = %{percentParent}
ratio to %{entry} = %{percentEntry}
ratio to %{root} = %{percentRoot}'; @@ -685,6 +685,23 @@ describe('Test treemap hover with levels', function() { [{ desc: 'entry', + level: 'X ray', + pos: 0, + exp: { + label: { + name: 'trace 0', + 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', + }, + ptData: { + curveNumber: 0, + pointNumber: 23, + label: 'X ray', + parent: 'Uniform' + } + } + }, { + desc: 'entry', + level: 'Oscar', pos: 0, exp: { label: { @@ -700,6 +717,7 @@ describe('Test treemap hover with levels', function() { } }, { desc: 'leaf', + level: 'Oscar', pos: 10, exp: { label: { @@ -713,69 +731,9 @@ describe('Test treemap hover with levels', function() { parent: 'Uniform' } } - }] - .forEach(function(spec) { - it('should generate correct hover labels and event data - ' + spec.desc, function(done) { - run(spec).catch(failTest).then(done); - }); - }); -}); - -describe('Test treemap hover at root level', function() { - var gd; - - 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']; - 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']; - 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]; - 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']; - - afterEach(destroyGraphDiv); - - function run(spec) { - gd = createGraphDiv(); - - var data = (spec.traces || [{}]).map(function(t) { - t.type = 'treemap'; - t.text = text0; - t.values = values0; - t.branchvalues = 'total'; - t.hovertemplate = 'path = %{currentPath}
label = %{label}
text = %{text}
value = %{value}
ratio to %{parent} = %{percentParent}
ratio to %{entry} = %{percentEntry}
ratio to %{root} = %{percentRoot}'; - - if(!t.labels) t.labels = labels0.slice(); - if(!t.parents) t.parents = parents0.slice(); - return t; - }); - - var layout = Lib.extendFlat({ - width: 500, - height: 500, - margin: {t: 0, b: 0, l: 0, r: 0, pad: 0} - }, spec.layout || {}); - - var exp = spec.exp || {}; - var ptData = null; - - return Plotly.plot(gd, data, layout) - .then(function() { - gd.once('plotly_hover', function(d) { ptData = d.points[0]; }); - }) - .then(hover(gd, spec.pos)) - .then(function() { - assertHoverLabelContent(exp.label); - - for(var k in exp.ptData) { - expect(ptData[k]).toBe(exp.ptData[k], 'pt event data key ' + k); - } - - if(exp.style) { - var gd3 = d3.select(gd); - assertHoverLabelStyle(gd3.select('.hovertext'), exp.style); - } - }); - } - - [{ + }, { desc: 'entry', + level: undefined, // root pos: 0, exp: { label: { @@ -791,6 +749,7 @@ describe('Test treemap hover at root level', function() { } }, { desc: 'leaf', + level: undefined, // root pos: 10, exp: { label: { @@ -806,7 +765,7 @@ describe('Test treemap hover at root level', function() { } }] .forEach(function(spec) { - it('should generate correct hover labels and event data - ' + spec.desc, function(done) { + it('should generate correct hover labels and event data - ' + spec.desc + ' with level:' + spec.level, function(done) { run(spec).catch(failTest).then(done); }); });