@easy-editor/materials-dashboard-radar-chart 0.0.3 → 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.
Files changed (42) hide show
  1. package/.vite/echarts-external-plugin.ts +61 -0
  2. package/CHANGELOG.md +27 -13
  3. package/easypack.config.ts +19 -0
  4. package/package.json +4 -8
  5. package/src/component.tsx +69 -22
  6. package/src/configure.ts +135 -247
  7. package/src/index.tsx +7 -7
  8. package/src/meta.ts +3 -3
  9. package/src/snippets.ts +86 -57
  10. package/tsconfig.json +20 -9
  11. package/.vite/plugins/vite-plugin-external-deps.ts +0 -224
  12. package/.vite/plugins/vite-plugin-material-dev.ts +0 -218
  13. package/dist/component.esm.js +0 -31510
  14. package/dist/component.esm.js.map +0 -1
  15. package/dist/component.js +0 -31517
  16. package/dist/component.js.map +0 -1
  17. package/dist/component.min.js +0 -24
  18. package/dist/component.min.js.map +0 -1
  19. package/dist/index.cjs +0 -31811
  20. package/dist/index.cjs.map +0 -1
  21. package/dist/index.esm.js +0 -31808
  22. package/dist/index.esm.js.map +0 -1
  23. package/dist/index.js +0 -31815
  24. package/dist/index.js.map +0 -1
  25. package/dist/index.min.js +0 -24
  26. package/dist/index.min.js.map +0 -1
  27. package/dist/meta.esm.js +0 -333
  28. package/dist/meta.esm.js.map +0 -1
  29. package/dist/meta.js +0 -343
  30. package/dist/meta.js.map +0 -1
  31. package/dist/meta.min.js +0 -2
  32. package/dist/meta.min.js.map +0 -1
  33. package/dist/src/component.d.ts +0 -21
  34. package/dist/src/configure.d.ts +0 -7
  35. package/dist/src/constants.d.ts +0 -39
  36. package/dist/src/index.d.ts +0 -6
  37. package/dist/src/meta.d.ts +0 -3
  38. package/dist/src/snippets.d.ts +0 -3
  39. package/rollup.config.js +0 -212
  40. package/tsconfig.build.json +0 -12
  41. package/tsconfig.test.json +0 -7
  42. package/vite.config.ts +0 -54
@@ -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,13 +1,27 @@
1
- # @easy-editor/materials-dashboard-radar-chart
2
-
3
- ## 0.0.3
4
-
5
- ### Patch Changes
6
-
7
- - fix: build error
8
-
9
- ## 0.0.2
10
-
11
- ### Patch Changes
12
-
13
- - 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
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @easy-editor/easypack configuration
3
+ * @type {import('@easy-editor/easypack').EasypackConfig}
4
+ */
5
+ import { ECHARTS_EXTERNALS, ECHARTS_GLOBALS, echartsExternalPlugin } from './.vite/echarts-external-plugin'
6
+
7
+ export default {
8
+ preset: 'material',
9
+ dev: {
10
+ port: 5001,
11
+ },
12
+ rollup: {
13
+ external: ECHARTS_EXTERNALS,
14
+ output: {
15
+ globals: ECHARTS_GLOBALS,
16
+ },
17
+ },
18
+ vitePlugins: [echartsExternalPlugin()],
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-editor/materials-dashboard-radar-chart",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Radar 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.0"
51
+ "@easy-editor/materials-shared": "0.0.1"
52
52
  },
