From 0c3a7166e061e87ed656830f80092a5545b29db6 Mon Sep 17 00:00:00 2001 From: alejandro-campos Date: Fri, 3 Apr 2020 10:34:54 +0200 Subject: [PATCH] fix format function for X axis of custom graphs --- .../include/graphs/flot/pandora.flot.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index cb2a6fc4cc..3d3b48b18e 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -458,10 +458,19 @@ function pandoraFlotHBars( // v, axis; function xFormatter(v) { var label = parseFloat(v); + + const unit_prefixes = ["K", "M", "G"]; + var unit_prefix; + var i = 0; + + while (label >= 1000 && i < 3) { + label = label / 1000; + unit_prefix = unit_prefixes[i]; + i++; + } var text = label.toLocaleString(); - if (label >= 1000000) text = text.substring(0, 4) + "M"; - else if (label >= 100000) text = text.substring(0, 3) + "K"; - else if (label >= 1000) text = text.substring(0, 2) + "K"; + + text = text + unit_prefix; return ( '