From 082ef73efdc744fd8aaf5563d992ad300022cf4e Mon Sep 17 00:00:00 2001 From: Stephan Lee Date: Tue, 15 Jan 2019 09:23:26 -0800 Subject: [PATCH] Trim trailing zero when formatting numbers d3.formatter now supports trim trailing zero with "~". For instance, number 0.1 used to result in "0.100" but now is "0.1". This does not affect numbers like "0.1234" and both formatter result in "0.123". --- .../components/vz_chart_helpers/vz-chart-helpers.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tensorboard/components/vz_chart_helpers/vz-chart-helpers.ts b/tensorboard/components/vz_chart_helpers/vz-chart-helpers.ts index f90c7c7de3..000166e13d 100644 --- a/tensorboard/components/vz_chart_helpers/vz-chart-helpers.ts +++ b/tensorboard/components/vz_chart_helpers/vz-chart-helpers.ts @@ -117,11 +117,11 @@ export function multiscaleFormatter(digits: number): ((v: number) => string) { } let f: (x: number) => string; if (absv >= 1E4) { - f = d3.format('.' + digits + 'e'); + f = d3.format('.' + digits + '~e'); } else if (absv > 0 && absv < 0.01) { - f = d3.format('.' + digits + 'e'); + f = d3.format('.' + digits + '~e'); } else { - f = d3.format('.' + digits + 'g'); + f = d3.format('.' + digits + '~g'); } return f(v); }; @@ -192,8 +192,7 @@ export interface XComponents { /* tslint:enable */ } -export let stepFormatter = - Plottable.Formatters.siSuffix(STEP_FORMATTER_PRECISION); +export const stepFormatter = d3.format(`.${STEP_FORMATTER_PRECISION}~s`); export function stepX(): XComponents { let scale = new Plottable.Scales.Linear(); scale.tickGenerator(Plottable.Scales.TickGenerators.integerTickGenerator());