Skip to content

Commit 5c75b14

Browse files
committed
Auto merge of #1645 - bryanburgers:download-graph-numbering, r=sgrif
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. Fixes #1628 Note that I couldn't fully test this, because even after changing my browser's language to `de`, I would still see English number formatting. I did test it by [forcing the Google Visualization chart locale](https://developers.google.com/chart/interactive/docs/basic_load_libs#loadwithlocale), but I'm still not 100% sure if the numbers will show in a German format for a German viewer. I am, however, sure that they will always show in a *consistent* format.
2 parents 4bed129 + b2c36a0 commit 5c75b14

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

app/components/download-graph.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,20 @@ 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+
// Create a formatter to use for daily download numbers
87+
let numberFormatWhole = new window.google.visualization.NumberFormat({
88+
pattern: '#,##0',
89+
});
90+
91+
// Create a formatter to use for 7-day average numbers
92+
let numberFormatDecimal = new window.google.visualization.NumberFormat({
93+
pattern: '#,##0.0',
94+
});
8595

8696
// use a DataView to calculate an x-day moving average
8797
let days = 7;
@@ -101,7 +111,7 @@ export default Component.extend({
101111
let avg = total / days;
102112
return {
103113
v: avg,
104-
f: avg.toFixed(2),
114+
f: numberFormatDecimal.formatValue(avg),
105115
};
106116
};
107117
};
@@ -113,6 +123,8 @@ export default Component.extend({
113123
// is at the end, but in the UI we want it at the top of the chart legend.
114124

115125
range(headers.length - 1, 0, -1).forEach((dataCol, i) => {
126+
// Set the number format for the colum in the data table.
127+
numberFormatWhole.format(myData, dataCol);
116128
columns.push(dataCol); // add the column itself
117129
columns.push({
118130
// add a 'calculated' column, the moving average

0 commit comments

Comments
 (0)