Skip to content

Commit

Permalink
Fixed #124: Improved protection for non-numerical input.
Browse files Browse the repository at this point in the history
  • Loading branch information
kplindegaard committed Apr 8, 2017
1 parent 47bf38e commit 1d4e64a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions dist/gauge.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ class BaseGauge extends ValueUpdater

return @

parseValue: (value) ->
value = parseFloat(value) || Number(value)
return if isFinite(value) then value else 0

class TextRenderer
constructor: (@el, @fractionDigits) ->

Expand Down Expand Up @@ -330,6 +334,10 @@ class Gauge extends BaseGauge
set: (value) ->
if not (value instanceof Array)
value = [value]
# Ensure values are OK
for i in [0..(value.length-1)]
value[i] = @parseValue(value[i])

# check if we have enough GaugePointers initialized
# lazy initialization
if value.length > @gp.length
Expand All @@ -345,7 +353,6 @@ class Gauge extends BaseGauge
i = 0

for val in value
val = Number(val)
# Limit pointer within min and max?
if val > @maxValue
if @options.limitMax
Expand Down Expand Up @@ -520,7 +527,7 @@ class BaseDonut extends BaseGauge
return @

set: (value) ->
@value = value
@value = @parseValue(value)
if @value > @maxValue
@maxValue = @value * 1.1
AnimationUpdater.run()
Expand Down
23 changes: 17 additions & 6 deletions dist/gauge.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1d4e64a

Please sign in to comment.