Skip to content

Commit

Permalink
Added time scale, fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet committed Jan 8, 2016
1 parent 4a107aa commit ef15ba6
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 90 deletions.
214 changes: 125 additions & 89 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -1,95 +1,131 @@
blessed = require 'blessed'
zibar = require 'zibar'
style =
bg: 'black'
screen = blessed.screen
smartCSR: true
container = blessed.box
padding: 1
parent: screen
msg = blessed.box
height: 4
bottom: 0
padding: 0
parent: screen
colors = [ 'yellow', 'blue,bold']
d = [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
pos=d.length
series =
one:
cpu: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
io: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
two:
cpu: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
io: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
three:
cpu: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
io: [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
setInterval ->
pos++
for title,serie of series
for subTitle,sub of serie
sub.splice pos, 1, Math.ceil(Math.random() * 6)
graphers[title][subTitle] adjust sub, pos
screen.render()
, 400
graphers = {}
start = 0
adjust = (serie) ->
length = Math.max(Math.floor(graphWidth * 0.9 - 5), 0)
if serie.length < length
last = if serie.length then serie[serie.length-1] else -1
serie.push 0 for i in [last+1..last+length-serie.length]
start = Math.max(pos-length+1,0)
return serie.slice start, start + length
graphWidth=0
layout = ->
height = Math.floor(screen.height / (Object.keys(series).length))-1
top = 0
offset = 0
titleWidth = 0
for title, serie of series
titleWidth = Math.max title.length, titleWidth
for subTitle of serie
titleWidth = Math.max subTitle.length, titleWidth
graphWidth = Math.max(screen.width+1-titleWidth, 10)
for title, serie of series
lane = blessed.box
parent: container
width: '100%'
height: height
top: top
blessed.box
tags: true
parent: lane
content: "{bold}{white-fg}#{title}"
graphHeight = Math.floor(lane.height / (Object.keys(serie).length))
index = 0
graphers[title] = {}
for subTitle, sub of serie
garafa = (config) ->
screen = blessed.screen
smartCSR: true
container = blessed.box
padding: 1
parent: screen
msg = blessed.box
height: 4
bottom: 0
padding: 0
parent: screen
colors = config?.colors || [ 'yellow', 'blue,bold', 'green', 'white,bold']
d = [1, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6, 5, 1, 6, 5, 5, 1, 6]
pos=0
scroll=pos
m = ''
series =
one:
cpu: []
io: []
two:
cpu: []
io: []
three:
cpu: []
io: []
now = Math.round(Date.now()/1000)
setInterval ->
pos++
for title,serie of series
for subTitle,sub of serie
sub.splice pos, 1, Math.ceil(Math.random() * 6)
graphers[title][subTitle] adjust sub
screen.render()
, config?.delay || 1000
graphers = {}
start = 0
length=0
factor = if config?.delay then config.delay / 1000 else 1
if config?.seconds
format = (x) -> Math.ceil(x)
else
format = (x) ->
m = /(\d{2}:\d{2}:)(\d{2})/.exec new Date(x*1000).toTimeString()
m[1].grey+m[2].cyan
interval = 10
refresh = ->
for title,serie of series
for subTitle,sub of serie
graphers[title][subTitle] adjust sub
screen.render()
adjust = (serie) ->
length = Math.max(Math.floor(graphWidth * 0.9 - 5), 0)
if serie.length < length
scroll = pos
else
scroll = pos if scroll >= pos - 1
start = Math.max(scroll-length+1,0)
msg.setContent start + " " + interval
return serie.slice start, start + length
graphWidth=0
layout = ->
height = Math.floor(screen.height / (Object.keys(series).length))-1
top = 0
offset = 0
titleWidth = 0
for title, serie of series
titleWidth = Math.max title.length, titleWidth
for subTitle of serie
titleWidth = Math.max subTitle.length, titleWidth
graphWidth = Math.max(screen.width+1-titleWidth, 10)
for title, serie of series
lane = blessed.box
parent: container
width: '100%'
height: height
top: top
blessed.box
tags: true
parent: lane
top: Math.ceil((index+0.2) * graphHeight)
content: " {white-fg}#{subTitle}"
graph = blessed.box
parent: lane
top: index * graphHeight
left: titleWidth
height: graphHeight
bottom: 1
grapher = graphers[title][subTitle] = do (graph,index) -> (s) ->
#msg.setContent ""+s.length+" "+start+" "+pos+" "+(x for x in s)
graph.setContent zibar s,
color: colors[index % colors.length]
height: graph.height-3
xAxis:
origin: start
offset: -start
grapher adjust sub
index++
top += height
screen.render()
layout()
screen.on 'resize', ->
content: "{bold}{white-fg}#{title}"
graphHeight = Math.max(Math.floor(lane.height / (Object.keys(serie).length)), 4)
graphHeight = Math.min graphHeight, 8
index = 0
graphers[title] = {}
for subTitle, sub of serie
blessed.box
tags: true
parent: lane
top: Math.ceil((index+0.2) * graphHeight)
content: " {white-fg}#{subTitle}"
graph = blessed.box
parent: lane
top: index * graphHeight
left: titleWidth
height: graphHeight
bottom: 1
grapher = graphers[title][subTitle] = do (graph,index) -> (s) ->
graph.setContent zibar s,
color: colors[index % colors.length]
height: graph.height-3
xAxis:
factor: if config?.delay then config.delay / 1000 else 1
interval: interval
origin: start * factor + if not config?.seconds then now + 6*factor else 0
offset: -start - if not config?.seconds then 6 else 0
format: format
index++
top += height
screen.render()
screen.on 'resize', ->
layout()
layout()
tryScroll = (s) ->
if pos > length
scroll = s
refresh()
screen.key ['q', 'C-c'], ->
process.exit()
screen.key 'left', -> tryScroll Math.max(length-1, scroll-10)
screen.key 'right', -> tryScroll scroll+10
screen.key 'home', -> tryScroll length-1
screen.key 'end', -> tryScroll pos
module.exports = garafa

if process.argv[1].indexOf("garafa") != -1
garafa
delay: 500
seconds: true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"blessed": "~0.1.81",
"chalk": "~1.1.1",
"zibar": "^1.0.2"
"zibar": "^1.0.3"
},
"devDependencies": {},
"scripts": {
Expand Down

0 comments on commit ef15ba6

Please sign in to comment.