Skip to content

Commit 834f64b

Browse files
committed
chore: Chart component spec naming
1 parent a617775 commit 834f64b

File tree

3 files changed

+245
-1
lines changed

3 files changed

+245
-1
lines changed

src/components.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export {}
77

88
declare module 'vue' {
99
export interface GlobalComponents {
10-
Chart: typeof import('./components/chart/index.vue')['default']
10+
Chart: typeof import('./components/Chart/index.vue')['default']
1111
NavBar: typeof import('./components/NavBar.vue')['default']
1212
RouterLink: typeof import('vue-router')['RouterLink']
1313
RouterView: typeof import('vue-router')['RouterView']

src/components/Chart/dark.ts

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
const contrastColor = 'rgba(255, 255, 255, 0.65)'
2+
const backgroundColor = 'transparent'
3+
const axisCommon = function () {
4+
return {
5+
axisLine: {
6+
lineStyle: {
7+
color: contrastColor,
8+
},
9+
},
10+
splitLine: {
11+
lineStyle: {
12+
color: '#484753',
13+
},
14+
},
15+
splitArea: {
16+
areaStyle: {
17+
color: ['rgba(255,255,255,0.02)', 'rgba(255,255,255,0.05)'],
18+
},
19+
},
20+
minorSplitLine: {
21+
lineStyle: {
22+
color: '#20203B',
23+
},
24+
},
25+
}
26+
}
27+
28+
const colorPalette = [
29+
'#4992ff',
30+
'#7cffb2',
31+
'#fddd60',
32+
'#ff6e76',
33+
'#58d9f9',
34+
'#05c091',
35+
'#ff8a45',
36+
'#8d48e3',
37+
'#dd79ff',
38+
]
39+
const theme: any = {
40+
color: colorPalette,
41+
backgroundColor,
42+
axisPointer: {
43+
lineStyle: {
44+
color: '#817f91',
45+
},
46+
crossStyle: {
47+
color: '#817f91',
48+
},
49+
label: {
50+
// TODO Contrast of label backgorundColor
51+
color: '#fff',
52+
},
53+
},
54+
legend: {
55+
textStyle: {
56+
color: contrastColor,
57+
},
58+
},
59+
textStyle: {
60+
color: contrastColor,
61+
},
62+
title: {
63+
textStyle: {
64+
color: 'red',
65+
},
66+
subtextStyle: {
67+
color: 'rgba(255, 255, 255, 0.65)',
68+
},
69+
},
70+
toolbox: {
71+
iconStyle: {
72+
borderColor: contrastColor,
73+
},
74+
},
75+
dataZoom: {
76+
borderColor: '#71708A',
77+
textStyle: {
78+
color: contrastColor,
79+
},
80+
brushStyle: {
81+
color: 'rgba(135,163,206,0.3)',
82+
},
83+
handleStyle: {
84+
color: '#353450',
85+
borderColor: '#C5CBE3',
86+
},
87+
moveHandleStyle: {
88+
color: '#B0B6C3',
89+
opacity: 0.3,
90+
},
91+
fillerColor: 'rgba(135,163,206,0.2)',
92+
emphasis: {
93+
handleStyle: {
94+
borderColor: '#91B7F2',
95+
color: '#4D587D',
96+
},
97+
moveHandleStyle: {
98+
color: '#636D9A',
99+
opacity: 0.7,
100+
},
101+
},
102+
dataBackground: {
103+
lineStyle: {
104+
color: '#71708A',
105+
width: 1,
106+
},
107+
areaStyle: {
108+
color: '#71708A',
109+
},
110+
},
111+
selectedDataBackground: {
112+
lineStyle: {
113+
color: '#87A3CE',
114+
},
115+
areaStyle: {
116+
color: '#87A3CE',
117+
},
118+
},
119+
},
120+
visualMap: {
121+
textStyle: {
122+
color: contrastColor,
123+
},
124+
},
125+
timeline: {
126+
lineStyle: {
127+
color: contrastColor,
128+
},
129+
label: {
130+
color: contrastColor,
131+
},
132+
controlStyle: {
133+
color: contrastColor,
134+
borderColor: contrastColor,
135+
},
136+
},
137+
calendar: {
138+
itemStyle: {
139+
color: backgroundColor,
140+
},
141+
dayLabel: {
142+
color: contrastColor,
143+
},
144+
monthLabel: {
145+
color: contrastColor,
146+
},
147+
yearLabel: {
148+
color: contrastColor,
149+
},
150+
},
151+
timeAxis: axisCommon(),
152+
logAxis: axisCommon(),
153+
valueAxis: axisCommon(),
154+
categoryAxis: axisCommon(),
155+
156+
line: {
157+
symbol: 'circle',
158+
},
159+
graph: {
160+
color: colorPalette,
161+
},
162+
gauge: {
163+
title: {
164+
color: contrastColor,
165+
},
166+
},
167+
candlestick: {
168+
itemStyle: {
169+
color: '#FD1050',
170+
color0: '#0CF49B',
171+
borderColor: '#FD1050',
172+
borderColor0: '#0CF49B',
173+
},
174+
},
175+
}
176+
177+
theme.categoryAxis.splitLine.show = false
178+
179+
export default theme

src/components/Chart/index.vue

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<script setup lang="ts">
2+
import type { ECharts } from 'echarts'
3+
import * as echarts from 'echarts'
4+
import { debounce } from 'lodash-es'
5+
import { addListener, removeListener } from 'resize-detector'
6+
import dark from './dark'
7+
8+
const props = defineProps({
9+
option: Object,
10+
})
11+
12+
echarts.registerTheme('dark-chart', dark)
13+
14+
const chartDom = ref<HTMLDivElement>()
15+
let chart: ECharts | null = null
16+
const isRealDark = ref(isDark.value)
17+
function resizeChart() {
18+
chart?.resize()
19+
}
20+
21+
const resize = debounce(resizeChart, 300)
22+
23+
function disposeChart() {
24+
if (chartDom.value)
25+
removeListener(chartDom.value, resize)
26+
27+
chart?.dispose()
28+
chart = null
29+
}
30+
31+
function initChart() {
32+
disposeChart()
33+
if (chartDom.value) {
34+
// init echarts
35+
chart = echarts.init(chartDom.value, isRealDark.value ? 'dark-chart' : undefined)
36+
chart.setOption(props.option)
37+
addListener(chartDom.value, resize)
38+
}
39+
}
40+
41+
watch(isRealDark, () => {
42+
initChart()
43+
}, {
44+
flush: 'post',
45+
})
46+
47+
onMounted(() => {
48+
watch(() => props.option, () => {
49+
chart?.setOption(props.option)
50+
}, {
51+
deep: true,
52+
flush: 'post',
53+
})
54+
55+
initChart()
56+
})
57+
58+
onUnmounted(() => {
59+
disposeChart()
60+
})
61+
</script>
62+
63+
<template>
64+
<div ref="chartDom" />
65+
</template>

0 commit comments

Comments
 (0)