This repository was archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotfloat.coffee
More file actions
54 lines (46 loc) · 1.45 KB
/
hotfloat.coffee
File metadata and controls
54 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class Dashing.Hotfloat extends Dashing.Widget
@accessor 'current', Dashing.AnimatedValue
@accessor 'difference', ->
if @get('last')
last = parseFloat(@get('last'))
current = parseFloat(@get('current'))
if last != 0
diff = Math.round(((current - last)) * 100) / 100
"#{diff}"
else
""
@accessor 'arrow', ->
if @get('last')
if parseFloat(@get('current')) > parseFloat(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'
mixin: (data) ->
if data?
@updateColor(data)
super data
onData: (data) ->
if data.status
# clear existing "status-*" classes
$(@get('node')).attr 'class', (i,c) ->
c.replace /\bstatus-\S+/g, ''
# add new class
$(@get('node')).addClass "status-#{data.status}"
@updateColor(data)
updateColor: (data) ->
if data.current?
node = $(@node)
currentVal = parseFloat data.current
cool = parseFloat node.data "cool"
warm = parseFloat node.data "warm"
if warm >= cool
level = switch
when currentVal <= cool then 0
when currentVal >= warm then 4
else 1
else
level = switch
when currentVal >= cool then 0
when currentVal <= warm then 2
else 1
backgroundClass = "hotfloat#{level}"
lastClass = @get "lastClass"
node.toggleClass "#{lastClass} #{backgroundClass}"
@set "lastClass", backgroundClass