@easy-editor/materials-dashboard-radar-chart 0.0.4 → 0.0.5

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.
@@ -0,0 +1,61 @@
1
+ // 自定义插件:处理 echarts 模块的命名导出
2
+ export const echartsExternalPlugin = () => {
3
+ const ECHARTS_MODULES = ['echarts', 'echarts/core', 'echarts/charts', 'echarts/components', 'echarts/renderers']
4
+ const VIRTUAL_PREFIX = '\0virtual:echarts-external:'
5
+
6
+ return {
7
+ name: 'vite-plugin-echarts-external',
8
+ enforce: 'pre',
9
+ resolveId(id) {
10
+ if (ECHARTS_MODULES.includes(id)) {
11
+ return VIRTUAL_PREFIX + id
12
+ }
13
+ return null
14
+ },
15
+ load(id) {
16
+ if (!id.startsWith(VIRTUAL_PREFIX)) {
17
+ return null
18
+ }
19
+ const moduleName = id.slice(VIRTUAL_PREFIX.length)
20
+ const globalKey = moduleName.includes('/') ? `["${moduleName}"]` : `.${moduleName}`
21
+
22
+ return `
23
+ // External module: ${moduleName} -> window${globalKey}
24
+ const mod = window${globalKey} || window.echarts;
25
+ if (!mod) {
26
+ throw new Error('External dependency "${moduleName}" is not available on window.');
27
+ }
28
+ export default mod;
29
+ export const {
30
+ ${getExportsForModule(moduleName)}
31
+ } = mod;
32
+ `
33
+ },
34
+ }
35
+ }
36
+
37
+ // 根据模块名返回需要导出的属性
38
+ function getExportsForModule(moduleName) {
39
+ switch (moduleName) {
40
+ case 'echarts/core':
41
+ return 'use, init, graphic, registerMap, getMap'
42
+ case 'echarts/charts':
43
+ return 'MapChart, LinesChart, EffectScatterChart, BarChart, LineChart, PieChart, RadarChart, ScatterChart, GaugeChart'
44
+ case 'echarts/components':
45
+ return 'GeoComponent, TooltipComponent, LegendComponent, GridComponent, VisualMapComponent, TitleComponent'
46
+ case 'echarts/renderers':
47
+ return 'CanvasRenderer, SVGRenderer'
48
+ default:
49
+ return 'use, init, graphic, registerMap'
50
+ }
51
+ }
52
+
53
+ // echarts 模块列表
54
+ export const ECHARTS_EXTERNALS = ['echarts', 'echarts/core', 'echarts/charts', 'echarts/components', 'echarts/renderers']
55
+ export const ECHARTS_GLOBALS = {
56
+ echarts: 'echarts',
57
+ 'echarts/core': 'echarts',
58
+ 'echarts/charts': 'echarts',
59
+ 'echarts/components': 'echarts',
60
+ 'echarts/renderers': 'echarts',
61
+ }
package/CHANGELOG.md CHANGED
@@ -1,21 +1,27 @@
1
- # @easy-editor/materials-dashboard-radar-chart
2
-
3
- ## 0.0.4
4
-
5
- ### Patch Changes
6
-
7
- - perf: configure & datasource
8
- - Updated dependencies
9
- - @easy-editor/materials-shared@0.0.1
10
-
11
- ## 0.0.3
12
-
13
- ### Patch Changes
14
-
15
- - fix: build error
16
-
17
- ## 0.0.2
18
-
19
- ### Patch Changes
20
-
21
- - feat: new setters
1
+ # @easy-editor/materials-dashboard-radar-chart
2
+
3
+ ## 0.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: component export error
8
+
9
+ ## 0.0.4
10
+
11
+ ### Patch Changes
12
+
13
+ - perf: configure & datasource
14
+ - Updated dependencies
15
+ - @easy-editor/materials-shared@0.0.1
16
+
17
+ ## 0.0.3
18
+
19
+ ### Patch Changes
20
+
21
+ - fix: build error
22
+
23
+ ## 0.0.2
24
+
25
+ ### Patch Changes
26
+
27
+ - feat: new setters
@@ -2,9 +2,18 @@
2
2
  * @easy-editor/easypack configuration
3
3
  * @type {import('@easy-editor/easypack').EasypackConfig}
4
4
  */
