你在正確的軌道上,我實際上已經放在一起的東西非常相似,但是爲了完成你正在嘗試做的,你需要將數據發送到您的兩個新的數據結合,這將與你的工作完成文件和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中添加樣式塊 –