Skip to content

Commit b22de17

Browse files
committed
DownloadGraph: Inline downloadData property
1 parent 2bed55f commit b22de17

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

app/components/download-graph.js

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,9 @@ export default class DownloadGraph extends Component {
6666
}
6767

6868
get data() {
69-
let [labels, ...rows] = this.downloadData;
70-
71-
let datasets = labels
72-
.slice(1)
73-
.map((label, index) => ({
74-
data: rows.map(row => ({ x: row[0], y: row[index + 1] })),
75-
label: label,
76-
}))
77-
.reverse()
78-
.map(({ label, data }, index) => {
79-
return {
80-
backgroundColor: BG_COLORS[index],
81-
borderColor: COLORS[index],
82-
borderWidth: 2,
83-
cubicInterpolationMode: 'monotone',
84-
data: data,
85-
label: label,
86-
pointHoverBorderWidth: 2,
87-
pointHoverRadius: 5,
88-
};
89-
});
90-
91-
return { datasets };
92-
}
93-
94-
get downloadData() {
9569
let downloads = this.args.data;
9670
if (!downloads) {
97-
return;
71+
return { datasets: [] };
9872
}
9973

10074
let extra = downloads.content?.meta?.extra_downloads ?? [];
@@ -133,17 +107,30 @@ export default class DownloadGraph extends Component {
133107
versionsList.unshift('Other');
134108
}
135109

136-
let headers = ['Date', ...versionsList];
110+
let rows = Object.keys(dates).map(date => [
111+
dates[date].date,
112+
...versionsList.map(version => dates[date].cnt[version] || 0),
113+
]);
137114

138-
let data = [headers];
139-
for (let date in dates) {
140-
let row = [dates[date].date];
141-
for (let version of versionsList) {
142-
row.push(dates[date].cnt[version] || 0);
143-
}
144-
data.push(row);
145-
}
115+
let datasets = versionsList
116+
.map((label, index) => ({
117+
data: rows.map(row => ({ x: row[0], y: row[index + 1] })),
118+
label: label,
119+
}))
120+
.reverse()
121+
.map(({ label, data }, index) => {
122+
return {
123+
backgroundColor: BG_COLORS[index],
124+
borderColor: COLORS[index],
125+
borderWidth: 2,
126+
cubicInterpolationMode: 'monotone',
127+
data: data,
128+
label: label,
129+
pointHoverBorderWidth: 2,
130+
pointHoverRadius: 5,
131+
};
132+
});
146133

147-
return data;
134+
return { datasets };
148135
}
149136
}

0 commit comments

Comments
 (0)