5
+ import { ECHARTS_EXTERNALS, ECHARTS_GLOBALS, echartsExternalPlugin } from './.vite/echarts-external-plugin'
6
+
5
7
  export default {
6
8
  preset: 'material',
7
9
  dev: {
8
10
  port: 5001,
9
11
  },
12
+ rollup: {
13
+ external: ECHARTS_EXTERNALS,
14
+ output: {
15
+ globals: ECHARTS_GLOBALS,
16
+ },
17
+ },
18
+ vitePlugins: [echartsExternalPlugin()],
10
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-editor/materials-dashboard-radar-chart",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Radar Chart component for EasyEditor dashboard",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/component.tsx CHANGED
@@ -1,244 +1,246 @@
1
- /**
2
- * Radar Chart Component
3
- * 雷达图组件 - 支持数据源绑定和事件交互
4
- */
5
-
6
- import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
7
- import * as echarts from 'echarts/core'
8
- import { RadarChart as EChartsRadarChart } from 'echarts/charts'
9
- import { TooltipComponent, LegendComponent } from 'echarts/components'
10
- import { CanvasRenderer } from 'echarts/renderers'
11
- import type { EChartsOption } from 'echarts'
12
- import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
13
- import { DEFAULT_DATA, DEFAULT_SERIES, type RadarDataPoint } from './constants'
14
- import styles from './component.module.css'
15
-
16
- // 按需注册 ECharts 组件
17
- echarts.use([EChartsRadarChart, TooltipComponent, LegendComponent, CanvasRenderer])
18
-
19
- interface RadarSeries {
20
- name: string
21
- dataKey: string
22
- color: string
23
- }
24
-
25
- export interface RadarChartProps extends MaterialComponet {
26
- /** 静态数据(兼容旧版) */
27
- data?: RadarDataPoint[]
28
- /** 维度字段 */
29
- dimensionKey?: string
30
- /** 系列配置 */
31
- series?: RadarSeries[]
32
- /** 显示网格 */
33
- showGrid?: boolean
34
- /** 填充透明度 */
35
- fillOpacity?: number
36
- /** 发光效果 */
37
- glowEffect?: boolean
38
- /** 显示图例 */
39
- showLegend?: boolean
40
- /** 显示提示 */
41
- showTooltip?: boolean
42
- /** 点击事件 */
43
- onClick?: (e: React.MouseEvent) => void
44
- /** 双击事件 */
45
- onDoubleClick?: (e: React.MouseEvent) => void
46
- /** 鼠标进入 */
47
- onMouseEnter?: (e: React.MouseEvent) => void
48
- /** 鼠标离开 */
49
- onMouseLeave?: (e: React.MouseEvent) => void
50
- }
51
-
52
- // 构建图表配置
53
- const buildOption = (
54
- data: RadarDataPoint[],
55
- dimensionKey: string,
56
- series: RadarSeries[],
57
- options: {
58
- showGrid: boolean
59
- fillOpacity: number
60
- glowEffect: boolean
61
- showLegend: boolean
62
- showTooltip: boolean
63
- },
64
- ): EChartsOption => {
65
- const { showGrid, fillOpacity, glowEffect, showLegend, showTooltip } = options
66
-
67
- // 提取维度名称
68
- const indicators = data.map(item => ({
69
- name: item[dimensionKey] as string,
70
- max: 100,
71
- }))
72
-
73
- // 构建 series 数据
74
- const seriesData = series.map(s => ({
75
- name: s.name,
76
- value: data.map(item => item[s.dataKey] as number),
77
- itemStyle: {
78
- color: s.color,
79
- shadowColor: glowEffect ? s.color : 'transparent',
80
- shadowBlur: glowEffect ? 10 : 0,
81
- },
82
- lineStyle: {
83
- color: s.color,
84
- width: 2,
85
- shadowColor: glowEffect ? s.color : 'transparent',
86
- shadowBlur: glowEffect ? 10 : 0,
87
- },
88
- areaStyle: {
89
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
90
- {
91
- offset: 0,
92
- color: `${s.color}${Math.round(fillOpacity * 255)
93
- .toString(16)
94
- .padStart(2, '0')}`,
95
- },
96
- { offset: 1, color: `${s.color}10` },
97
- ]),
98
- },
99
- }))
100
-
101
- return {
102
- backgroundColor: 'transparent',
103
- tooltip: showTooltip
104
- ? {
105
- trigger: 'item',
106
- backgroundColor: 'rgba(0, 20, 40, 0.9)',
107
- borderColor: '#00d4ff',
108
- borderWidth: 1,
109
- textStyle: {
110
- color: '#fff',
111
- },
112
- }
113
- : undefined,
114
- legend: showLegend
115
- ? {
116
- show: true,
117
- bottom: 10,
118
- textStyle: {
119
- color: '#8899aa',
120
- fontSize: 11,
121
- },
122
- }
123
- : undefined,
124
- radar: {
125
- indicator: indicators,
126
- shape: 'polygon',
127
- splitNumber: 5,
128
- axisName: {
129
- color: '#8899aa',
130
- fontSize: 11,
131
- },
132
- splitLine: {
133
- show: showGrid,
134
- lineStyle: {
135
- color: '#1a3a5c',
136
- opacity: 0.6,
137
- },
138
- },
139
- splitArea: {
140
- show: false,
141
- },
142
- axisLine: {
143
- show: showGrid,
144
- lineStyle: {
145
- color: '#1a3a5c',
146
- opacity: 0.6,
147
- },
148
- },
149
- },
150
- series: [
151
- {
152
- type: 'radar',
153
- data: seriesData,
154
- symbol: 'circle',
155
- symbolSize: 6,
156
- },
157
- ],
158
- }
159
- }
160
-
161
- export const RadarChart: React.FC<RadarChartProps> = ({
162
- ref,
163
- $data,
164
- __dataSource,
165
- data: staticData,
166
- dimensionKey = 'dimension',
167
- series = DEFAULT_SERIES,
168
- showGrid = true,
169
- fillOpacity = 0.3,
170
- glowEffect = true,
171
- showLegend = true,
172
- showTooltip = true,
173
- rotation = 0,
174
- opacity = 100,
175
- background = 'transparent',
176
- style: externalStyle,
177
- onClick,
178
- onDoubleClick,
179
- onMouseEnter,
180
- onMouseLeave,
181
- }) => {
182
- const chartRef = useRef<HTMLDivElement>(null)
183
- const chartInstance = useRef<echarts.ECharts | null>(null)
184
-
185
- // 解析数据源
186
- const dataSource = useDataSource($data, __dataSource)
187
- const data = useMemo<RadarDataPoint[]>(() => {
188
- if (dataSource.length > 0) {
189
- return dataSource as RadarDataPoint[]
190
- }
191
- return staticData ?? DEFAULT_DATA
192
- }, [dataSource, staticData])
193
-
194
- useEffect(() => {
195
- if (!chartRef.current) {
196
- return
197
- }
198
-
199
- chartInstance.current = echarts.init(chartRef.current)
200
-
201
- const option = buildOption(data, dimensionKey, series, {
202
- showGrid,
203
- fillOpacity,
204
- glowEffect,
205
- showLegend,
206
- showTooltip,
207
- })
208
-
209
- chartInstance.current.setOption(option)
210
-
211
- const resizeObserver = new ResizeObserver(() => {
212
- chartInstance.current?.resize()
213
- })
214
- resizeObserver.observe(chartRef.current)
215
-
216
- return () => {
217
- resizeObserver.disconnect()
218
- chartInstance.current?.dispose()
219
- }
220
- }, [data, dimensionKey, series, showGrid, fillOpacity, glowEffect, showLegend, showTooltip])
221
-
222
- const containerStyle: CSSProperties = {
223
- width: '100%',
224
- height: '100%',
225
- transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
226
- opacity: opacity / 100,
227
- backgroundColor: background,
228
- ...externalStyle,
229
- }
230
-
231
- return (
232
- <div
233
- className={styles.container}
234
- onClick={onClick}
235
- onDoubleClick={onDoubleClick}
236
- onMouseEnter={onMouseEnter}
237
- onMouseLeave={onMouseLeave}
238
- ref={ref}
239
- style={containerStyle}
240
- >
241
- <div className={styles.chart} ref={chartRef} />
242
- </div>
243
- )
244
- }
1
+ /**
2
+ * Radar Chart Component
3
+ * 雷达图组件 - 支持数据源绑定和事件交互
4
+ */
5
+
6
+ import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
7
+ import * as echarts from 'echarts/core'
8
+ import { RadarChart as EChartsRadarChart } from 'echarts/charts'
9
+ import { TooltipComponent, LegendComponent } from 'echarts/components'
10
+ import { CanvasRenderer } from 'echarts/renderers'
11
+ import type { EChartsOption } from 'echarts'
12
+ import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
13
+ import { DEFAULT_DATA, DEFAULT_SERIES, type RadarDataPoint } from './constants'
14
+ import styles from './component.module.css'
15
+
16
+ // 按需注册 ECharts 组件
17
+ echarts.use([EChartsRadarChart, TooltipComponent, LegendComponent, CanvasRenderer])
18
+
19
+ interface RadarSeries {
20
+ name: string
21
+ dataKey: string
22
+ color: string
23
+ }
24
+
25
+ export interface RadarChartProps extends MaterialComponet {
26
+ /** 静态数据(兼容旧版) */
27
+ data?: RadarDataPoint[]
28
+ /** 维度字段 */
29
+ dimensionKey?: string
30
+ /** 系列配置 */
31
+ series?: RadarSeries[]
32
+ /** 显示网格 */
33
+ showGrid?: boolean
34
+ /** 填充透明度 */
35
+ fillOpacity?: number
36
+ /** 发光效果 */
37
+ glowEffect?: boolean
38
+ /** 显示图例 */
39
+ showLegend?: boolean
40
+ /** 显示提示 */
41
+ showTooltip?: boolean
42
+ /** 点击事件 */
43
+ onClick?: (e: React.MouseEvent) => void
44
+ /** 双击事件 */
45
+ onDoubleClick?: (e: React.MouseEvent) => void
46
+ /** 鼠标进入 */
47
+ onMouseEnter?: (e: React.MouseEvent) => void
48
+ /** 鼠标离开 */
49
+ onMouseLeave?: (e: React.MouseEvent) => void
50
+ }
51
+
52
+ // 构建图表配置
53
+ const buildOption = (
54
+ data: RadarDataPoint[],
55
+ dimensionKey: string,
56
+ series: RadarSeries[],
57
+ options: {
58
+ showGrid: boolean
59
+ fillOpacity: number
60
+ glowEffect: boolean
61
+ showLegend: boolean
62
+ showTooltip: boolean
63
+ },
64
+ ): EChartsOption => {
65
+ const { showGrid, fillOpacity, glowEffect, showLegend, showTooltip } = options
66
+
67
+ // 提取维度名称
68
+ const indicators = data.map(item => ({
69
+ name: item[dimensionKey] as string,
70
+ max: 100,
71
+ }))
72
+
73
+ // 构建 series 数据
74
+ const seriesData = series.map(s => ({
75
+ name: s.name,
76
+ value: data.map(item => item[s.dataKey] as number),
77
+ itemStyle: {
78
+ color: s.color,
79
+ shadowColor: glowEffect ? s.color : 'transparent',
80
+ shadowBlur: glowEffect ? 10 : 0,
81
+ },
82
+ lineStyle: {
83
+ color: s.color,
84
+ width: 2,
85
+ shadowColor: glowEffect ? s.color : 'transparent',
86
+ shadowBlur: glowEffect ? 10 : 0,
87
+ },
88
+ areaStyle: {
89
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
90
+ {
91
+ offset: 0,
92
+ color: `${s.color}${Math.round(fillOpacity * 255)
93
+ .toString(16)
94
+ .padStart(2, '0')}`,
95
+ },
96
+ { offset: 1, color: `${s.color}10` },
97
+ ]),
98
+ },
99
+ }))
100
+
101
+ return {
102
+ backgroundColor: 'transparent',
103
+ tooltip: showTooltip
104
+ ? {
105
+ trigger: 'item',
106
+ backgroundColor: 'rgba(0, 20, 40, 0.9)',
107
+ borderColor: '#00d4ff',
108
+ borderWidth: 1,
109
+ textStyle: {
110
+ color: '#fff',
111
+ },
112
+ }
113
+ : undefined,
114
+ legend: showLegend
115
+ ? {
116
+ show: true,
117
+ bottom: 10,
118
+ textStyle: {
119
+ color: '#8899aa',
120
+ fontSize: 11,
121
+ },
122
+ }
123
+ : undefined,
124
+ radar: {
125
+ indicator: indicators,
126
+ shape: 'polygon',
127
+ splitNumber: 5,
128
+ axisName: {
129
+ color: '#8899aa',
130
+ fontSize: 11,
131
+ },
132
+ splitLine: {
133
+ show: showGrid,
134
+ lineStyle: {
135
+ color: '#1a3a5c',
136
+ opacity: 0.6,
137
+ },
138
+ },
139
+ splitArea: {
140
+ show: false,
141
+ },
142
+ axisLine: {
143
+ show: showGrid,
144
+ lineStyle: {
145
+ color: '#1a3a5c',
146
+ opacity: 0.6,
147
+ },
148
+ },
149
+ },
150
+ series: [
151
+ {
152
+ type: 'radar',
153
+ data: seriesData,
154
+ symbol: 'circle',
155
+ symbolSize: 6,
156
+ },
157
+ ],
158
+ }
159
+ }
160
+
161
+ export const RadarChart: React.FC<RadarChartProps> = ({
162
+ ref,
163
+ $data,
164
+ __dataSource,
165
+ data: staticData,
166
+ dimensionKey = 'dimension',
167
+ series = DEFAULT_SERIES,
168
+ showGrid = true,
169
+ fillOpacity = 0.3,
170
+ glowEffect = true,
171
+ showLegend = true,
172
+ showTooltip = true,
173
+ rotation = 0,
174
+ opacity = 100,
175
+ background = 'transparent',
176
+ style: externalStyle,
177
+ onClick,
178
+ onDoubleClick,
179
+ onMouseEnter,
180
+ onMouseLeave,
181
+ }) => {
182
+ const chartRef = useRef<HTMLDivElement>(null)
183
+ const chartInstance = useRef<echarts.ECharts | null>(null)
184
+
185
+ // 解析数据源
186
+ const dataSource = useDataSource($data, __dataSource)
187
+ const data = useMemo<RadarDataPoint[]>(() => {
188
+ if (dataSource.length > 0) {
189
+ return dataSource as RadarDataPoint[]
190
+ }
191
+ return staticData ?? DEFAULT_DATA
192
+ }, [dataSource, staticData])
193
+
194
+ useEffect(() => {
195
+ if (!chartRef.current) {
196
+ return
197
+ }
198
+
199
+ chartInstance.current = echarts.init(chartRef.current)
200
+
201
+ const option = buildOption(data, dimensionKey, series, {
202
+ showGrid,
203
+ fillOpacity,
204
+ glowEffect,
205
+ showLegend,
206
+ showTooltip,
207
+ })
208
+
209
+ chartInstance.current.setOption(option)
210
+
211
+ const resizeObserver = new ResizeObserver(() => {
212
+ chartInstance.current?.resize()
213
+ })
214
+ resizeObserver.observe(chartRef.current)
215
+
216
+ return () => {
217
+ resizeObserver.disconnect()
218
+ chartInstance.current?.dispose()
219
+ }
220
+ }, [data, dimensionKey, series, showGrid, fillOpacity, glowEffect, showLegend, showTooltip])
221
+
222
+ const containerStyle: CSSProperties = {
223
+ width: '100%',
224
+ height: '100%',
225
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
226
+ opacity: opacity / 100,
227
+ backgroundColor: background,
228
+ ...externalStyle,
229
+ }
230
+
231
+ return (
232
+ <div
233
+ className={styles.container}
234
+ onClick={onClick}
235
+ onDoubleClick={onDoubleClick}
236
+ onMouseEnter={onMouseEnter}
237
+ onMouseLeave={onMouseLeave}
238
+ ref={ref}
239
+ style={containerStyle}
240
+ >
241
+ <div className={styles.chart} ref={chartRef} />
242
+ </div>
243
+ )
244
+ }
245
+
246
+ export default RadarChart
package/src/meta.ts CHANGED
@@ -1,23 +1,23 @@
1
- import type { ComponentMetadata } from '@easy-editor/core'
2
- import { MaterialGroup } from '@easy-editor/materials-shared'
3
- import { COMPONENT_NAME, PACKAGE_NAME } from './constants'
4
- import { configure } from './configure'
5
- import { snippets } from './snippets'
6
- import pkg from '../package.json'
7
-
8
- const meta: ComponentMetadata = {
9
- componentName: COMPONENT_NAME,
10
- title: '雷达图',
11
- group: MaterialGroup.CHART,
12
- devMode: 'proCode',
13
- npm: {
14
- package: PACKAGE_NAME,
15
- version: pkg.version,
16
- globalName: COMPONENT_NAME,
17
- componentName: COMPONENT_NAME,
18
- },
19
- snippets,
20
- configure,
21
- }
22
-
23
- export { meta }
1
+ import type { ComponentMetadata } from '@easy-editor/core'
2
+ import { MaterialGroup } from '@easy-editor/materials-shared'
3
+ import { COMPONENT_NAME, PACKAGE_NAME } from './constants'
4
+ import { configure } from './configure'
5
+ import { snippets } from './snippets'
6
+ import pkg from '../package.json'
7
+
8
+ export const meta: ComponentMetadata = {
9
+ componentName: COMPONENT_NAME,
10
+ title: '雷达图',
11
+ group: MaterialGroup.CHART,
12
+ devMode: 'proCode',
13
+ npm: {
14
+ package: PACKAGE_NAME,
15
+ version: pkg.version,
16
+ globalName: COMPONENT_NAME,
17
+ componentName: COMPONENT_NAME,
18
+ },
19
+ snippets,
20
+ configure,
21
+ }
22
+
23
+ export default meta