Skip to content

Commit b521323

Browse files
authored
Merge pull request #5163 from plotly/fix5160-improve-tree-error
More informative error messages when creating sunburst and treemap charts
2 parents 38e528e + 4a896ae commit b521323

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

src/traces/sunburst/calc.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,10 @@ exports.calc = function(gd, trace) {
111111
label: k
112112
});
113113
} else {
114-
return Lib.warn('Multiple implied roots, cannot build ' + trace.type + ' hierarchy.');
114+
return Lib.warn([
115+
'Multiple implied roots, cannot build', trace.type, 'hierarchy of', trace.name + '.',
116+
'These roots include:', impliedRoots.join(', ')
117+
].join(' '));
115118
}
116119
} else if(parent2children[''].length > 1) {
117120
var dummyId = Lib.randstr();
@@ -140,7 +143,10 @@ exports.calc = function(gd, trace) {
140143
.id(function(d) { return d.id; })
141144
.parentId(function(d) { return d.pid; })(cd);
142145
} catch(e) {
143-
return Lib.warn('Failed to build ' + trace.type + ' hierarchy. Error: ' + e.message);
146+
return Lib.warn([
147+
'Failed to build', trace.type, 'hierarchy of', trace.name + '.',
148+
'Error:', e.message
149+
].join(' '));
144150
}
145151

146152
var hierarchy = d3Hierarchy.hierarchy(root);
@@ -170,7 +176,7 @@ exports.calc = function(gd, trace) {
170176
if(v < partialSum * ALMOST_EQUAL) {
171177
failed = true;
172178
return Lib.warn([
173-
'Total value for node', d.data.data.id,
179+
'Total value for node', d.data.data.id, 'of', trace.name,
174180
'is smaller than the sum of its children.',
175181
'\nparent value =', v,
176182
'\nchildren sum =', partialSum

test/jasmine/tests/sunburst_test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ describe('Test sunburst calc:', function() {
248248
});
249249

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

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

301301
expect(Lib.warn).toHaveBeenCalledTimes(2);
302-
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');
303-
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');
302+
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');
303+
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');
304304
});
305305

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

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

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

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

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

test/jasmine/tests/treemap_test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ describe('Test treemap calc:', function() {
363363
});
364364

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

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

416416
expect(Lib.warn).toHaveBeenCalledTimes(2);
417-
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');
418-
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');
417+
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');
418+
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');
419419
});
420420

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

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

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

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

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

0 commit comments

Comments
 (0)