daisho
Version:
Modular dashboard framework
65 lines (57 loc) • 1.66 kB
text/coffeescript
import Tween from 'es-tween'
import Dynamic from '../dynamic'
import html from '../../templates/graphics/counter'
# --Counter--
# A counter supports a model with 2 series. It will display the first
# datapoint in each series and display a comparison in the two series case or
# just a single number
class Counter extends Dynamic
tag: 'daisho-graphics-counter'
html: html
value0: 0
value1: 0
tween0: null
tween1: null
timer: 1000
init: -> super()
_refresh: ->
data =
self = @
if ! && data.get '0'
value0 = data.get(0 + '.ys.0')
if value0? && value0 !=
= new Tween.Tween
v:
.to { v: value0 },
.onUpdate ->
self.value0 =
#needs to be update since its already in a RAF
self.update()
.onComplete =>
= null
= value0
.start()
if ! && data.get '1'
value1 = data.get(1 + '.ys.0')
if value1? && value1 !=
= new Tween.Tween
v:
.to { v: value1 },
.onUpdate ->
self.value1 =
#needs to be update since its already in a RAF
self.update()
.onComplete =>
= null
= value1
.start()
getNumber: (index) ->
if index == 0
return if !.get(0 + '.fmt.y')
.get(0 + '.fmt.y')
else
return if !.get(1 + '.fmt.y')
.get(1 + '.fmt.y')
export default Counter