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

Conversation

pallan
Copy link

@pallan pallan commented Dec 12, 2013

The currently implemented number widget only supports integers when calculating the difference. We were using it with NewRelic's response time metric which is returned in milliseconds but we wanted to show in seconds (200ms vs 0.200s). However, since the JS used parseInt it changed the floats to zero (0) and never showed a valid difference. There were a couple of pull requests already that just changed parseInt to parseFloat. This PR updated the JS to detect if the supplied values are floats or integers and then use the appropriate parser for the value, thereby, supporting both types.

@austinheap
Copy link

Exactly what I was looking for, thanks @pallan!

This was referenced Aug 26, 2014
@@ -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.

@terraboops
Copy link
Contributor

Seems like a sensible change, except for the edge case I bring up in the note above.

@pallan pallan closed this Apr 18, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants