Add persistent device traffic history charts
This commit is contained in:
@@ -37,13 +37,16 @@ export function positiveByteDelta(previous, current) {
|
||||
return after > before ? formatByteString((after - before).toString()) : '';
|
||||
}
|
||||
|
||||
export function trafficSampleMetrics(gatewayValue, proxyValue, maxValue) {
|
||||
export function trafficSampleMetrics(gatewayValue, proxyValue, maxValue, scale = 'linear') {
|
||||
const gateway = byteString(gatewayValue);
|
||||
const proxy = byteString(proxyValue);
|
||||
const total = gateway + proxy;
|
||||
const max = byteString(maxValue);
|
||||
const ratio = scale === 'log'
|
||||
? Math.log1p(Number(total)) / Math.log1p(Number(max))
|
||||
: Number(total * 100n / (max || 1n)) / 100;
|
||||
return {
|
||||
height: max && total ? Math.max(10, Math.min(100, Number(total * 100n / max))) : 0,
|
||||
height: max && total ? Math.max(10, Math.min(100, Math.round(ratio * 100))) : 0,
|
||||
gatewayShare: total ? Number(gateway * 100n / total) : 0,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user