Skip to content
This repository has been archived by the owner on Mar 7, 2018. It is now read-only.

Updates the Number widget to use floats or integers #292

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 8 additions & 3 deletions templates/project/widgets/number/number.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ class Dashing.Number extends Dashing.Widget

@accessor 'difference', ->
if @get('last')
last = parseInt(@get('last'))
current = parseInt(@get('current'))
last = @parseValue(@get('last'))
current = @parseValue(@get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
Expand All @@ -13,7 +13,7 @@ class Dashing.Number extends Dashing.Widget

@accessor 'arrow', ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'
if @parseValue(@get('current')) > @parseValue(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'

onData: (data) ->
if data.status
Expand All @@ -22,3 +22,8 @@ class Dashing.Number extends Dashing.Widget
c.replace /\bstatus-\S+/g, ''
# add new class
$(@get('node')).addClass "status-#{data.status}"

parseValue: (number) ->
if number == parseInt(number, 10) then parseInt(number) else parseFloat(number)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If number has non-numeric digits, this function will assume it is a float.

For example: @parseValue("15px") should return 15, but would return the float 15.0 instead.

Not sure if this is a big deal, but it would be confusing if it happened and you weren't aware of this. Seems like an edge case to me though.