Skip to content

Commit

Permalink
fix(event-chart): Round time labels in x-axis
Browse files Browse the repository at this point in the history
  • Loading branch information
subarroca committed Feb 18, 2020
1 parent 46ab183 commit 25baa03
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions components/event-chart/src/event-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,20 @@ function formatRelativeTimestamp(timestamp: number): string {
const min = sec * 60;
const hour = min * 60;
const day = hour * 24;
const decimals = 2;
if (timestamp >= day) {
return `${timestamp / day}d`;
return `${roundUp(timestamp / day, decimals)} d`;
} else if (timestamp >= hour) {
return `${timestamp / hour}h`;
return `${roundUp(timestamp / hour, decimals)} h`;
} else if (timestamp >= min) {
return `${timestamp / min}min`;
return `${roundUp(timestamp / min, decimals)} min`;
} else if (timestamp >= sec) {
return `${timestamp / sec}s`;
return `${roundUp(timestamp / sec, decimals)} s`;
}
return `${timestamp}ms`;
// tslint:enable: no-magic-numbers
}

function roundUp(num: number, decimals: number): number {
return Math.round(10 ** decimals * num) / 10 ** decimals;
}

0 comments on commit 25baa03

Please sign in to comment.