Skip to content

Commit

Permalink
Created
Browse files Browse the repository at this point in the history
  • Loading branch information
lbovet committed Jan 5, 2016
0 parents commit 0e511fa
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
77 changes: 77 additions & 0 deletions index.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
blessed = require 'blessed'
babar = require 'babar'
style =
bg: 'black'
screen = blessed.screen
smartCSR: true
container = blessed.box
padding: 1
parent: screen
colors = [ 'green', 'cyan']
series =
one:
cpu: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
io: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
two:
cpu: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
io: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
three:
cpu: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
io: [[0, 1], [1, 5], [2, 5], [3, 1], [4, 6]]
graphers = {}
adjust = (serie, length) ->
if serie.length > length
serie.splice 0, serie.length-length
if serie.length < length
serie.unshift [0,0] for i in [0..length-serie.length]
return serie
layout = ->
height = Math.floor(screen.height / (Object.keys(series).length))
top = 0
titleWidth = 0
for title, serie of series
titleWidth = Math.max title.length, titleWidth
for subTitle of serie
titleWidth = Math.max subTitle.length, titleWidth
titleWidth += 2
graphWidth = screen.width+1-titleWidth
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))-1
index = 0
graphers[title] = {}
for subTitle, sub of serie
blessed.box
tags: true
parent: lane
top: Math.ceil((index+0.5) * graphHeight)
content: " {white-fg}#{subTitle}"
graph = blessed.box
parent: lane
top: index * graphHeight + 1
left: titleWidth
height: graphHeight
bottom: 1
grapher = graphers[title][subTitle] = (serie) ->
graph.setContent ""+serie
graph.setContent babar(serie, {
color: colors[index % colors.length],
width: graphWidth
height: graph.height
yFractions: 1
})
grapher adjust sub, graphWidth-3
index++
top += height
screen.render()
layout()
screen.on 'resize', ->
layout()
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "garafa",
"version": "0.0.0",
"description": "",
"main": "index.coffee",
"dependencies": {
"chalk": "~1.1.1",
"blessed": "~0.1.81"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}

0 comments on commit 0e511fa

Please sign in to comment.