diff --git a/public/models/LegendModel.js b/public/models/LegendModel.js
index 69c1846..d43193d 100644
--- a/public/models/LegendModel.js
+++ b/public/models/LegendModel.js
@@ -22,7 +22,10 @@ class LegendModel extends Backbone.Model {
this.set({ artistColors: {} });
}
get_artist_color(artist) {
- return this.get('artistColors').get(artist.toLowerCase());
+ return this.artist_colors()[artist.toLowerCase()];
+ }
+ artist_colors() {
+ return this.get('artistColors');
}
compute_artist_colors(scrobbles) {
let a = _.chain(scrobbles.models)
@@ -31,16 +34,16 @@ class LegendModel extends Backbone.Model {
.sortBy('length')
.reverse()
.value();
- let artistColors = new Map();
+ let artistColors = {};
const otherColor = LEGEND_COLORS[0];
for (let i = 0; i < a.length; i++) {
- let x = a[i];
- artistColors.set(x[0].artist().toLowerCase(), {
- artist: x[0].artist(),
+ let scrobbles = a[i];
+ artistColors[scrobbles[0].artist().toLowerCase()] = {
+ artist: scrobbles[0].artist(),
color: LEGEND_COLORS[i + 1] || otherColor,
- count: x.length,
+ count: scrobbles.length,
showInLegend: !!LEGEND_COLORS[i + 1],
- });
+ };
}
this.set({ artistColors, otherColor });
}
diff --git a/public/views/LegendView.js b/public/views/LegendView.js
index f42e385..072fa87 100644
--- a/public/views/LegendView.js
+++ b/public/views/LegendView.js
@@ -1,8 +1,9 @@
class LegendView extends Backbone.View {
render() {
this.$("li").remove();
- let artistColors = legendModel.get("artistColors");
- for (const color of artistColors.values()) {
+ let artistColors = legendModel.artist_colors();
+ for (const k in artistColors) {
+ const color = artistColors[k];
if (color.showInLegend) {
$("
")
.text(`${color.artist} (${color.count})`)
diff --git a/src/models/LegendModel.ts b/src/models/LegendModel.ts
index 9690b0a..e478321 100644
--- a/src/models/LegendModel.ts
+++ b/src/models/LegendModel.ts
@@ -27,8 +27,13 @@ class LegendModel extends Backbone.Model {
initialize() {
this.set({ artistColors: {} });
}
+
get_artist_color(artist: string): ArtistColor {
- return this.get('artistColors').get(artist.toLowerCase());
+ return this.artist_colors()[artist.toLowerCase()];
+ }
+
+ artist_colors(): { [key: string]: ArtistColor; } {
+ return this.get('artistColors');
}
compute_artist_colors(scrobbles: ScrobbleCollection) {
let a = _.chain(scrobbles.models)
@@ -38,16 +43,16 @@ class LegendModel extends Backbone.Model {
.reverse()
.value();
- let artistColors: Map = new Map();
+ let artistColors: { [key: string]: ArtistColor; } = {};
const otherColor = LEGEND_COLORS[0];
for (let i = 0; i < a.length; i++) {
- let x = a[i];
- artistColors.set(x[0].artist().toLowerCase(), {
- artist: x[0].artist(),
+ let scrobbles = a[i];
+ artistColors[scrobbles[0].artist().toLowerCase()] = {
+ artist: scrobbles[0].artist(),
color: LEGEND_COLORS[i + 1] || otherColor,
- count: x.length,
+ count: scrobbles.length,
showInLegend: !!LEGEND_COLORS[i + 1],
- });
+ };
}
this.set({ artistColors, otherColor });
diff --git a/src/views/LegendView.ts b/src/views/LegendView.ts
index 06d04d4..87a85c0 100644
--- a/src/views/LegendView.ts
+++ b/src/views/LegendView.ts
@@ -1,8 +1,9 @@
class LegendView extends Backbone.View {
render() {
this.$("li").remove();
- let artistColors = legendModel.get("artistColors");
- for (const color of artistColors.values()) {
+ let artistColors = legendModel.artist_colors();
+ for (const k in artistColors) {
+ const color = artistColors[k];
if (color.showInLegend) {
$("")
.text(`${color.artist} (${color.count})`)