@easy-editor/materials-dashboard-gauge-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.
Files changed (46) hide show
  1. package/.vite/echarts-external-plugin.ts +61 -0
  2. package/CHANGELOG.md +21 -7
  3. package/easypack.config.ts +19 -0
  4. package/package.json +4 -8
  5. package/src/component.tsx +88 -41
  6. package/src/configure.ts +140 -285
  7. package/src/index.tsx +7 -7
  8. package/src/meta.ts +3 -3
  9. package/src/snippets.ts +69 -55
  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 -28857
  14. package/dist/component.esm.js.map +0 -1
  15. package/dist/component.js +0 -28864
  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 -29174
  20. package/dist/index.cjs.map +0 -1
  21. package/dist/index.esm.js +0 -29171
  22. package/dist/index.esm.js.map +0 -1
  23. package/dist/index.js +0 -29178
  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 -319
  28. package/dist/meta.esm.js.map +0 -1
  29. package/dist/meta.js +0 -329
  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 -19
  34. package/dist/src/configure.d.ts +0 -7
  35. package/dist/src/constants.d.ts +0 -28
  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/dist/src/types.d.ts +0 -50
  40. package/dist/src/utils.d.ts +0 -28
  41. package/rollup.config.js +0 -212
  42. package/src/types.ts +0 -55
  43. package/src/utils.ts +0 -57
  44. package/tsconfig.build.json +0 -12
  45. package/tsconfig.test.json +0 -7
  46. 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,7 +1,21 @@
1
- # @easy-editor/materials-dashboard-gauge-chart
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - feat: new setters
1
+ # @easy-editor/materials-dashboard-gauge-chart
2
+
3
+ ## 0.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: component export error
8
+
9
+ ## 0.0.3
10
+
11
+ ### Patch Changes
12
+
13
+ - perf: configure & datasource
14
+ - Updated dependencies
15
+ - @easy-editor/materials-shared@0.0.1
16
+
17
+ ## 0.0.2
18
+
19
+ ### Patch Changes
20
+
21
+ - 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-gauge-chart",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Gauge Chart component for EasyEditor dashboard",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -47,20 +47,16 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "echarts": "^5.6.0",
50
- "@easy-editor/materials-shared": "0.0.0"
50
+ "@easy-editor/materials-shared": "0.0.1"
51
51
  },
52
52
  "scripts": {
53
- "dev": "vite",
53
+ "dev": "easypack dev",
54
54
  "dev:debug": "vite --port 5006",
55
55
  "format": "biome format --write .",
56
56
  "lint": "biome check .",
57
57
  "build": "npm-run-all -nl build:*",
58
58
  "build:clean": "rimraf dist/",
59
- "build:js": "rollup -c",
60
- "build:types": "pnpm types",
61
- "types": "npm-run-all -nl types:*",
62
- "types:src": "tsc --project tsconfig.build.json",
63
- "test-types": "tsc --project tsconfig.test.json"
59
+ "build:js": "easypack build"
64
60
  },
65
61
  "module": "dist/index.esm.js",
66
62
  "unpkg": "dist/index.min.js"
package/src/component.tsx CHANGED
@@ -1,51 +1,87 @@
1
- import { useEffect, useRef, type CSSProperties, type Ref } from 'react'
1
+ /**
2
+ * Gauge Chart Component
3
+ * 仪表盘组件 - 支持数据源绑定和事件交互
4
+ */
5
+
6
+ import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
2
7
  import * as echarts from 'echarts/core'
3
- import { GaugeChart } from 'echarts/charts'
8
+ import { GaugeChart as EChartsGaugeChart } from 'echarts/charts'
4
9
  import { TooltipComponent } 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_RANGES, type GaugeRange } from './constants'
8
14
  import styles from './component.module.css'
9
15
 
10
16
  // 按需注册 ECharts 组件
11
- echarts.use([GaugeChart, TooltipComponent, CanvasRenderer])
17
+ echarts.use([EChartsGaugeChart, TooltipComponent, CanvasRenderer])
12
18
 
