@easy-editor/materials-dashboard-line-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 +73 -26
  6. package/src/configure.ts +170 -349
  7. package/src/index.tsx +7 -7
  8. package/src/meta.ts +3 -3
  9. package/src/snippets.ts +101 -51
  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 -35200
  14. package/dist/component.esm.js.map +0 -1
  15. package/dist/component.js +0 -35207
  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 -35572
  20. package/dist/index.cjs.map +0 -1
  21. package/dist/index.esm.js +0 -35569
  22. package/dist/index.esm.js.map +0 -1
  23. package/dist/index.js +0 -35576
  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 -403
  28. package/dist/meta.esm.js.map +0 -1
  29. package/dist/meta.js +0 -413
  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 -27
  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-line-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-line-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-line-chart",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
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.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 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": "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,29 +1,50 @@
1
- import { useEffect, useRef, type CSSProperties, type Ref } from 'react'
1
+ /**
2
+ * Line Chart Component
3
+ * 折线图组件 - 支持数据源绑定和事件交互
4
+ */
5
+
6
+ import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
2
7
  import * as echarts from 'echarts/core'
3
- import { LineChart } from 'echarts/charts'
8
+ import { LineChart as EChartsLineChart } from 'echarts/charts'
4
9
  import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
5
10
  import { CanvasRenderer } from 'echarts/renderers'
6
11
  import type { SeriesOption } from 'echarts'
12
+ import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
7
13
  import { DEFAULT_COLORS, DEFAULT_DATA, type DataPoint } from './constants'
8
14
  import styles from './component.module.css'
9
15
 
10
16
  // 按需注册 ECharts 组件
11
- echarts.use([LineChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
17
+ echarts.use([EChartsLineChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
12
18
 
13
- interface LineChartProps {
14
- ref?: Ref<HTMLDivElement>
15
- data?: DataPoint[]
19
+ export interface LineChartProps extends MaterialComponet {
20
+ /** X轴字段 */
16
21
  xField?: string
22
+ /** Y轴字段列表 */
17
23
  yFields?: string[]
24
+ /** 颜色列表 */
18
25
  colors?: string[]
26
+ /** 显示网格 */
19
27
  showGrid?: boolean
28
+ /** 显示图例 */
20
29
  showLegend?: boolean
30
+ /** 显示提示 */
21
31
  showTooltip?: boolean
32
+ /** 发光效果 */
22
33
  glowEffect?: boolean
34
+ /** 线条宽度 */
23
35
  strokeWidth?: number
36
+ /** 区域填充 */
24
37
  areaFill?: boolean
38
+ /** 平滑曲线 */
25
39
  smooth?: 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
50
  // 构建 series 配置
@@ -161,26 +182,41 @@ const buildOption = (
161
182
  }
162
183
  }
163
184
 
164
- const LineChartComponent = (props: LineChartProps) => {
165
- const {
166
- ref,
167
- data = DEFAULT_DATA,
168
- xField = 'name',
169
- yFields = ['value1', 'value2'],
170
- colors = DEFAULT_COLORS,
171
- showGrid = true,
172
- showLegend = true,
173
- showTooltip = true,
174
- glowEffect = true,
175
- strokeWidth = 2,
176
- areaFill = false,
177
- smooth = true,
178
- style: externalStyle,
179
- } = props
180
-
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
+ }) => {
181
208
  const chartRef = useRef<HTMLDivElement>(null)
182
209
  const chartInstance = useRef<echarts.ECharts | null>(null)
183
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
+
184
220
  useEffect(() => {
185
221
  if (!chartRef.current) {
186
222
  return
@@ -219,14 +255,25 @@ const LineChartComponent = (props: LineChartProps) => {
219
255
  const containerStyle: CSSProperties = {
220
256
  width: '100%',
221
257
  height: '100%',
258
+ transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
259
+ opacity: opacity / 100,
260
+ backgroundColor: background,
222
261
  ...externalStyle,
223
262
  }
224
263
 
225
264
  return (
226
- <div className={styles.container} ref={ref} style={containerStyle}>
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
+ >
227
274
  <div className={styles.chart} ref={chartRef} />
228
275
  </div>
229
276
  )
230
277
  }
231
278
 
232
- export default LineChartComponent
279
+ export default LineChart