Skip to content

More informative error messages when creating sunburst and treemap charts #5163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/traces/sunburst/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ exports.calc = function(gd, trace) {
label: k
});
} else {
return Lib.warn('Multiple implied roots, cannot build ' + trace.type + ' hierarchy.');
return Lib.warn([
'Multiple implied roots, cannot build', trace.type, 'hierarchy of', trace.name + '.',
'These roots include:', impliedRoots.join(', ')
].join(' '));
}
} else if(parent2children[''].length > 1) {
var dummyId = Lib.randstr();
Expand Down Expand Up @@ -140,7 +143,10 @@ exports.calc = function(gd, trace) {
.id(function(d) { return d.id; })
.parentId(function(d) { return d.pid; })(cd);
} catch(e) {
return Lib.warn('Failed to build ' + trace.type + ' hierarchy. Error: ' + e.message);
return Lib.warn([
'Failed to build', trace.type, 'hierarchy of', trace.name + '.',
'Error:', e.message
].join(' '));
}

var hierarchy = d3Hierarchy.hierarchy(root);
Expand Down Expand Up @@ -170,7 +176,7 @@ exports.calc = function(gd, trace) {
if(v < partialSum * ALMOST_EQUAL) {
failed = true;
return Lib.warn([
'Total value for node', d.data.data.id,
'Total value for node', d.data.data.id, 'of', trace.name,
'is smaller than the sum of its children.',
'\nparent value =', v,
'\nchildren sum =', partialSum
Expand Down
10 changes: 5 additions & 5 deletions test/jasmine/tests/sunburst_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ describe('Test sunburst calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Multiple implied roots, cannot build sunburst hierarchy.');
expect(Lib.warn).toHaveBeenCalledWith('Multiple implied roots, cannot build sunburst hierarchy of trace 0. These roots include: Root1, Root22');
});

it('should generate "root of roots" when it can', function() {
Expand Down Expand Up @@ -299,8 +299,8 @@ describe('Test sunburst calc:', function() {
expect(gd.calcdata[0][0].hierarchy).toBe(undefined, 'no computed hierarchy');

expect(Lib.warn).toHaveBeenCalledTimes(2);
expect(Lib.warn.calls.allArgs()[0][0]).toBe('Total value for node Root is smaller than the sum of its children. \nparent value = 0 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[1][0]).toBe('Total value for node B is smaller than the sum of its children. \nparent value = 2 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[0][0]).toBe('Total value for node Root of trace 0 is smaller than the sum of its children. \nparent value = 0 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[1][0]).toBe('Total value for node B of trace 0 is smaller than the sum of its children. \nparent value = 2 \nchildren sum = 3');
});

it('should warn labels/parents lead to ambiguous hierarchy', function() {
Expand All @@ -310,7 +310,7 @@ describe('Test sunburst calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Failed to build sunburst hierarchy. Error: ambiguous: A');
expect(Lib.warn).toHaveBeenCalledWith('Failed to build sunburst hierarchy of trace 0. Error: ambiguous: A');
});

it('should warn ids/parents lead to ambiguous hierarchy', function() {
Expand All @@ -321,7 +321,7 @@ describe('Test sunburst calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Failed to build sunburst hierarchy. Error: ambiguous: b');
expect(Lib.warn).toHaveBeenCalledWith('Failed to build sunburst hierarchy of trace 0. Error: ambiguous: b');
});

it('should accept numbers (even `0`) are ids/parents items', function() {
Expand Down
10 changes: 5 additions & 5 deletions test/jasmine/tests/treemap_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('Test treemap calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Multiple implied roots, cannot build treemap hierarchy.');
expect(Lib.warn).toHaveBeenCalledWith('Multiple implied roots, cannot build treemap hierarchy of trace 0. These roots include: Root1, Root22');
});

it('should generate "root of roots" when it can', function() {
Expand Down Expand Up @@ -414,8 +414,8 @@ describe('Test treemap calc:', function() {
expect(gd.calcdata[0][0].hierarchy).toBe(undefined, 'no computed hierarchy');

expect(Lib.warn).toHaveBeenCalledTimes(2);
expect(Lib.warn.calls.allArgs()[0][0]).toBe('Total value for node Root is smaller than the sum of its children. \nparent value = 0 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[1][0]).toBe('Total value for node B is smaller than the sum of its children. \nparent value = 2 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[0][0]).toBe('Total value for node Root of trace 0 is smaller than the sum of its children. \nparent value = 0 \nchildren sum = 3');
expect(Lib.warn.calls.allArgs()[1][0]).toBe('Total value for node B of trace 0 is smaller than the sum of its children. \nparent value = 2 \nchildren sum = 3');
});

it('should warn labels/parents lead to ambiguous hierarchy', function() {
Expand All @@ -425,7 +425,7 @@ describe('Test treemap calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Failed to build treemap hierarchy. Error: ambiguous: A');
expect(Lib.warn).toHaveBeenCalledWith('Failed to build treemap hierarchy of trace 0. Error: ambiguous: A');
});

it('should warn ids/parents lead to ambiguous hierarchy', function() {
Expand All @@ -436,7 +436,7 @@ describe('Test treemap calc:', function() {
});

expect(Lib.warn).toHaveBeenCalledTimes(1);
expect(Lib.warn).toHaveBeenCalledWith('Failed to build treemap hierarchy. Error: ambiguous: b');
expect(Lib.warn).toHaveBeenCalledWith('Failed to build treemap hierarchy of trace 0. Error: ambiguous: b');
});

it('should accept numbers (even `0`) are ids/parents items', function() {
Expand Down