fix resource units

This commit is contained in:
Henning Jacobs
2016-12-19 22:03:11 +01:00
parent 5a319233ed
commit 9d46ac1a92

View File

@@ -1,6 +1,23 @@
import Pod from './pod.js'
const PIXI = require('pixi.js')
// see https://github.com/kubernetes/kubernetes/blob/master/docs/design/resources.md
const FACTORS = {
'm': 1/1000,
'K': 1000,
'M': Math.pow(1000, 2),
'G': Math.pow(1000, 3),
'T': Math.pow(1000, 4),
'P': Math.pow(1000, 5),
'E': Math.pow(1000, 6),
'Ki': 1024,
'Mi': Math.pow(1024, 2),
'Gi': Math.pow(1024, 3),
'Ti': Math.pow(1024, 4),
'Pi': Math.pow(1024, 5),
'Ei': Math.pow(1024, 6)
}
export default class Node extends PIXI.Graphics {
constructor (node, tooltip) {
super()
@@ -13,11 +30,6 @@ export default class Node extends PIXI.Graphics {
}
parseResource(v) {
const FACTORS = {
'm': 1/1000,
'Ki': 1000,
'Mi': 1000 * 1000
}
const match = v.match(/^(\d*)(\D*)$/)
const factor = FACTORS[match[2]] || 1
return parseInt(match[1]) * factor