Skip to content

Commit

Permalink
Trim trailing zero when formatting numbers
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
stephanwlee committed Jan 17, 2019
1 parent fad69e5 commit 082ef73
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions tensorboard/components/vz_chart_helpers/vz-chart-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 082ef73

Please sign in to comment.