Skip to content

Commit a090e50

Browse files
committed
chore: optimize the user count chart
1 parent db0eebe commit a090e50

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

script/user-chart/render.ts

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import {
2-
createGist,
3-
type FileForm,
4-
findTarget,
5-
getJsonFileContent,
6-
type GistForm,
7-
updateGist
2+
createGist, findTarget, getJsonFileContent, updateGist,
3+
type FileForm, type GistForm,
84
} from "@api/gist"
9-
import { type EChartsType, init } from "echarts"
5+
import {
6+
init,
7+
type ComposeOption, type EChartsType, type GridComponentOption, type LineSeriesOption, type TitleComponentOption,
8+
} from "echarts"
109
import { writeFileSync } from "fs"
11-
import { exit } from "process"
10+
import { exit } from 'process'
1211
import { filenameOf, getExistGist, validateTokenFromEnv } from "./common"
1312

13+
type EcOption = ComposeOption<
14+
| LineSeriesOption
15+
| TitleComponentOption
16+
| GridComponentOption
17+
>
18+
1419
const ALL_BROWSERS: Browser[] = ['firefox', 'edge', 'chrome']
1520

16-
const POINT_COUNT = 200
21+
const POINT_COUNT = 500
1722

1823
type OriginData = {
1924
[browser in Browser]: UserCount
@@ -127,7 +132,7 @@ function render2Svg(chartData: ChartData): string {
127132
const totalUserCount = Object.values(yAxises)
128133
.map(v => v[v.length - 1] || 0)
129134
.reduce((a, b) => a + b)
130-
chart.setOption({
135+
const option: EcOption = {
131136
title: {
132137
text: 'Total Active User Count',
133138
subtext: `${xAxis[0]} to ${xAxis[xAxis.length - 1]} | currently ${totalUserCount} `
@@ -139,23 +144,30 @@ function render2Svg(chartData: ChartData): string {
139144
bottom: '8%',
140145
containLabel: true
141146
},
142-
xAxis: [{
143-
type: 'category',
144-
boundaryGap: false,
145-
data: xAxis
146-
}],
147-
yAxis: [
148-
{ type: 'value' }
149-
],
147+
xAxis: { type: 'time' },
148+
yAxis: {
149+
type: 'value',
150+
minInterval: 100,
151+
axisLabel: {
152+
formatter(value) {
153+
const text = value.toString()
154+
const textLen = text.length
155+
return textLen < 4 ? text : text.substring(0, textLen - 3) + 'K'
156+
},
157+
},
158+
},
150159
series: ALL_BROWSERS.map(b => ({
151160
name: b,
152161
type: 'line',
153162
stack: 'Total',
154163
// Fill the area
155164
areaStyle: {},
156-
data: yAxises[b]
165+
lineStyle: { width: 0 },
166+
showSymbol: false,
167+
data: yAxises[b].map((val, idx) => [xAxis[idx], val]),
157168
}))
158-
})
169+
}
170+
chart.setOption(option)
159171
return chart.renderToSVGString()
160172
}
161173

0 commit comments

Comments
 (0)