Skip to content

Commit

Permalink
Prevent error in console if NaN in path to draw
Browse files Browse the repository at this point in the history
Original idea from morrisjs#705
  • Loading branch information
Pierre Clavequin committed Jan 31, 2018
1 parent 2f21d11 commit 909f9a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
21 changes: 12 additions & 9 deletions lib/morris.donut.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,18 @@ class Morris.DonutSegment extends Morris.EventEmitter
"A#{r},#{r},0,#{@is_long},0,#{ix1},#{iy1}")

render: ->
@arc = @drawDonutArc(@hilight, @color)
@seg = @drawDonutSegment(
@path,
@color,
@backgroundColor,
=> @fire('hover', @index),
=> @fire('click', @index),
=> @fire('mouseout', @index)
)
if !/NaN/.test @hilight
@arc = @drawDonutArc(@hilight, @color)

if !/NaN/.test @path
@seg = @drawDonutSegment(
@path,
@color,
@backgroundColor,
=> @fire('hover', @index),
=> @fire('click', @index),
=> @fire('mouseout', @index)
)

drawDonutArc: (path, color) ->
if @options.animate
Expand Down
20 changes: 12 additions & 8 deletions morris.js
Original file line number Diff line number Diff line change
Expand Up @@ -2822,14 +2822,18 @@ Licensed under the BSD-2-Clause License.

DonutSegment.prototype.render = function() {
var _this = this;
this.arc = this.drawDonutArc(this.hilight, this.color);
return this.seg = this.drawDonutSegment(this.path, this.color, this.backgroundColor, function() {
return _this.fire('hover', _this.index);
}, function() {
return _this.fire('click', _this.index);
}, function() {
return _this.fire('mouseout', _this.index);
});
if (!/NaN/.test(this.hilight)) {
this.arc = this.drawDonutArc(this.hilight, this.color);
}
if (!/NaN/.test(this.path)) {
return this.seg = this.drawDonutSegment(this.path, this.color, this.backgroundColor, function() {
return _this.fire('hover', _this.index);
}, function() {
return _this.fire('click', _this.index);
}, function() {
return _this.fire('mouseout', _this.index);
});
}
};

DonutSegment.prototype.drawDonutArc = function(path, color) {
Expand Down
Loading

0 comments on commit 909f9a4

Please sign in to comment.