@easy-editor/materials-dashboard-bar-chart 0.0.2

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 (44) hide show
  1. package/.vite/plugins/vite-plugin-external-deps.ts +224 -0
  2. package/.vite/plugins/vite-plugin-material-dev.ts +218 -0
  3. package/CHANGELOG.md +7 -0
  4. package/LICENSE +9 -0
  5. package/dist/component.esm.js +34452 -0
  6. package/dist/component.esm.js.map +1 -0
  7. package/dist/component.js +34459 -0
  8. package/dist/component.js.map +1 -0
  9. package/dist/component.min.js +24 -0
  10. package/dist/component.min.js.map +1 -0
  11. package/dist/index.cjs +34870 -0
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/index.esm.js +34867 -0
  14. package/dist/index.esm.js.map +1 -0
  15. package/dist/index.js +34874 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/index.min.js +24 -0
  18. package/dist/index.min.js.map +1 -0
  19. package/dist/meta.esm.js +441 -0
  20. package/dist/meta.esm.js.map +1 -0
  21. package/dist/meta.js +451 -0
  22. package/dist/meta.js.map +1 -0
  23. package/dist/meta.min.js +2 -0
  24. package/dist/meta.min.js.map +1 -0
  25. package/dist/src/component.d.ts +21 -0
  26. package/dist/src/configure.d.ts +7 -0
  27. package/dist/src/constants.d.ts +27 -0
  28. package/dist/src/index.d.ts +6 -0
  29. package/dist/src/meta.d.ts +3 -0
  30. package/dist/src/snippets.d.ts +3 -0
  31. package/package.json +68 -0
  32. package/rollup.config.js +212 -0
  33. package/src/component.module.css +16 -0
  34. package/src/component.tsx +260 -0
  35. package/src/configure.ts +365 -0
  36. package/src/constants.ts +38 -0
  37. package/src/index.tsx +7 -0
  38. package/src/meta.ts +23 -0
  39. package/src/snippets.ts +79 -0
  40. package/src/type.d.ts +8 -0
  41. package/tsconfig.build.json +12 -0
  42. package/tsconfig.json +9 -0
  43. package/tsconfig.test.json +7 -0
  44. package/vite.config.ts +54 -0
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@easy-editor/materials-dashboard-bar-chart",
3
+ "version": "0.0.2",
4
+ "description": "Bar Chart component for EasyEditor dashboard",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.esm.js",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "publishConfig": {
16
+ "access": "public",
17
+ "jsdelivr": "dist/index.min.js",
18
+ "registry": "https://registry.npmjs.org/"
19
+ },
20
+ "homepage": "https://github.com/Easy-Editor/EasyMaterials",
21
+ "license": "MIT",
22
+ "author": "JinSo <kimjinso@qq.com>",
23
+ "keywords": [
24
+ "@easy-editor",
25
+ "easyeditor",
26
+ "low-code",
27
+ "dashboard",
28
+ "bar-chart",
29
+ "chart",
30
+ "echarts",
31
+ "component",
32
+ "react"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/Easy-Editor/EasyMaterials",
37
+ "directory": "packages/dashboard/chart/bar-chart"
38
+ },
39
+ "bugs": {
40
+ "url": "https://github.com/Easy-Editor/EasyMaterials/issues"
41
+ },
42
+ "peerDependencies": {
43
+ "@easy-editor/core": "*",
44
+ "react": "^18 || ^19",
45
+ "react-dom": "^18 || ^19",
46
+ "@types/react": "^18 || ^19",
47
+ "@types/react-dom": "^18 || ^19"
48
+ },
49
+ "dependencies": {
50
+ "echarts": "^5.6.0",
51
+ "@easy-editor/materials-shared": "0.0.0"
52
+ },
53
+ "scripts": {
54
+ "dev": "vite",
55
+ "dev:debug": "vite --port 5003",
56
+ "format": "biome format --write .",
57
+ "lint": "biome check .",
58
+ "build": "npm-run-all -nl build:*",
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"
65
+ },
66
+ "module": "dist/index.esm.js",
67
+ "unpkg": "dist/index.min.js"
68
+ }
@@ -0,0 +1,212 @@
1
+ import babel from '@rollup/plugin-babel'
2
+ import commonjs from '@rollup/plugin-commonjs'
3
+ import nodeResolve from '@rollup/plugin-node-resolve'
4
+ import json from '@rollup/plugin-json'
5
+ import { terser } from 'rollup-plugin-terser'
6
+ import cleanup from 'rollup-plugin-cleanup'
7
+ import postcss from 'rollup-plugin-postcss'
8
+ import pkg from './package.json' with { type: 'json' }
9
+
10
+ const GLOBAL_NAME = 'EasyEditorMaterialsTechBarChart'
11
+
12
+ // 外部依赖(不打包进组件)
13
+ const external = ['react', 'react-dom', 'react/jsx-runtime', '@easy-editor/core']
14
+
15
+ const globals = {
16
+ react: 'React',
17
+ 'react-dom': 'ReactDOM',
18
+ 'react/jsx-runtime': 'jsxRuntime',
19
+ '@easy-editor/core': 'EasyEditorCore',
20
+ }
21
+
22
+ const plugins = [
23
+ nodeResolve({
24
+ extensions: ['.js', '.ts', '.jsx', '.tsx'],
25
+ }),
26
+ commonjs(),
27
+ json(),
28
+ postcss({
29
+ modules: {
30
+ generateScopedName: '[name]__[local]___[hash:base64:5]',
31
+ },
32
+ autoModules: true,
33
+ minimize: true,
34
+ inject: true,
35
+ }),
36
+ babel({
37
+ extensions: ['.js', '.ts', '.jsx', '.tsx'],
38
+ exclude: 'node_modules/**',
39
+ babelrc: false,
40
+ babelHelpers: 'bundled',
41
+ presets: [
42
+ ['@babel/preset-react', { runtime: 'automatic' }],
43
+ [
44
+ '@babel/preset-typescript',
45
+ {
46
+ allowDeclareFields: true,
47
+ },
48
+ ],
49
+ ],
50
+ }),
51
+ cleanup({
52
+ comments: ['some', /PURE/],
53
+ extensions: ['.js', '.ts'],
54
+ }),
55
+ ]
56
+
57
+ export default [
58
+ /* ---------------------------------- 元数据构建 --------------------------------- */
59
+ {
60
+ input: 'src/meta.ts',
61
+ output: [
62
+ {
63
+ file: 'dist/meta.esm.js',
64
+ format: 'esm',
65
+ sourcemap: true,
66
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (meta, esm) */`,
67
+ exports: 'named',
68
+ },
69
+ ],
70
+ plugins,
71
+ external,
72
+ },
73
+ {
74
+ input: 'src/meta.ts',
75
+ output: [
76
+ {
77
+ file: 'dist/meta.js',
78
+ format: 'umd',
79
+ name: `${GLOBAL_NAME}Meta`,
80
+ globals,
81
+ sourcemap: true,
82
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (meta) */`,
83
+ exports: 'named',
84
+ },
85
+ ],
86
+ plugins,
87
+ external,
88
+ },
89
+ {
90
+ input: 'src/meta.ts',
91
+ output: [
92
+ {
93
+ file: 'dist/meta.min.js',
94
+ format: 'umd',
95
+ name: `${GLOBAL_NAME}Meta`,
96
+ globals,
97
+ sourcemap: true,
98
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (meta, minified) */`,
99
+ exports: 'named',
100
+ },
101
+ ],
102
+ plugins: [...plugins, terser()],
103
+ external,
104
+ },
105
+
106
+ /* ---------------------------------- 组件构建 ---------------------------------- */
107
+ {
108
+ input: 'src/component.tsx',
109
+ output: [
110
+ {
111
+ file: 'dist/component.esm.js',
112
+ format: 'esm',
113
+ sourcemap: true,
114
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (component, esm) */`,
115
+ exports: 'named',
116
+ },
117
+ ],
118
+ plugins,
119
+ external,
120
+ },
121
+ {
122
+ input: 'src/component.tsx',
123
+ output: [
124
+ {
125
+ file: 'dist/component.js',
126
+ format: 'umd',
127
+ name: `${GLOBAL_NAME}Component`,
128
+ globals,
129
+ sourcemap: true,
130
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (component) */`,
131
+ exports: 'named',
132
+ },
133
+ ],
134
+ plugins,
135
+ external,
136
+ },
137
+ {
138
+ input: 'src/component.tsx',
139
+ output: [
140
+ {
141
+ file: 'dist/component.min.js',
142
+ format: 'umd',
143
+ name: `${GLOBAL_NAME}Component`,
144
+ globals,
145
+ sourcemap: true,
146
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (component, minified) */`,
147
+ exports: 'named',
148
+ },
149
+ ],
150
+ plugins: [...plugins, terser()],
151
+ external,
152
+ },
153
+
154
+ /* ---------------------------------- 完整构建 ---------------------------------- */
155
+ {
156
+ input: 'src/index.tsx',
157
+ output: [
158
+ {
159
+ file: 'dist/index.js',
160
+ format: 'umd',
161
+ name: GLOBAL_NAME,
162
+ globals,
163
+ sourcemap: true,
164
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} */`,
165
+ exports: 'named',
166
+ },
167
+ ],
168
+ plugins,
169
+ external,
170
+ },
171
+ {
172
+ input: 'src/index.tsx',
173
+ output: [
174
+ {
175
+ file: 'dist/index.esm.js',
176
+ format: 'esm',
177
+ sourcemap: true,
178
+ },
179
+ ],
180
+ plugins,
181
+ external,
182
+ },
183
+ {
184
+ input: 'src/index.tsx',
185
+ output: [
186
+ {
187
+ file: 'dist/index.cjs',
188
+ format: 'cjs',
189
+ sourcemap: true,
190
+ exports: 'named',
191
+ },
192
+ ],
193
+ plugins,
194
+ external,
195
+ },
196
+ {
197
+ input: 'src/index.tsx',
198
+ output: [
199
+ {
200
+ file: 'dist/index.min.js',
201
+ format: 'umd',
202
+ name: GLOBAL_NAME,
203
+ globals,
204
+ sourcemap: true,
205
+ banner: `/* @easy-editor/materials-dashboard-tech-bar-chart v${pkg.version} (minified) */`,
206
+ exports: 'named',
207
+ },
208
+ ],
209
+ plugins: [...plugins, terser()],
210
+ external,
211
+ },
212
+ ]
@@ -0,0 +1,16 @@
1
+ .container {
2
+ width: 100%;
3
+ height: 100%;
4
+ background: linear-gradient(
5
+ 180deg,
6
+ rgba(0, 20, 40, 0.9) 0%,
7
+ rgba(0, 10, 20, 0.95) 100%
8
+ );
9
+ border-radius: 8px;
10
+ overflow: hidden;
11
+ }
12
+
13
+ .chart {
14
+ width: 100%;
15
+ height: 100%;
16
+ }
@@ -0,0 +1,260 @@
1
+ import { useEffect, useRef, type CSSProperties, type Ref } from 'react'
2
+ import * as echarts from 'echarts/core'
3
+ import { BarChart } from 'echarts/charts'
4
+ import { GridComponent, TooltipComponent, LegendComponent } from 'echarts/components'
5
+ import { CanvasRenderer } from 'echarts/renderers'
6
+ import type { SeriesOption } from 'echarts'
7
+ import { DEFAULT_COLORS, DEFAULT_DATA, type DataPoint } from './constants'
8
+ import styles from './component.module.css'
9
+
10
+ // 按需注册 ECharts 组件
11
+ echarts.use([BarChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
12
+
13
+ interface BarChartProps {
14
+ ref?: Ref<HTMLDivElement>
15
+ data?: DataPoint[]
16
+ xField?: string
17
+ yFields?: string[]
18
+ colors?: string[]
19
+ layout?: 'vertical' | 'horizontal'
20
+ stacked?: boolean
21
+ gradient?: boolean
22
+ borderRadius?: number
23
+ barGap?: string
24
+ showGrid?: boolean
25
+ showLegend?: boolean
26
+ showTooltip?: boolean
27
+ glowEffect?: boolean
28
+ style?: CSSProperties
29
+ }
30
+
31
+ interface SeriesOptions {
32
+ stacked: boolean
33
+ gradient: boolean
34
+ borderRadius: number
35
+ glowEffect: boolean
36
+ layout: string
37
+ barGap?: string
38
+ }
39
+
40
+ // 获取渐变色
41
+ const getGradientColor = (color: string, isVertical: boolean) =>
42
+ new echarts.graphic.LinearGradient(isVertical ? 0 : 1, isVertical ? 1 : 0, isVertical ? 0 : 0, isVertical ? 0 : 1, [
43
+ { offset: 0, color: `${color}99` },
44
+ { offset: 1, color },
45
+ ])
46
+
47
+ // 构建单个 series 配置
48
+ const createBarSeries = (field: string, data: DataPoint[], color: string, options: SeriesOptions): SeriesOption => {
49
+ const { stacked, gradient, borderRadius, glowEffect, layout } = options
50
+ const isVertical = layout === 'vertical'
51
+
52
+ return {
53
+ name: field,
54
+ type: 'bar' as const,
55
+ data: data.map(item => item[field] as number),
56
+ stack: stacked ? 'total' : undefined,
57
+ barGap: options.barGap,
58
+ itemStyle: {
59
+ color: gradient ? getGradientColor(color, isVertical) : color,
60
+ borderRadius,
61
+ shadowColor: glowEffect ? color : 'transparent',
62
+ shadowBlur: glowEffect ? 10 : 0,
63
+ },
64
+ }
65
+ }
66
+
67
+ // 构建 series 配置
68
+ const buildSeries = (yFields: string[], data: DataPoint[], colors: string[], options: SeriesOptions): SeriesOption[] =>
69
+ yFields.map((field, index) => {
70
+ const color = colors[index % colors.length]
71
+ return createBarSeries(field, data, color, options)
72
+ })
73
+
74
+ // 构建图表配置
75
+ const buildOption = (
76
+ data: DataPoint[],
77
+ xField: string,
78
+ series: SeriesOption[],
79
+ options: {
80
+ layout: string
81
+ showGrid: boolean
82
+ showLegend: boolean
83
+ showTooltip: boolean
84
+ glowEffect: boolean
85
+ },
86
+ ) => {
87
+ const { layout, showGrid, showLegend, showTooltip } = options
88
+ const isHorizontal = layout === 'horizontal'
89
+
90
+ return {
91
+ backgroundColor: 'transparent',
92
+ grid: {
93
+ top: showLegend ? 40 : 20,
94
+ right: 20,
95
+ bottom: 30,
96
+ left: isHorizontal ? 80 : 50,
97
+ containLabel: false,
98
+ },
99
+ xAxis: {
100
+ type: isHorizontal ? 'value' : 'category',
101
+ data: isHorizontal ? undefined : data.map(item => item[xField]),
102
+ axisLine: {
103
+ lineStyle: {
104
+ color: '#8899aa',
105
+ opacity: 0.3,
106
+ },
107
+ },
108
+ axisTick: { show: false },
109
+ axisLabel: {
110
+ color: '#8899aa',
111
+ fontSize: isHorizontal ? 11 : 12,
112
+ },
113
+ splitLine: {
114
+ show: showGrid,
115
+ lineStyle: {
116
+ color: '#00d4ff',
117
+ opacity: 0.1,
118
+ type: 'dashed',
119
+ },
120
+ },
121
+ },
122
+ yAxis: {
123
+ type: isHorizontal ? 'category' : 'value',
124
+ data: isHorizontal ? data.map(item => item[xField]) : undefined,
125
+ axisLine: {
126
+ lineStyle: {
127
+ color: '#8899aa',
128
+ opacity: 0.3,
129
+ },
130
+ },
131
+ axisTick: { show: false },
132
+ axisLabel: {
133
+ color: '#8899aa',
134
+ fontSize: isHorizontal ? 12 : 11,
135
+ },
136
+ splitLine: {
137
+ show: showGrid && !isHorizontal,
138
+ lineStyle: {
139
+ color: '#00d4ff',
140
+ opacity: 0.1,
141
+ type: 'dashed',
142
+ },
143
+ },
144
+ },
145
+ tooltip: showTooltip
146
+ ? {
147
+ trigger: 'axis',
148
+ axisPointer: {
149
+ type: 'shadow',
150
+ },
151
+ backgroundColor: 'rgba(0, 20, 40, 0.9)',
152
+ borderColor: '#00d4ff',
153
+ borderWidth: 1,
154
+ textStyle: {
155
+ color: '#fff',
156
+ },
157
+ }
158
+ : undefined,
159
+ legend: showLegend
160
+ ? {
161
+ show: true,
162
+ top: 10,
163
+ textStyle: {
164
+ color: '#8899aa',
165
+ fontSize: 11,
166
+ },
167
+ }
168
+ : undefined,
169
+ series,
170
+ }
171
+ }
172
+
173
+ const BarChartComponent = (props: BarChartProps) => {
174
+ const {
175
+ ref,
176
+ data = DEFAULT_DATA,
177
+ xField = 'name',
178
+ yFields = ['value1', 'value2'],
179
+ colors = DEFAULT_COLORS,
180
+ layout = 'vertical',
181
+ stacked = false,
182
+ gradient = true,
183
+ borderRadius = 4,
184
+ barGap = '20%',
185
+ showGrid = true,
186
+ showLegend = true,
187
+ showTooltip = true,
188
+ glowEffect = true,
189
+ style: externalStyle,
190
+ } = props
191
+
192
+ const chartRef = useRef<HTMLDivElement>(null)
193
+ const chartInstance = useRef<echarts.ECharts | null>(null)
194
+
195
+ useEffect(() => {
196
+ if (!chartRef.current) {
197
+ return
198
+ }
199
+
200
+ chartInstance.current = echarts.init(chartRef.current)
201
+
202
+ // 构建 series
203
+ const series = buildSeries(yFields, data, colors, {
204
+ stacked,
205
+ gradient,
206
+ borderRadius,
207
+ glowEffect,
208
+ layout,
209
+ barGap,
210
+ })
211
+
212
+ const option = buildOption(data, xField, series, {
213
+ layout,
214
+ showGrid,
215
+ showLegend,
216
+ showTooltip,
217
+ glowEffect,
218
+ })
219
+
220
+ chartInstance.current.setOption(option)
221
+
222
+ const resizeObserver = new ResizeObserver(() => {
223
+ chartInstance.current?.resize()
224
+ })
225
+ resizeObserver.observe(chartRef.current)
226
+
227
+ return () => {
228
+ resizeObserver.disconnect()
229
+ chartInstance.current?.dispose()
230
+ }
231
+ }, [
232
+ data,
233
+ xField,
234
+ yFields,
235
+ colors,
236
+ layout,
237
+ stacked,
238
+ gradient,
239
+ borderRadius,
240
+ barGap,
241
+ showGrid,
242
+ showLegend,
243
+ showTooltip,
244
+ glowEffect,
245
+ ])
246
+
247
+ const containerStyle: CSSProperties = {
248
+ width: '100%',
249
+ height: '100%',
250
+ ...externalStyle,
251
+ }
252
+
253
+ return (
254
+ <div className={styles.container} ref={ref} style={containerStyle}>
255
+ <div className={styles.chart} ref={chartRef} />
256
+ </div>
257
+ )
258
+ }
259
+
260
+ export default BarChartComponent