13
- interface GaugeChartProps {
14
- ref?: Ref<HTMLDivElement>
15
- value?: number
19
+ export interface GaugeChartProps extends MaterialComponet {
20
+ /** 最小值 */
16
21
  min?: number
22
+ /** 最大值 */
17
23
  max?: number
24
+ /** 单位 */
18
25
  unit?: string
26
+ /** 显示刻度 */
19
27
  showScale?: boolean
28
+ /** 刻度数量 */
20
29
  divisions?: number
30
+ /** 显示刻度值 */
21
31
  showLabels?: boolean
32
+ /** 指针类型 */
22
33
  pointerType?: 'needle' | 'triangle' | 'rect'
34
+ /** 指针颜色 */
23
35
  pointerColor?: string
36
+ /** 颜色区间 */
24
37
  ranges?: GaugeRange[]
38
+ /** 发光效果 */
25
39
  glowEffect?: boolean
26
- style?: CSSProperties
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
27
48
  }
28
49
 
29
- const GaugeChartComponent = (props: GaugeChartProps) => {
30
- const {
31
- ref,
32
- value = 0,
33
- min = 0,
34
- max = 100,
35
- unit = '',
36
- showScale = true,
37
- divisions = 10,
38
- showLabels = true,
39
- pointerType = 'needle',
40
- pointerColor = '#00d4ff',
41
- ranges = DEFAULT_RANGES,
42
- glowEffect = true,
43
- style: externalStyle,
44
- } = props
45
-
50
+ export const GaugeChart: React.FC<GaugeChartProps> = ({
51
+ ref,
52
+ $data,
53
+ __dataSource,
54
+ min = 0,
55
+ max = 100,
56
+ unit = '',
57
+ showScale = true,
58
+ divisions = 10,
59
+ showLabels = true,
60
+ pointerType = 'needle',
61
+ pointerColor = '#00d4ff',
62
+ ranges = DEFAULT_RANGES,
63
+ glowEffect = true,
64
+ rotation = 0,
65
+ opacity = 100,
66
+ background = 'transparent',
67
+ style: externalStyle,
68
+ onClick,
69
+ onDoubleClick,
70
+ onMouseEnter,
71
+ onMouseLeave,
72
+ }) => {
46
73
  const chartRef = useRef<HTMLDivElement>(null)
47
74
  const chartInstance = useRef<echarts.ECharts | null>(null)
48
75
 
76
+ // 解析数据源(单值)
77
+ const dataSource = useDataSource($data, __dataSource)
78
+ const value = useMemo<number>(() => {
79
+ if (dataSource.length > 0 && dataSource[0]?.value !== undefined) {
80
+ return Number(dataSource[0].value)
81
+ }
82
+ return 0
83
+ }, [dataSource])
84
+
49
85
  useEffect(() => {
50
86
  if (!chartRef.current) {
51
87
  return
@@ -73,14 +109,14 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
73
109
  max,
74
110
  startAngle: 180,
75
111
  endAngle: 0,
76
- center: ['50%', '70%'],
77
- radius: '90%',
112
+ center: ['50%', '80%'],
113
+ radius: '72%',
78
114
  progress: {
79
115
  show: false,
80
116
  },
81
117
  axisLine: {
82
118
  lineStyle: {
83
- width: 20,
119
+ width: 16,
84
120
  color: axisLineColors,
85
121
  shadowColor: glowEffect ? 'rgba(0, 212, 255, 0.3)' : 'transparent',
86
122
  shadowBlur: glowEffect ? 10 : 0,
@@ -88,8 +124,8 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
88
124
  },
89
125
  axisTick: {
90
126
  show: showScale,
91
- distance: -25,
92
- length: 6,
127
+ distance: -20,
128
+ length: 4,
93
129
  lineStyle: {
94
130
  color: '#8899aa',
95
131
  width: 1,
@@ -98,8 +134,8 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
98
134
  },
99
135
  splitLine: {
100
136
  show: showScale,
101
- distance: -30,
102
- length: 12,
137
+ distance: -24,
138
+ length: 8,
103
139
  lineStyle: {
104
140
  color: '#8899aa',
105
141
  width: 2,
@@ -107,13 +143,13 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
107
143
  },
108
144
  axisLabel: {
109
145
  show: showLabels,
110
- distance: -40,
146
+ distance: -32,
111
147
  color: '#8899aa',
112
- fontSize: 10,
148
+ fontSize: 9,
113
149
  },
114
150
  pointer: {
115
151
  show: true,
116
- length: '60%',
152
+ length: '55%',
117
153
  width: pointerWidth,
118
154
  itemStyle: {
119
155
  color: pointerColor,
@@ -123,7 +159,7 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
123
159
  },
124
160
  anchor: {
125
161
  show: true,
126
- size: 12,
162
+ size: 10,
127
163
  itemStyle: {
128
164
  color: pointerColor,
129
165
  shadowColor: glowEffect ? pointerColor : 'transparent',
@@ -132,14 +168,14 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
132
168
  },
133
169
  title: {
134
170
  show: true,
135
- offsetCenter: [0, '30%'],
171
+ offsetCenter: [0, '20%'],
136
172
  color: '#8899aa',
137
- fontSize: 12,
173
+ fontSize: 11,
138
174
  },
139
175
  detail: {
140
176
  valueAnimation: true,
141
- offsetCenter: [0, '50%'],
142
- fontSize: 28,
177
+ offsetCenter: [0, '40%'],
178
+ fontSize: 22,
143
179
  fontWeight: 'bold',
144
180
  color: '#fff',
145
181
  formatter: (val: number) => `${val}${unit}`,
@@ -167,14 +203,25 @@ const GaugeChartComponent = (props: GaugeChartProps) => {
167
203
  const containerStyle: CSSProperties = {
168
204
  width: '100%',
169
205
  height: '100%',
206
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
207
+ opacity: opacity / 100,
208
+ backgroundColor: background,
170
209
  ...externalStyle,
171
210
  }
172
211
 
173
212
  return (
174
- <div className={styles.container} ref={ref} style={containerStyle}>
213
+ <div
214
+ className={styles.container}
215
+ onClick={onClick}
216
+ onDoubleClick={onDoubleClick}
217
+ onMouseEnter={onMouseEnter}
218
+ onMouseLeave={onMouseLeave}
219
+ ref={ref}
220
+ style={containerStyle}
221
+ >
175
222
  <div className={styles.chart} ref={chartRef} />
176
223
  </div>
177
224
  )
178
225
  }
179
226
 
180
- export default GaugeChartComponent
227
+ export default GaugeChart