@easy-editor/materials-dashboard-line-chart 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/component.min.js +3 -4
- package/dist/index.min.js +3 -4
- package/dist/meta.min.js +1 -2
- package/easypack.config.ts +10 -0
- package/package.json +4 -8
- package/src/component.tsx +277 -232
- package/src/configure.ts +170 -349
- package/src/index.tsx +7 -7
- package/src/meta.ts +23 -23
- package/src/snippets.ts +101 -51
- package/tsconfig.json +20 -9
- package/.vite/plugins/vite-plugin-external-deps.ts +0 -224
- package/.vite/plugins/vite-plugin-material-dev.ts +0 -218
- package/dist/component.esm.js +0 -35200
- package/dist/component.esm.js.map +0 -1
- package/dist/component.js +0 -35207
- package/dist/component.js.map +0 -1
- package/dist/component.min.js.map +0 -1
- package/dist/index.cjs +0 -35572
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js +0 -35569
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -35576
- package/dist/index.js.map +0 -1
- package/dist/index.min.js.map +0 -1
- package/dist/meta.esm.js +0 -403
- package/dist/meta.esm.js.map +0 -1
- package/dist/meta.js +0 -413
- package/dist/meta.js.map +0 -1
- package/dist/meta.min.js.map +0 -1
- package/dist/src/component.d.ts +0 -19
- package/dist/src/configure.d.ts +0 -7
- package/dist/src/constants.d.ts +0 -27
- package/dist/src/index.d.ts +0 -6
- package/dist/src/meta.d.ts +0 -3
- package/dist/src/snippets.d.ts +0 -3
- package/rollup.config.js +0 -212
- package/tsconfig.build.json +0 -12
- package/tsconfig.test.json +0 -7
- package/vite.config.ts +0 -54
package/dist/meta.min.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).
|
|
2
|
-
//# sourceMappingURL=meta.min.js.map
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EasyEditorMaterialsLineChartMeta={})}(this,function(e){"use strict";const t=(e,t)=>{const a=Array.isArray(e)?e:[e],r=a[0]||{};return{sourceType:"static",staticData:a,fieldMappings:Object.keys(r).map(e=>({componentField:e,sourceField:e}))}},a=(e,t,a)=>({type:"group",title:e,setter:{componentName:"CollapseSetter",props:{icon:!1,...a}},items:t}),r={name:"nodeInfo",title:"节点信息",setter:"NodeInfoSetter",extraProps:{label:!1}},o=a("基础配置",[{name:"title",title:"标题",setter:"StringSetter",extraProps:{getValue:e=>e.getExtraPropValue("title"),setValue(e,t){e.setExtraPropValue("title",t)}}},{name:"rect",title:"位置尺寸",setter:"RectSetter",extraProps:{getValue:e=>e.getExtraPropValue("$dashboard.rect"),setValue(e,t){e.setExtraPropValue("$dashboard.rect",t)}}},{name:"rotation",title:"旋转角度",setter:{componentName:"SliderSetter",props:{min:0,max:360,suffix:"°"}},extraProps:{defaultValue:0}},{name:"opacity",title:"不透明度",setter:{componentName:"SliderSetter",props:{min:0,max:100,suffix:"%"}},extraProps:{defaultValue:100}},{name:"background",title:"背景颜色",setter:"ColorSetter",extraProps:{defaultValue:"transparent"}}]),l=[{title:"点击事件",children:[{label:"点击",value:"onClick",description:"鼠标点击时触发"},{label:"双击",value:"onDoubleClick",description:"鼠标双击时触发"}]},{title:"鼠标事件",children:[{label:"鼠标进入",value:"onMouseEnter",description:"鼠标进入时触发"},{label:"鼠标离开",value:"onMouseLeave",description:"鼠标离开时触发"}]}],i=((e=l)=>a("事件绑定",[{name:"events",title:"事件",setter:{componentName:"EventSetter",props:{events:e}},extraProps:{label:!1}}]))(),s=a("高级配置",[{title:"条件渲染",setter:"SwitchSetter",extraProps:{supportVariable:!0,getValue:e=>e.getNode().getExtraPropValue("condition"),setValue(e,t){e.getNode().setExtraProp("condition",t)}}}]),n="EasyEditorMaterialsLineChart";const p=((e,t)=>({props:[{type:"group",title:"属性",setter:"TabSetter",items:[{type:"group",key:"config",title:"配置",items:[r,o,e]},{type:"group",key:"data",title:"数据",items:[r,t]},{type:"group",key:"advanced",title:"高级",items:[r,i,s]}]}],component:{},supports:{},advanced:{}}))(a("组件配置",[{type:"group",title:"组件配置",setter:"SubTabSetter",items:[{type:"group",key:"chartData",title:"数据",items:[{name:"xField",title:"X轴字段",setter:"StringSetter",extraProps:{defaultValue:"name"}},{name:"yFields",title:"Y轴字段",setter:{componentName:"ArraySetter",props:{itemSetter:"StringSetter"}},extraProps:{defaultValue:["value1","value2"]}}]},{type:"group",key:"style",title:"样式",items:[{name:"colors",title:"颜色",setter:{componentName:"ArraySetter",props:{itemSetter:"ColorSetter"}}},{name:"strokeWidth",title:"线条宽度",setter:{componentName:"SliderSetter",props:{min:1,max:10,step:1,suffix:"px"}},extraProps:{defaultValue:2}},{name:"smooth",title:"平滑曲线",setter:"SwitchSetter",extraProps:{defaultValue:!0}},{name:"areaFill",title:"区域填充",setter:"SwitchSetter",extraProps:{defaultValue:!1}},{name:"glowEffect",title:"发光效果",setter:"SwitchSetter",extraProps:{defaultValue:!0}}]},{type:"group",key:"legend",title:"图例",items:[{name:"showGrid",title:"显示网格",setter:"SwitchSetter",extraProps:{defaultValue:!0}},{name:"showLegend",title:"显示图例",setter:"SwitchSetter",extraProps:{defaultValue:!0}},{name:"legendPosition",title:"图例位置",setter:{componentName:"SelectSetter",props:{options:[{label:"顶部",value:"top"},{label:"底部",value:"bottom"},{label:"左侧",value:"left"},{label:"右侧",value:"right"}]}},extraProps:{defaultValue:"bottom"}},{name:"showTooltip",title:"显示提示",setter:"SwitchSetter",extraProps:{defaultValue:!0}}]}]}],{padding:"6px 16px 12px"}),{name:"$data",title:"数据配置",setter:{componentName:"DataSetter",props:{expectedFields:[{name:"name",label:"name",type:"string",required:!0,description:"类目名称"},{name:"value1",label:"value1",type:"number",required:!0,description:"数值1"},{name:"value2",label:"value2",type:"number",required:!1,description:"数值2"}],showPreview:!0,previewLimit:10}},extraProps:{label:!1}}),d=[{name:"A",value1:120,value2:80},{name:"B",value1:200,value2:120},{name:"C",value1:150,value2:100},{name:"D",value1:280,value2:180},{name:"E",value1:220,value2:140}];const u={componentName:n,title:"折线图",group:"chart",devMode:"proCode",npm:{package:"@easy-editor/materials-dashboard-line-chart",version:"0.0.4",globalName:n,componentName:n},snippets:[{title:"折线图",screenshot:"",schema:{componentName:n,title:"折线图",props:{$data:t(d),xField:"name",yFields:["value1","value2"],showGrid:!0,showLegend:!0,glowEffect:!0,strokeWidth:2,rotation:0,opacity:100,background:"transparent"},$dashboard:{rect:{width:400,height:300}}}},{title:"面积图",screenshot:"",schema:{componentName:n,title:"面积图",props:{$data:t(d),xField:"name",yFields:["value1","value2"],showGrid:!0,showLegend:!0,glowEffect:!0,strokeWidth:2,areaFill:!0,rotation:0,opacity:100,background:"transparent"},$dashboard:{rect:{width:400,height:300}}}},{title:"简单折线图",screenshot:"",schema:{componentName:n,title:"简单折线图",props:{$data:t(d),xField:"name",yFields:["value1"],showGrid:!0,showLegend:!1,glowEffect:!0,strokeWidth:3,rotation:0,opacity:100,background:"transparent"},$dashboard:{rect:{width:300,height:200}}}}],configure:p};e.meta=u});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easy-editor/materials-dashboard-line-chart",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Line Chart component for EasyEditor dashboard",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -48,20 +48,16 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"echarts": "^5.6.0",
|
|
51
|
-
"@easy-editor/materials-shared": "0.0.
|
|
51
|
+
"@easy-editor/materials-shared": "0.0.1"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"dev": "
|
|
54
|
+
"dev": "easypack dev",
|
|
55
55
|
"dev:debug": "vite --port 5002",
|
|
56
56
|
"format": "biome format --write .",
|
|
57
57
|
"lint": "biome check .",
|
|
58
58
|
"build": "npm-run-all -nl build:*",
|
|
59
59
|
"build:clean": "rimraf dist/",
|
|
60
|
-
"build:js": "
|
|
61
|
-
"build:types": "pnpm types",
|
|
62
|
-
"types": "npm-run-all -nl types:*",
|
|
63
|
-
"types:src": "tsc --project tsconfig.build.json",
|
|
64
|
-
"test-types": "tsc --project tsconfig.test.json"
|
|
60
|
+
"build:js": "easypack build"
|
|
65
61
|
},
|
|
66
62
|
"module": "dist/index.esm.js",
|
|
67
63
|
"unpkg": "dist/index.min.js"
|
package/src/component.tsx
CHANGED
|
@@ -1,232 +1,277 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import type
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Line Chart Component
|
|
3
|
+
* 折线图组件 - 支持数据源绑定和事件交互
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
|
|
7
|
+
import * as echarts from 'echarts/core'
|
|
8
|
+
import { LineChart as EChartsLineChart } from 'echarts/charts'
|
|
9
|
+
import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
|
|
10
|
+
import { CanvasRenderer } from 'echarts/renderers'
|
|
11
|
+
import type { SeriesOption } from 'echarts'
|
|
12
|
+
import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
|
|
13
|
+
import { DEFAULT_COLORS, DEFAULT_DATA, type DataPoint } from './constants'
|
|
14
|
+
import styles from './component.module.css'
|
|
15
|
+
|
|
16
|
+
// 按需注册 ECharts 组件
|
|
17
|
+
echarts.use([EChartsLineChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
|
|
18
|
+
|
|
19
|
+
export interface LineChartProps extends MaterialComponet {
|
|
20
|
+
/** X轴字段 */
|
|
21
|
+
xField?: string
|
|
22
|
+
/** Y轴字段列表 */
|
|
23
|
+
yFields?: string[]
|
|
24
|
+
/** 颜色列表 */
|
|
25
|
+
colors?: string[]
|
|
26
|
+
/** 显示网格 */
|
|
27
|
+
showGrid?: boolean
|
|
28
|
+
/** 显示图例 */
|
|
29
|
+
showLegend?: boolean
|
|
30
|
+
/** 显示提示 */
|
|
31
|
+
showTooltip?: boolean
|
|
32
|
+
/** 发光效果 */
|
|
33
|
+
glowEffect?: boolean
|
|
34
|
+
/** 线条宽度 */
|
|
35
|
+
strokeWidth?: number
|
|
36
|
+
/** 区域填充 */
|
|
37
|
+
areaFill?: boolean
|
|
38
|
+
/** 平滑曲线 */
|
|
39
|
+
smooth?: boolean
|
|
40
|
+
/** 点击事件 */
|
|
41
|
+
onClick?: (e: React.MouseEvent) => void
|
|
42
|
+
/** 双击事件 */
|
|
43
|
+
onDoubleClick?: (e: React.MouseEvent) => void
|
|
44
|
+
/** 鼠标进入 */
|
|
45
|
+
onMouseEnter?: (e: React.MouseEvent) => void
|
|
46
|
+
/** 鼠标离开 */
|
|
47
|
+
onMouseLeave?: (e: React.MouseEvent) => void
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 构建 series 配置
|
|
51
|
+
const buildSeries = (
|
|
52
|
+
yFields: string[],
|
|
53
|
+
data: DataPoint[],
|
|
54
|
+
colors: string[],
|
|
55
|
+
options: {
|
|
56
|
+
smooth: boolean
|
|
57
|
+
strokeWidth: number
|
|
58
|
+
glowEffect: boolean
|
|
59
|
+
areaFill: boolean
|
|
60
|
+
},
|
|
61
|
+
): SeriesOption[] => {
|
|
62
|
+
const { smooth, strokeWidth, glowEffect, areaFill } = options
|
|
63
|
+
return yFields.map((field, index) => {
|
|
64
|
+
const color = colors[index % colors.length]
|
|
65
|
+
return {
|
|
66
|
+
name: field,
|
|
67
|
+
type: 'line' as const,
|
|
68
|
+
data: data.map(item => item[field] as number),
|
|
69
|
+
smooth,
|
|
70
|
+
lineStyle: {
|
|
71
|
+
width: strokeWidth,
|
|
72
|
+
color,
|
|
73
|
+
shadowColor: glowEffect ? color : 'transparent',
|
|
74
|
+
shadowBlur: glowEffect ? 10 : 0,
|
|
75
|
+
},
|
|
76
|
+
itemStyle: {
|
|
77
|
+
color,
|
|
78
|
+
},
|
|
79
|
+
areaStyle: areaFill
|
|
80
|
+
? {
|
|
81
|
+
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
82
|
+
{ offset: 0, color: `${color}40` },
|
|
83
|
+
{ offset: 1, color: `${color}05` },
|
|
84
|
+
]),
|
|
85
|
+
}
|
|
86
|
+
: undefined,
|
|
87
|
+
symbol: 'circle',
|
|
88
|
+
symbolSize: 6,
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 构建图表配置
|
|
94
|
+
const buildOption = (
|
|
95
|
+
data: DataPoint[],
|
|
96
|
+
xField: string,
|
|
97
|
+
series: SeriesOption[],
|
|
98
|
+
options: {
|
|
99
|
+
showGrid: boolean
|
|
100
|
+
showLegend: boolean
|
|
101
|
+
showTooltip: boolean
|
|
102
|
+
},
|
|
103
|
+
) => {
|
|
104
|
+
const { showGrid, showLegend, showTooltip } = options
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
backgroundColor: 'transparent',
|
|
108
|
+
grid: {
|
|
109
|
+
top: showLegend ? 40 : 20,
|
|
110
|
+
right: 20,
|
|
111
|
+
bottom: 30,
|
|
112
|
+
left: 50,
|
|
113
|
+
containLabel: false,
|
|
114
|
+
},
|
|
115
|
+
xAxis: {
|
|
116
|
+
type: 'category',
|
|
117
|
+
data: data.map(item => item[xField]),
|
|
118
|
+
axisLine: {
|
|
119
|
+
lineStyle: {
|
|
120
|
+
color: '#8899aa',
|
|
121
|
+
opacity: 0.3,
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
axisTick: { show: false },
|
|
125
|
+
axisLabel: {
|
|
126
|
+
color: '#8899aa',
|
|
127
|
+
fontSize: 12,
|
|
128
|
+
},
|
|
129
|
+
splitLine: {
|
|
130
|
+
show: showGrid,
|
|
131
|
+
lineStyle: {
|
|
132
|
+
color: '#00d4ff',
|
|
133
|
+
opacity: 0.1,
|
|
134
|
+
type: 'dashed',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
yAxis: {
|
|
139
|
+
type: 'value',
|
|
140
|
+
axisLine: {
|
|
141
|
+
lineStyle: {
|
|
142
|
+
color: '#8899aa',
|
|
143
|
+
opacity: 0.3,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
axisTick: { show: false },
|
|
147
|
+
axisLabel: {
|
|
148
|
+
color: '#8899aa',
|
|
149
|
+
fontSize: 11,
|
|
150
|
+
},
|
|
151
|
+
splitLine: {
|
|
152
|
+
show: showGrid,
|
|
153
|
+
lineStyle: {
|
|
154
|
+
color: '#00d4ff',
|
|
155
|
+
opacity: 0.1,
|
|
156
|
+
type: 'dashed',
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
tooltip: showTooltip
|
|
161
|
+
? {
|
|
162
|
+
trigger: 'axis',
|
|
163
|
+
backgroundColor: 'rgba(0, 20, 40, 0.9)',
|
|
164
|
+
borderColor: '#00d4ff',
|
|
165
|
+
borderWidth: 1,
|
|
166
|
+
textStyle: {
|
|
167
|
+
color: '#fff',
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
: undefined,
|
|
171
|
+
legend: showLegend
|
|
172
|
+
? {
|
|
173
|
+
show: true,
|
|
174
|
+
top: 10,
|
|
175
|
+
textStyle: {
|
|
176
|
+
color: '#8899aa',
|
|
177
|
+
fontSize: 11,
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
: undefined,
|
|
181
|
+
series,
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export const LineChart: React.FC<LineChartProps> = ({
|
|
186
|
+
ref,
|
|
187
|
+
$data,
|
|
188
|
+
__dataSource,
|
|
189
|
+
xField = 'name',
|
|
190
|
+
yFields = ['value1', 'value2'],
|
|
191
|
+
colors = DEFAULT_COLORS,
|
|
192
|
+
showGrid = true,
|
|
193
|
+
showLegend = true,
|
|
194
|
+
showTooltip = true,
|
|
195
|
+
glowEffect = true,
|
|
196
|
+
strokeWidth = 2,
|
|
197
|
+
areaFill = false,
|
|
198
|
+
smooth = true,
|
|
199
|
+
rotation = 0,
|
|
200
|
+
opacity = 100,
|
|
201
|
+
background = 'transparent',
|
|
202
|
+
style: externalStyle,
|
|
203
|
+
onClick,
|
|
204
|
+
onDoubleClick,
|
|
205
|
+
onMouseEnter,
|
|
206
|
+
onMouseLeave,
|
|
207
|
+
}) => {
|
|
208
|
+
const chartRef = useRef<HTMLDivElement>(null)
|
|
209
|
+
const chartInstance = useRef<echarts.ECharts | null>(null)
|
|
210
|
+
|
|
211
|
+
// 解析数据源
|
|
212
|
+
const dataSource = useDataSource($data, __dataSource)
|
|
213
|
+
const data = useMemo<DataPoint[]>(() => {
|
|
214
|
+
if (dataSource.length > 0) {
|
|
215
|
+
return dataSource as DataPoint[]
|
|
216
|
+
}
|
|
217
|
+
return DEFAULT_DATA
|
|
218
|
+
}, [dataSource])
|
|
219
|
+
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
if (!chartRef.current) {
|
|
222
|
+
return
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
chartInstance.current = echarts.init(chartRef.current)
|
|
226
|
+
|
|
227
|
+
// 构建 series
|
|
228
|
+
const series = buildSeries(yFields, data, colors, {
|
|
229
|
+
smooth,
|
|
230
|
+
strokeWidth,
|
|
231
|
+
glowEffect,
|
|
232
|
+
areaFill,
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
const option = buildOption(data, xField, series, {
|
|
236
|
+
showGrid,
|
|
237
|
+
showLegend,
|
|
238
|
+
showTooltip,
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
chartInstance.current.setOption(option)
|
|
242
|
+
|
|
243
|
+
// 响应式调整
|
|
244
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
245
|
+
chartInstance.current?.resize()
|
|
246
|
+
})
|
|
247
|
+
resizeObserver.observe(chartRef.current)
|
|
248
|
+
|
|
249
|
+
return () => {
|
|
250
|
+
resizeObserver.disconnect()
|
|
251
|
+
chartInstance.current?.dispose()
|
|
252
|
+
}
|
|
253
|
+
}, [data, xField, yFields, colors, showGrid, showLegend, showTooltip, glowEffect, strokeWidth, areaFill, smooth])
|
|
254
|
+
|
|
255
|
+
const containerStyle: CSSProperties = {
|
|
256
|
+
width: '100%',
|
|
257
|
+
height: '100%',
|
|
258
|
+
transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
|
|
259
|
+
opacity: opacity / 100,
|
|
260
|
+
backgroundColor: background,
|
|
261
|
+
...externalStyle,
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return (
|
|
265
|
+
<div
|
|
266
|
+
className={styles.container}
|
|
267
|
+
onClick={onClick}
|
|
268
|
+
onDoubleClick={onDoubleClick}
|
|
269
|
+
onMouseEnter={onMouseEnter}
|
|
270
|
+
onMouseLeave={onMouseLeave}
|
|
271
|
+
ref={ref}
|
|
272
|
+
style={containerStyle}
|
|
273
|
+
>
|
|
274
|
+
<div className={styles.chart} ref={chartRef} />
|
|
275
|
+
</div>
|
|
276
|
+
)
|
|
277
|
+
}
|