colorize bars according to usage

This commit is contained in:
Henning Jacobs
2016-12-19 21:34:38 +01:00
parent 9887ed46a7
commit c93d64c4d3

View File

@@ -23,6 +23,30 @@ export default class Node extends PIXI.Graphics {
return parseInt(match[1]) * factor
}
hsvToRgb(h, s, v) {
var r, g, b, i, f, p, q, t;
i = Math.floor(h * 6);
f = h * 6 - i;
p = v * (1 - s);
q = v * (1 - f * s);
t = v * (1 - (1 - f) * s);
switch (i % 6) {
case 0:
r = v, g = t, b = p; break;
case 1:
r = q, g = v, b = p; break;
case 2:
r = p, g = v, b = t; break;
case 3:
r = p, g = q, b = v; break;
case 4:
r = t, g = p, b = v; break;
case 5:
r = v, g = p, b = q; break;
}
return PIXI.utils.rgb2hex([r, g, b])
}
getResourceUsage() {
const resources = {}
for (var key of Object.keys(this.node.status.capacity)) {
@@ -88,22 +112,24 @@ export default class Node extends PIXI.Graphics {
})
const resources = this.getResourceUsage()
const cpuHeight = 80 / resources.cpu.capacity
nodeBox.lineStyle(2, 0xaaffaa, 1)
nodeBox.beginFill(0xaaffaa, 1)
nodeBox.drawRect(3, 110 - resources.cpu.requested * cpuHeight, 3, resources.cpu.requested * cpuHeight)
nodeBox.drawRect(5, 110 - resources.cpu.used * cpuHeight, 5, resources.cpu.used * cpuHeight)
nodeBox.lineStyle(0, 0xaaffaa, 1)
nodeBox.beginFill(this.hsvToRgb(0.4 - (0.4 * (resources.cpu.requested / resources.cpu.capacity)), 0.6, 1), 1)
nodeBox.drawRect(5, 110 - resources.cpu.requested * cpuHeight, 2.5, resources.cpu.requested * cpuHeight)
nodeBox.beginFill(this.hsvToRgb(0.4 - (0.4 * (resources.cpu.used / resources.cpu.capacity)), 0.6, 1), 1)
nodeBox.drawRect(7.5, 110 - resources.cpu.used * cpuHeight, 2.5, resources.cpu.used * cpuHeight)
nodeBox.endFill()
nodeBox.lineStyle(2, 0xaaaaaa, 1);
nodeBox.lineStyle(1, 0xaaaaaa, 1);
for (var i=0; i<resources.cpu.capacity; i++) {
nodeBox.drawRect(5, 110 - (i+1) * cpuHeight, 5, cpuHeight)
}
const scale = resources.memory.capacity / 80
nodeBox.drawRect(14, 110 - resources.memory.capacity/scale, 5, resources.memory.capacity/scale)
nodeBox.lineStyle(2, 0xaaffaa, 1)
nodeBox.beginFill(0xaaffaa, 1)
nodeBox.drawRect(13, 110 - resources.memory.requested/scale, 3, resources.memory.requested/scale)
nodeBox.drawRect(15, 110 - resources.memory.used/scale, 3, resources.memory.used/scale)
nodeBox.lineStyle(0, 0xaaffaa, 1)
nodeBox.beginFill(this.hsvToRgb(0.4 - (0.4 * (resources.memory.requested / resources.memory.capacity)), 0.6, 1), 1)
nodeBox.drawRect(14, 110 - resources.memory.requested/scale, 2.5, resources.memory.requested/scale)
nodeBox.beginFill(this.hsvToRgb(0.4 - (0.4 * (resources.memory.used / resources.memory.capacity)), 0.6, 1), 1)
nodeBox.drawRect(16.5, 110 - resources.memory.used/scale, 2.5, resources.memory.used/scale)
nodeBox.endFill()
var text = new PIXI.Text('', {fontSize: 10, fill: 0xffffff})
nodeBox.addChild(text)