Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0160e16

Browse files
committed
draw blank value arc/bullet when value is NaN
... so that we don't get console warnings
1 parent 3acb333 commit 0160e16

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/traces/indicator/plot.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ function drawBulletGauge(gd, plotGroup, cd, opts) {
316316
.attr('width', Math.max(0, ax.c2p(Math.min(trace.gauge.axis.range[1], cd[0].y))));
317317
} else {
318318
fgBullet.select('rect')
319-
.attr('width', Math.max(0, ax.c2p(Math.min(trace.gauge.axis.range[1], cd[0].y))));
319+
.attr('width', typeof cd[0].y === 'number' ?
320+
Math.max(0, ax.c2p(Math.min(trace.gauge.axis.range[1], cd[0].y))) :
321+
0);
320322
}
321323
fgBullet.exit().remove();
322324

@@ -483,8 +485,9 @@ function drawAngularGauge(gd, plotGroup, cd, opts) {
483485
.attrTween('d', arcTween(valueArcPathGenerator, valueToAngle(cd[0].lastY), valueToAngle(cd[0].y)));
484486
trace._lastValue = cd[0].y;
485487
} else {
486-
valueArcPath
487-
.attr('d', valueArcPathGenerator.endAngle(valueToAngle(cd[0].y)));
488+
valueArcPath.attr('d', typeof cd[0].y === 'number' ?
489+
valueArcPathGenerator.endAngle(valueToAngle(cd[0].y)) :
490+
'M0,0Z');
488491
}
489492
valueArcPath.call(styleShape);
490493
valueArc.exit().remove();

test/jasmine/tests/indicator_test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,39 @@ describe('Indicator plot', function() {
487487
.catch(failTest)
488488
.then(done);
489489
});
490+
491+
it('should draw blank path when value is NaN', function(done) {
492+
function getArcPath() {
493+
return d3.selectAll('g.value-arc > path').attr('d');
494+
}
495+
496+
function getBulletRect() {
497+
return d3.selectAll('g.value-bullet > rect').attr('width');
498+
}
499+
500+
Plotly.plot(gd, [{
501+
type: 'indicator',
502+
mode: 'number+delta+gauge',
503+
value: null
504+
}])
505+
.then(function() {
506+
expect(getArcPath()).toBe('M0,0Z', 'blank path with value:null');
507+
})
508+
.then(function() { return Plotly.restyle(gd, 'value', 10); })
509+
.then(function() {
510+
expect(getArcPath()).not.toBe('M0,0Z', 'non blank path with value:10');
511+
})
512+
.then(function() { return Plotly.restyle(gd, 'gauge.shape', 'bullet'); })
513+
.then(function() {
514+
expect(getBulletRect()).toBe('270', 'bullet of value:10');
515+
})
516+
.then(function() { return Plotly.restyle(gd, 'value', null); })
517+
.then(function() {
518+
expect(getBulletRect()).toBe('0', 'width-less bullet of value:null');
519+
})
520+
.catch(failTest)
521+
.then(done);
522+
});
490523
});
491524

492525
describe('Indicator animations', function() {

0 commit comments

Comments
 (0)