Skip to content

Commit 6a16b6a

Browse files
refactor: use highcharts instead of chart.js
1 parent fdbdb93 commit 6a16b6a

4 files changed

Lines changed: 61 additions & 94 deletions

File tree

frontend/package-lock.json

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
"@primeuix/themes": "^1.2.3",
2121
"@primevue/forms": "^4.3.9",
2222
"axios": "^1.12.2",
23-
"chart.js": "^4.5.0",
24-
"chartjs-adapter-date-fns": "^3.0.0",
2523
"date-fns": "^4.1.0",
24+
"highcharts": "^12.5.0",
25+
"highcharts-vue": "^2.0.1",
2626
"primeicons": "^7.0.0",
2727
"primevue": "^4.3.9",
2828
"vue": "^3.5.18",

frontend/src/components/user-stats/IndexerStatsEvolutions.vue

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,40 @@
33
<div class="wrapper-center title">Evolution on the selected period</div>
44
<div class="charts">
55
<ContentContainer v-for="value in selectedValues" :key="value">
6-
<Chart type="line" :data="chartData(value)" :options="chartOptions(value)" />
6+
<highcharts :options="chartOptions(value)" />
77
</ContentContainer>
88
</div>
99
</div>
1010
</template>
1111
<script lang="ts" setup>
12+
import type { Options } from 'highcharts'
1213
import type { UserProfileVec, UserProfileScrapedVec } from '@/services/api/userStatsService'
13-
import Chart from 'primevue/chart'
1414
import ContentContainer from '../ContentContainer.vue'
15-
import 'chartjs-adapter-date-fns'
15+
16+
const GIB_KEYS: (keyof UserProfileScrapedVec)[] = ['uploaded', 'downloaded', 'seed_size', 'uploaded_real', 'downloaded_real']
1617
1718
const props = defineProps<{
1819
userStats: UserProfileVec
1920
selectedValues: (keyof UserProfileScrapedVec)[]
2021
}>()
21-
const documentStyle = getComputedStyle(document.documentElement)
2222
23-
const chartOptions = (value: keyof UserProfileScrapedVec) => {
24-
let unit = ''
25-
switch (value) {
26-
case 'uploaded':
27-
case 'downloaded':
28-
case 'seed_size':
29-
case 'uploaded_real':
30-
case 'downloaded_real':
31-
unit = 'GiB'
32-
break
33-
}
34-
return {
35-
scales: {
36-
x: {
37-
type: 'time',
38-
time: {
39-
unit: 'day',
40-
},
41-
},
42-
y: {
43-
title: {
44-
display: true,
45-
text: unit,
46-
},
47-
},
48-
},
49-
}
50-
}
23+
const seriesColor = getComputedStyle(document.documentElement).getPropertyValue('--p-button-primary-border-color')
24+
25+
function chartOptions(value: keyof UserProfileScrapedVec): Options {
26+
const isGib = GIB_KEYS.includes(value)
27+
const raw = props.userStats.profile[value] as (number | null)[]
28+
const timestamps = props.userStats.scraped_at.map((d) => new Date(d).getTime())
29+
30+
const data: [number, number][] = timestamps.map((t, i) => [t, isGib ? (raw[i] ?? 0) / 1024 / 1024 / 1024 : (raw[i] as number)])
5131
52-
const chartData = (value: keyof UserProfileScrapedVec) => {
53-
let data: number[] = []
54-
switch (value) {
55-
case 'uploaded':
56-
case 'downloaded':
57-
case 'seed_size':
58-
case 'uploaded_real':
59-
case 'downloaded_real':
60-
data = props.userStats.profile[value].map((val) => (val ?? 0) / 1024 / 1024 / 1024)
61-
break
62-
default:
63-
data = props.userStats.profile[value] as number[]
64-
}
6532
return {
66-
labels: props.userStats.scraped_at.map((date) => new Date(date).toISOString()),
67-
datasets: [
68-
{
69-
// tension: 0.2,
70-
borderColor: documentStyle.getPropertyValue('--p-button-primary-border-color'),
71-
label: value,
72-
data: data,
73-
},
74-
],
33+
chart: { type: 'line', backgroundColor: 'transparent', height: 300 },
34+
title: { text: value },
35+
xAxis: { type: 'datetime' },
36+
yAxis: { title: { text: isGib ? 'GiB' : undefined } },
37+
legend: { enabled: false },
38+
credits: { enabled: false },
39+
series: [{ type: 'line', name: value, data, color: seriesColor }],
7540
}
7641
}
7742
</script>
@@ -80,13 +45,6 @@ const chartData = (value: keyof UserProfileScrapedVec) => {
8045
display: flex;
8146
justify-content: center;
8247
flex-wrap: wrap;
83-
> * {
84-
margin: 0 5px;
85-
margin-bottom: 10px;
86-
}
87-
.p-chart {
88-
width: 36em;
89-
height: auto;
90-
}
48+
gap: 10px;
9149
}
9250
</style>

frontend/src/main.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ import PrimeVue from 'primevue/config'
77
import Aura from '@primeuix/themes/aura'
88
import ToastService from 'primevue/toastservice'
99
import Tooltip from 'primevue/tooltip'
10+
import Highcharts from 'highcharts'
11+
import HighchartsVue from 'highcharts-vue'
12+
13+
Highcharts.setOptions({
14+
lang: {
15+
locale: 'en',
16+
},
17+
})
1018

1119
const app = createApp(App)
1220

21+
app.use(HighchartsVue)
1322
app.use(PrimeVue, {
1423
theme: {
1524
preset: Aura,

0 commit comments

Comments
 (0)