Commit c792deba authored by Vasily Belolapotkov's avatar Vasily Belolapotkov

update y labels number formatting

parent 22c0157d
......@@ -112,3 +112,25 @@ export function makeLinearAnimation(
window.requestAnimationFrame(step);
}
export function formatNumber(value: number): string {
const scales: { [key: number]: string } = {
3: 'k',
6: 'M',
9: 'B',
};
const precision = 100;
const pow10 = Math.log10(value);
const scale = Math.floor(pow10 / 3) * 3;
if (!scales[scale]) {
return `${limitPrecision(value, precision)}`;
}
const scaledValue = limitPrecision(value / Math.pow(10, scale), precision);
return `${scaledValue}${scales[scale]}`;
}
function limitPrecision(value: number, precision: number): number {
return Math.round(value * precision) / precision;
}
......@@ -2,6 +2,7 @@ import { IChartStateController } from './chart-state';
import { DOMContainerElement, IRenderable } from './chart-component';
import {
applyElementConfig,
formatNumber,
makeLinearAnimation,
makeSvgElement,
} from './ui-utils';
......@@ -174,7 +175,7 @@ export function makeYAxis(
},
});
labelSvgText.innerHTML = formatLabelText(label);
labelSvgText.innerHTML = formatNumber(label);
g.appendChild(labelSvgLine);
g.appendChild(labelSvgText);
......@@ -183,9 +184,4 @@ export function makeYAxis(
svgAxis.appendChild(g);
return g;
}
function formatLabelText(labelValue: number): string {
// TODO: format value properly
return `${labelValue}`;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment