Skip to content

Use a consistent format for numbers in dl graph #1645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/components/download-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ export default Component.extend({

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

let fmt = new window.google.visualization.DateFormat({
let dateFmt = new window.google.visualization.DateFormat({
pattern: 'LLL d, yyyy',
});
fmt.format(myData, 0);
dateFmt.format(myData, 0);

// Create a formatter to use for daily download numbers
let numberFormatWhole = new window.google.visualization.NumberFormat({
pattern: '#,##0',
});

// Create a formatter to use for 7-day average numbers
let numberFormatDecimal = new window.google.visualization.NumberFormat({
pattern: '#,##0.0',
});

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

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