Skip to content

Commit 48618a8

Browse files
committed
Use a consistent format for numbers in dl graph
When formatting download numbers in the download graph, use a consistent numbering format for both raw numbers and the rolling 7-day average. There are cases where the user's local can make inconsistent formatting. Specifically, we use `Number.prototype.toFixed` to format the rolling 7-day average, which always results in a number format that uses a decimal point (e.g. "1234.56"). However, the raw download numbers end up using the locale, which in some places can end up formatting the number with a decimal as the thousands separator ("1.234"). To fix this, use google.visualization.NumberFormat for *both* values, so that they are always consistent.
1 parent 09f8888 commit 48618a8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

app/components/download-graph.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,23 @@ export default Component.extend({
7878

7979
let myData = window.google.visualization.arrayToDataTable(data);
8080

81-
let fmt = new window.google.visualization.DateFormat({
81+
let dateFmt = new window.google.visualization.DateFormat({
8282
pattern: 'LLL d, yyyy',
8383
});
84-
fmt.format(myData, 0);
84+
dateFmt.format(myData, 0);
85+
86+
// Format download numbers
87+
let numberFormatWhole = new window.google.visualization.NumberFormat({
88+
pattern: '#,##0',
89+
});
90+
range(headers.length - 1, 0, -1).forEach((dataCol, i) => {
91+
numberFormatWhole.format(myData, dataCol);
92+
})
93+
94+
// Create a formatter to use for 7-day average numbers
95+
let numberFormatDecimal = new window.google.visualization.NumberFormat({
96+
pattern: '#,##0.0',
97+
});
8598

8699
// use a DataView to calculate an x-day moving average
87100
let days = 7;
@@ -101,7 +114,7 @@ export default Component.extend({
101114
let avg = total / days;
102115
return {
103116
v: avg,
104-
f: avg.toFixed(2),
117+
f: numberFormatDecimal.formatValue(avg),
105118
};
106119
};
107120
};

0 commit comments

Comments
 (0)