Skip to content

Commit b0e9885

Browse files
committed
Polish charts UI
1 parent da93c0c commit b0e9885

File tree

3 files changed

+77
-52
lines changed

3 files changed

+77
-52
lines changed

src/routes/stats/+page.svelte

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,61 @@
2020
/**
2121
* @type {number[]}
2222
*/
23-
let dateData = [];
23+
let dateData = [];
2424
2525
/**
2626
* @type {number[]}
2727
*/
28-
let hourData = [];
28+
let hourData = [];
2929
30-
/**
31-
* @type {number[]}
32-
*/
33-
let yearList = [];
30+
/**
31+
* @type {number[]}
32+
*/
33+
let yearList = [];
3434
35-
let currentYear = moment().year();
35+
let currentYear = moment().year();
3636
37-
/**
38-
* @type {{name:string; value: number}[]}
39-
*/
40-
let topCratesData = [];
37+
/**
38+
* @type {{name:string; value: number}[]}
39+
*/
40+
let topCratesData = [];
4141
42-
let searchTime = "the last year";
42+
let searchTime = "the last year";
4343
4444
/**
45-
*
45+
*
4646
* @param {number} now
4747
* @param {number} yearAgo
4848
*/
4949
async function getEchartData(now, yearAgo) {
50-
const { weeksArr, dateArr, hourArr, topCratesArr } = await getHistogramEchartDatas(now, yearAgo);
50+
const { weeksArr, dateArr, hourArr, topCratesArr } =
51+
await getHistogramEchartDatas(now, yearAgo);
5152
weekData = weeksArr;
5253
dateData = dateArr;
5354
hourData = hourArr;
5455
topCratesData = topCratesArr;
5556
await renderCharts(now, yearAgo);
5657
}
5758
58-
/**
59-
*
60-
* @param {number} y
61-
*/
62-
function handleChangeYear(y){
59+
/**
60+
*
61+
* @param {number} y
62+
*/
63+
function handleChangeYear(y) {
6364
currentYear = y;
6465
searchTime = String(y);
6566
const year = moment(searchTime);
66-
const now = year.endOf('year').valueOf();
67-
const yearAgo = year.startOf('year').valueOf();
67+
const now = year.endOf("year").valueOf();
68+
const yearAgo = year.startOf("year").valueOf();
6869
getEchartData(now, yearAgo);
69-
};
70+
}
7071
7172
onMount(async () => {
7273
const now = moment().valueOf();
7374
const yearAgo = moment().startOf("day").subtract(1, "year").valueOf();
7475
yearList = await getYearList(currentYear);
7576
getEchartData(now, yearAgo);
76-
})
77+
});
7778
</script>
7879

7980
<link rel="stylesheet" href="/css/charts.css" />
@@ -126,6 +127,11 @@
126127
</div>
127128
<ul class="hidden md:block filter-list">
128129
{#each yearList as item}
129-
<li class:selected={item === currentYear} on:click={() => handleChangeYear(item)}>{item}</li>
130+
<li
131+
class:selected={item === currentYear}
132+
on:click={() => handleChangeYear(item)}
133+
>
134+
{item}
135+
</li>
130136
{/each}
131137
</ul>

src/routes/stats/HistogramChart.svelte

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import { init } from "echarts";
44
import { CHART_COLOR } from "./stats";
55
6+
/**
7+
* @type {string}
8+
*/
9+
export let color = CHART_COLOR;
610
/**
711
* @type {number[]}
812
*/
@@ -16,7 +20,7 @@
1620
/**
1721
* @type {HTMLElement}
1822
*/
19-
let echartElement
23+
let echartElement;
2024
2125
/**
2226
* @type {any}
@@ -38,13 +42,14 @@
3842
},
3943
],
4044
tooltip: {
41-
show:true,
42-
trigger: 'axis'
43-
}
44-
}
45+
show: true,
46+
trigger: "axis",
47+
},
48+
};
4549
4650
$: {
47-
elementChart && elementChart.setOption({
51+
elementChart &&
52+
elementChart.setOption({
4853
xAxis: {
4954
type: "category",
5055
data: labels,
@@ -53,15 +58,21 @@
5358
{
5459
data,
5560
type: "bar",
56-
}
57-
]
61+
itemStyle: {
62+
borderRadius: [5, 5, 0, 0], // [topLeft, topRight, bottomRight, bottomLeft]
63+
},
64+
},
65+
],
5866
});
5967
}
6068
6169
onMount(() => {
6270
elementChart = init(echartElement);
6371
elementChart.setOption(option);
64-
})
72+
});
6573
</script>
6674

67-
<div class="relative h-[320px] w-[340px] md:w-[460px] m-auto" bind:this={echartElement}></div>
75+
<div
76+
class="relative h-[320px] w-[340px] md:w-[460px] m-auto"
77+
bind:this={echartElement}
78+
></div>

src/routes/stats/TopCratesChart.svelte

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import { init } from "echarts";
44
import { CHART_COLOR, TOP_CRATE_LABEL } from "./stats";
55
6-
/**
7-
* @type {{name:string; value: number}[]}
8-
*/
6+
/**
7+
* @type {{name:string; value: number}[]}
8+
*/
99
export let data = [];
1010
1111
/**
@@ -20,50 +20,58 @@
2020
const option = {
2121
color: CHART_COLOR,
2222
xAxis: {
23-
position: 'top',
23+
position: "top",
2424
},
2525
yAxis: {
2626
type: "category",
2727
data: TOP_CRATE_LABEL,
2828
inverse: true,
29-
3029
},
3130
series: [
3231
{
3332
data,
3433
type: "bar",
34+
barWidth: '55%', // Adjust this value to make bars thinner
35+
barGap: '100%', // Increase this value to create larger gaps
3536
label: {
3637
show: true,
37-
color: '#000',
38-
formatter:(/** @type {{ data: {name:string} }} */ params) => params.data.name,
38+
color: "#000",
39+
formatter: (/** @type {{ data: {name:string} }} */ params) =>
40+
params.data.name,
3941
verticalAlign: "middle",
40-
position: [10, '50%'],
42+
position: [10, "50%"],
4143
fontSize: 14,
42-
}
44+
},
45+
itemStyle: {
46+
borderRadius: [0, 5, 5, 0], // [topLeft, topRight, bottomRight, bottomLeft]
47+
},
4348
},
4449
],
4550
tooltip: {
46-
show:true,
47-
trigger: 'axis'
48-
}
49-
}
51+
show: true,
52+
trigger: "axis",
53+
},
54+
};
5055
5156
$: {
52-
if(elementChart) {
57+
if (elementChart) {
5358
elementChart.setOption({
5459
series: [
5560
{
5661
data,
57-
}
58-
]
62+
},
63+
],
5964
});
6065
}
6166
}
6267
6368
onMount(async () => {
6469
elementChart = init(echartElement);
6570
elementChart.setOption(option);
66-
})
71+
});
6772
</script>
6873

69-
<div class="relative w-[340px] md:w-[460px] m-auto h-[1060px]" bind:this={echartElement}></div>
74+
<div
75+
class="relative w-[340px] md:w-[460px] m-auto h-[1060px]"
76+
bind:this={echartElement}
77+
></div>

0 commit comments

Comments
 (0)