2022-06-18 10:56:34 +01:00
|
|
|
import * as Vue from "vue";
|
|
|
|
import { Chart, PointElement, LineElement, LineController, CategoryScale, LinearScale, TimeSeriesScale } from "chart.js";
|
2022-06-23 19:26:36 +01:00
|
|
|
import 'chartjs-adapter-luxon';
|
2022-06-18 10:56:34 +01:00
|
|
|
import { CountSample } from "scripts/HubInterfaces";
|
2022-06-23 19:26:36 +01:00
|
|
|
import { ScrobbleDataSeries } from "scripts/now";
|
2022-06-18 10:56:34 +01:00
|
|
|
|
|
|
|
Chart.register(LineController, CategoryScale, LinearScale, TimeSeriesScale, PointElement, LineElement);
|
|
|
|
|
|
|
|
const months = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"];
|
|
|
|
|
|
|
|
export let PlayCountChartCard: Vue.Component = {
|
2022-06-23 19:26:36 +01:00
|
|
|
props: ['data_points', 'title', 'chart_id', 'link', 'earliest_date', 'latest_date', 'colour'],
|
2022-06-18 10:56:34 +01:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chartData: {
|
|
|
|
datasets: [{
|
2022-06-23 19:26:36 +01:00
|
|
|
data: this.data_points.map((e: CountSample) => {
|
|
|
|
return {x: e.timeStamp, y: e.value};
|
|
|
|
}),
|
2022-06-18 10:56:34 +01:00
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
chartId() {
|
|
|
|
return "play-count-chart-" + this.chart_id;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template:
|
|
|
|
`
|
|
|
|
<div class="card info-card chart-card">
|
|
|
|
<h1>{{ title }}</h1>
|
|
|
|
<canvas :id="chartId"></canvas>
|
2022-06-22 21:51:38 +01:00
|
|
|
<lastfm-logo :link="link" />
|
2022-06-18 10:56:34 +01:00
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
mounted() {
|
|
|
|
new Chart(`play-count-chart-${this.chart_id}`, {
|
|
|
|
type: "line",
|
|
|
|
data: this.chartData,
|
|
|
|
options: {
|
|
|
|
elements: {
|
|
|
|
line: {
|
2022-06-23 19:26:36 +01:00
|
|
|
borderWidth: 5,
|
|
|
|
borderColor: this.colour,
|
|
|
|
borderCapStyle: "round",
|
|
|
|
borderJoinStyle: "round"
|
|
|
|
},
|
|
|
|
point: {
|
|
|
|
radius: 0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
scales: {
|
|
|
|
yAxis: {
|
|
|
|
suggestedMin: 0
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: 'time',
|
|
|
|
min: this.earliest_date,
|
|
|
|
max: this.latest_date
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export let CombinedPlayCountChartCard: Vue.Component = {
|
|
|
|
props: ['data_points', 'title', 'chart_id', 'link', 'earliest_date'],
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chartData: {
|
|
|
|
datasets: this.data_points.map((series: ScrobbleDataSeries) => {
|
|
|
|
return {
|
|
|
|
label: series.label,
|
|
|
|
borderColor: series.colour,
|
|
|
|
data: series.data.map((e: CountSample) => {
|
|
|
|
return {x: e.timeStamp, y: e.value};
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
chartId() {
|
|
|
|
return "play-count-chart-" + this.chart_id;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template:
|
|
|
|
`
|
|
|
|
<div class="card info-card chart-card">
|
|
|
|
<canvas :id="chartId"></canvas>
|
|
|
|
<lastfm-logo :link="link" />
|
|
|
|
</div>
|
|
|
|
`,
|
|
|
|
mounted() {
|
|
|
|
new Chart(`play-count-chart-${this.chart_id}`, {
|
|
|
|
type: "line",
|
|
|
|
data: this.chartData,
|
|
|
|
options: {
|
|
|
|
elements: {
|
|
|
|
line: {
|
|
|
|
borderWidth: 5,
|
2022-06-18 10:56:34 +01:00
|
|
|
borderColor: "#a34c77",
|
|
|
|
borderCapStyle: "round",
|
|
|
|
borderJoinStyle: "round"
|
|
|
|
},
|
2022-06-23 19:26:36 +01:00
|
|
|
point: {
|
|
|
|
radius: 0
|
|
|
|
}
|
2022-06-18 10:56:34 +01:00
|
|
|
},
|
|
|
|
scales: {
|
2022-06-22 21:51:38 +01:00
|
|
|
yAxis: {
|
|
|
|
suggestedMin: 0
|
2022-06-23 19:26:36 +01:00
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type: 'time',
|
|
|
|
min: this.earliest_date
|
2022-06-22 21:51:38 +01:00
|
|
|
}
|
2022-06-18 10:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-06-23 19:26:36 +01:00
|
|
|
}
|