你在正确的轨道上,我实际上已经放在一起的东西非常相似,但是为了完成你正在尝试做的,你需要将数据发送到您的两个新的数据结合,这将与你的工作完成文件和graph.coffee文件。
我不确定从redis到你的作业erb文件的图表数据到底有多精确,但是你会想要设置一些新变量,例如我使用nowNumber
和lastNumber
。这些将是执行估值的数字。
工作/ 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.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'
所以,如果我想要实现的状态,这是否需要graph.html中的任何更改?我的发送事件会是这样吗? 'send_event('graph',points:points,current:nowNumber,last:lastNumber,status:myStatus)'? –
没有变化graph.html,和你的send_event看起来不错,只是确保myStatus =“危险”,“警告”或“OK”。你可能也想添加一些CSS来调整你的组合元素。您可以在仪表板erb或graph.scss中添加样式块 –