53
53
  "scripts": {
54
- "dev": "vite",
54
+ "dev": "easypack dev",
55
55
  "dev:debug": "vite --port 5005",
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": "rollup -c",
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,14 +1,20 @@
1
- import { useEffect, useRef, type CSSProperties, type Ref } from 'react'
1
+ /**
2
+ * Radar Chart Component
3
+ * 雷达图组件 - 支持数据源绑定和事件交互
4
+ */
5
+
6
+ import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
2
7
  import * as echarts from 'echarts/core'
3
- import { RadarChart } from 'echarts/charts'
8
+ import { RadarChart as EChartsRadarChart } from 'echarts/charts'
4
9
  import { TooltipComponent, LegendComponent } from 'echarts/components'
5
10
  import { CanvasRenderer } from 'echarts/renderers'
6
11
  import type { EChartsOption } from 'echarts'
12
+ import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
7
13
  import { DEFAULT_DATA, DEFAULT_SERIES, type RadarDataPoint } from './constants'
8
14
  import styles from './component.module.css'
9
15
 
10
16
  // 按需注册 ECharts 组件
11
- echarts.use([RadarChart, TooltipComponent, LegendComponent, CanvasRenderer])
17
+ echarts.use([EChartsRadarChart, TooltipComponent, LegendComponent, CanvasRenderer])
12
18
 
13
19
  interface RadarSeries {
14
20
  name: string
@@ -16,17 +22,31 @@ interface RadarSeries {
16
22
  color: string
17
23
  }
18
24
 
19
- interface RadarChartProps {
20
- ref?: Ref<HTMLDivElement>
25
+ export interface RadarChartProps extends MaterialComponet {
26
+ /** 静态数据(兼容旧版) */
21
27
  data?: RadarDataPoint[]
28
+ /** 维度字段 */
22
29
  dimensionKey?: string
30
+ /** 系列配置 */
23
31
  series?: RadarSeries[]
32
+ /** 显示网格 */
24
33
  showGrid?: boolean
34
+ /** 填充透明度 */
25
35
  fillOpacity?: number
36
+ /** 发光效果 */
26
37
  glowEffect?: boolean
38
+ /** 显示图例 */
27
39
  showLegend?: boolean
40
+ /** 显示提示 */
28
41
  showTooltip?: boolean
29
- style?: CSSProperties
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
30
50
  }
31
51
 
32
52
  // 构建图表配置
@@ -138,23 +158,39 @@ const buildOption = (
138
158
  }
139
159
  }
140
160
 
141
- const RadarChartComponent = (props: RadarChartProps) => {
142
- const {
143
- ref,
144
- data = DEFAULT_DATA,
145
- dimensionKey = 'dimension',
146
- series = DEFAULT_SERIES,
147
- showGrid = true,
148
- fillOpacity = 0.3,
149
- glowEffect = true,
150
- showLegend = true,
151
- showTooltip = true,
152
- style: externalStyle,
153
- } = props
154
-
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
+ }) => {
155
182
  const chartRef = useRef<HTMLDivElement>(null)
156
183
  const chartInstance = useRef<echarts.ECharts | null>(null)
157
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
+
158
194
  useEffect(() => {
159
195
  if (!chartRef.current) {
160
196
  return
@@ -186,14 +222,25 @@ const RadarChartComponent = (props: RadarChartProps) => {
186
222
  const containerStyle: CSSProperties = {
187
223
  width: '100%',
188
224
  height: '100%',
225
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
226
+ opacity: opacity / 100,
227
+ backgroundColor: background,
189
228
  ...externalStyle,
190
229
  }
191
230
 
192
231
  return (
193
- <div className={styles.container} ref={ref} style={containerStyle}>
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
+ >
194
241
  <div className={styles.chart} ref={chartRef} />
195
242
  </div>
196
243
  )
197
244
  }
198
245
 
199
- export default RadarChartComponent
246
+ export default RadarChart
package/src/configure.ts CHANGED
@@ -1,247 +1,135 @@
1
- /**
2
- * Radar Chart Configure
3
- * 雷达图组件配置
4
- */
5
-
6
- import type { Configure } from '@easy-editor/core'
7
-
8
- const configure: Configure = {
9
- props: [
10
- {
11
- type: 'group',
12
- title: '属性',
13
- setter: 'TabSetter',
14
- items: [
15
- {
16
- type: 'group',
17
- key: 'config',
18
- title: '配置',
19
- setter: {
20
- componentName: 'CollapseSetter',
21
- props: {
22
- icon: false,
23
- },
24
- },
25
- items: [
26
- // 基础配置
27
- {
28
- name: 'id',
29
- title: 'ID',
30
- setter: 'NodeIdSetter',
31
- extraProps: {
32
- // @ts-expect-error label is not a valid extra prop
33
- label: false,
34
- },
35
- },
36
- {
37
- name: 'title',
38
- title: '标题',
39
- setter: 'StringSetter',
40
- extraProps: {
41
- getValue(target) {
42
- return target.getExtraPropValue('title')
43
- },
44
- setValue(target, value) {
45
- target.setExtraPropValue('title', value)
46
- },
47
- },
48
- },
49
- {
50
- type: 'group',
51
- title: '基础属性',
52
- setter: {
53
- componentName: 'CollapseSetter',
54
- props: {
55
- icon: false,
56
- },
57
- },
58
- items: [
59
- {
60
- name: 'rect',
61
- title: '位置尺寸',
62
- setter: 'RectSetter',
63
- extraProps: {
64
- getValue(target) {
65
- return target.getExtraPropValue('$dashboard.rect')
66
- },
67
- setValue(target, value) {
68
- target.setExtraPropValue('$dashboard.rect', value)
69
- },
70
- },
71
- },
72
- ],
73
- },
74
- // 组件配置
75
- {
76
- type: 'group',
77
- title: '数据',
78
- setter: {
79
- componentName: 'CollapseSetter',
80
- props: {
81
- icon: false,
82
- },
83
- },
84
- items: [
85
- {
86
- name: 'data',
87
- title: '数据',
88
- setter: 'JsonSetter',
89
- },
90
- {
91
- name: 'dimensionKey',
92
- title: '维度字段',
93
- setter: 'StringSetter',
94
- extraProps: {
95
- defaultValue: 'dimension',
96
- },
97
- },
98
- {
99
- name: 'series',
100
- title: '系列',
101
- setter: 'JsonSetter',
102
- },
103
- ],
104
- },
105
- {
106
- type: 'group',
107
- title: '数值格式',
108
- setter: {
109
- componentName: 'CollapseSetter',
110
- props: {
111
- icon: false,
112
- },
113
- },
114
- items: [
115
- {
116
- name: 'valuePrefix',
117
- title: '前缀',
118
- setter: 'StringSetter',
119
- },
120
- {
121
- name: 'valueSuffix',
122
- title: '后缀',
123
- setter: 'StringSetter',
124
- },
125
- {
126
- name: 'valueDecimals',
127
- title: '小数位数',
128
- setter: {
129
- componentName: 'NumberSetter',
130
- props: {
131
- suffix: '',
132
- },
133
- },
134
- extraProps: {
135
- defaultValue: 0,
136
- },
137
- },
138
- ],
139
- },
140
- {
141
- type: 'group',
142
- title: '样式',
143
- setter: {
144
- componentName: 'CollapseSetter',
145
- props: {
146
- icon: false,
147
- },
148
- },
149
- items: [
150
- {
151
- name: 'showGrid',
152
- title: '显示网格',
153
- setter: 'SwitchSetter',
154
- extraProps: {
155
- defaultValue: true,
156
- },
157
- },
158
- {
159
- name: 'fillOpacity',
160
- title: '填充透明度',
161
- setter: {
162
- componentName: 'SliderSetter',
163
- props: {
164
- min: 0,
165
- max: 1,
166
- step: 0.1,
167
- },
168
- },
169
- extraProps: {
170
- defaultValue: 0.3,
171
- },
172
- },
173
- {
174
- name: 'showLegend',
175
- title: '显示图例',
176
- setter: 'SwitchSetter',
177
- extraProps: {
178
- defaultValue: true,
179
- },
180
- },
181
- {
182
- name: 'legendPosition',
183
- title: '图例位置',
184
- setter: {
185
- componentName: 'SelectSetter',
186
- props: {
187
- options: [
188
- { label: '顶部', value: 'top' },
189
- { label: '底部', value: 'bottom' },
190
- { label: '左侧', value: 'left' },
191
- { label: '右侧', value: 'right' },
192
- ],
193
- },
194
- },
195
- extraProps: {
196
- defaultValue: 'bottom',
197
- },
198
- },
199
- {
200
- name: 'glowEffect',
201
- title: '发光效果',
202
- setter: 'SwitchSetter',
203
- extraProps: {
204
- defaultValue: true,
205
- },
206
- },
207
- ],
208
- },
209
- ],
210
- },
211
- {
212
- type: 'group',
213
- key: 'data',
214
- title: '数据',
215
- items: [
216
- {
217
- name: 'dataBinding',
218
- title: '数据绑定',
219
- setter: 'DataBindingSetter',
220
- },
221
- ],
222
- },
223
- {
224
- type: 'group',
225
- key: 'advanced',
226
- title: '高级',
227
- items: [
228
- {
229
- name: 'condition',
230
- title: '显隐控制',
231
- setter: 'SwitchSetter',
232
- extraProps: {
233
- defaultValue: true,
234
- supportVariable: true,
235
- },
236
- },
237
- ],
238
- },
239
- ],
240
- },
241
- ],
242
- component: {},
243
- supports: {},
244
- advanced: {},
245
- }
246
-
247
- export default configure
1
+ /**
2
+ * Radar Chart Configure
3
+ * 雷达图组件配置
4
+ */
5
+
6
+ import type { FieldConfig } from '@easy-editor/core'
7
+ import { createCollapseGroup, createDataConfigGroup, createStandardConfigure } from '@easy-editor/materials-shared'
8
+
9
+ /** 组件配置 */
10
+ const componentConfigGroup: FieldConfig = createCollapseGroup(
11
+ '组件配置',
12
+ [
13
+ {
14
+ type: 'group',
15
+ title: '组件配置',
16
+ setter: 'SubTabSetter',
17
+ items: [
18
+ // 数据 Tab
19
+ {
20
+ type: 'group',
21
+ key: 'chartData',
22
+ title: '数据',
23
+ items: [
24
+ {
25
+ name: 'dimensionKey',
26
+ title: '维度字段',
27
+ setter: 'StringSetter',
28
+ extraProps: {
29
+ defaultValue: 'dimension',
30
+ },
31
+ },
32
+ {
33
+ name: 'series',
34
+ title: '系列配置',
35
+ setter: 'JsonSetter',
36
+ },
37
+ ],
38
+ },
39
+ // 样式 Tab
40
+ {
41
+ type: 'group',
42
+ key: 'style',
43
+ title: '样式',
44
+ items: [
45
+ {
46
+ name: 'showGrid',
47
+ title: '显示网格',
48
+ setter: 'SwitchSetter',
49
+ extraProps: {
50
+ defaultValue: true,
51
+ },
52
+ },
53
+ {
54
+ name: 'fillOpacity',
55
+ title: '填充透明度',
56
+ setter: {
57
+ componentName: 'SliderSetter',
58
+ props: {
59
+ min: 0,
60
+ max: 1,
61
+ step: 0.1,
62
+ },
63
+ },
64
+ extraProps: {
65
+ defaultValue: 0.3,
66
+ },
67
+ },
68
+ {
69
+ name: 'glowEffect',
70
+ title: '发光效果',
71
+ setter: 'SwitchSetter',
72
+ extraProps: {
73
+ defaultValue: true,
74
+ },
75
+ },
76
+ ],
77
+ },
78
+ // 图例 Tab
79
+ {
80
+ type: 'group',
81
+ key: 'legend',
82
+ title: '图例',
83
+ items: [
84
+ {
85
+ name: 'showLegend',
86
+ title: '显示图例',
87
+ setter: 'SwitchSetter',
88
+ extraProps: {
89
+ defaultValue: true,
90
+ },
91
+ },
92
+ {
93
+ name: 'legendPosition',
94
+ title: '图例位置',
95
+ setter: {
96
+ componentName: 'SelectSetter',
97
+ props: {
98
+ options: [
99
+ { label: '顶部', value: 'top' },
100
+ { label: '底部', value: 'bottom' },
101
+ { label: '左侧', value: 'left' },
102
+ { label: '右侧', value: 'right' },
103
+ ],
104
+ },
105
+ },
106
+ extraProps: {
107
+ defaultValue: 'bottom',
108
+ },
109
+ },
110
+ {
111
+ name: 'showTooltip',
112
+ title: '显示提示',
113
+ setter: 'SwitchSetter',
114
+ extraProps: {
115
+ defaultValue: true,
116
+ },
117
+ },
118
+ ],
119
+ },
120
+ ],
121
+ },
122
+ ],
123
+ {
124
+ padding: '6px 16px 12px',
125
+ },
126
+ )
127
+
128
+ /** 数据配置 */
129
+ const dataConfigGroup: FieldConfig = createDataConfigGroup([
130
+ { name: 'dimension', label: 'dimension', type: 'string', required: true, description: '维度名称' },
131
+ { name: 'value1', label: 'value1', type: 'number', required: true, description: '数值1' },
132
+ { name: 'value2', label: 'value2', type: 'number', required: false, description: '数值2' },
133
+ ])
134
+
135
+ export const configure = createStandardConfigure(componentConfigGroup, dataConfigGroup)