你在正确的轨道上,我实际上已经把一些非常相似的东西放在一起,但为了完成你想要做的事情,你需要将数据发送到你的两个新数据绑定,这将通过你的工作文件完成和 graph.coffee 文件。
我不确定您如何准确地将图形数据从 redis 获取到您的作业 erb 文件,但您需要设置几个新变量,例如我使用了 nowNumber 和 lastNumber。这些将是进行估值的数字。
jobs/jobname.erb
send_event('graph', points: points, current: nowNumber, last: lastNumber )
如果你把它打印出来,你会得到这样的东西:
{:points=>[{:x=>6, :y=>64}, {:x=>5, :y=>62}, {:x=>4, :y=>56}], :current=>57, :last=>64}
调整您的 graph/graph.coffee 文件:
# The following 6 lines aren't needed for your solution, but if you wanted to take advantage of 'warning', 'danger', and 'ok' status classes (changes background color and flashes), just feed your send_event with 'status: [one of the three status names]
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}"
@accessor 'difference', ->
if @get('last')
last = parseInt(@get('last'))
current = parseInt(@get('current'))
if last != 0
diff = Math.abs(Math.round((current - last) / last * 100))
"#{diff}%"
else
""
# Picks the direction of the arrow based on whether the current value is higher or lower than the last
@accessor 'arrow', ->
if @get('last')
if parseInt(@get('current')) > parseInt(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'