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'
1213import type { UserProfileVec , UserProfileScrapedVec } from ' @/services/api/userStatsService'
13- import Chart from ' primevue/chart'
1414import 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
1718const 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 >
0 commit comments