@easy-editor/materials-dashboard-bar-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.
- package/.vite/echarts-external-plugin.ts +61 -0
- package/CHANGELOG.md +27 -13
- package/easypack.config.ts +19 -0
- package/package.json +6 -10
- package/src/component.tsx +82 -29
- package/src/configure.ts +220 -365
- package/src/index.tsx +7 -7
- package/src/meta.ts +3 -3
- package/src/snippets.ts +104 -79
- package/tsconfig.json +20 -9
- package/.vite/plugins/vite-plugin-external-deps.ts +0 -224
- package/.vite/plugins/vite-plugin-material-dev.ts +0 -218
- package/dist/component.esm.js +0 -34452
- package/dist/component.esm.js.map +0 -1
- package/dist/component.js +0 -34459
- package/dist/component.js.map +0 -1
- package/dist/component.min.js +0 -24
- package/dist/component.min.js.map +0 -1
- package/dist/index.cjs +0 -34870
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js +0 -34867
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -34874
- package/dist/index.js.map +0 -1
- package/dist/index.min.js +0 -24
- package/dist/index.min.js.map +0 -1
- package/dist/meta.esm.js +0 -441
- package/dist/meta.esm.js.map +0 -1
- package/dist/meta.js +0 -451
- package/dist/meta.js.map +0 -1
- package/dist/meta.min.js +0 -2
- package/dist/meta.min.js.map +0 -1
- package/dist/src/component.d.ts +0 -21
- package/dist/src/configure.d.ts +0 -7
- package/dist/src/constants.d.ts +0 -27
- package/dist/src/index.d.ts +0 -6
- package/dist/src/meta.d.ts +0 -3
- package/dist/src/snippets.d.ts +0 -3
- package/rollup.config.js +0 -212
- package/tsconfig.build.json +0 -12
- package/tsconfig.test.json +0 -7
- 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-bar-chart
|
|
2
|
-
|
|
3
|
-
## 0.0.
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- fix:
|
|
8
|
-
|
|
9
|
-
## 0.0.
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
-
|
|
1
|
+
# @easy-editor/materials-dashboard-bar-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-bar-chart",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Bar Chart component for EasyEditor dashboard",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,24 +44,20 @@
|
|
|
44
44
|
"react": "^18 || ^19",
|
|
45
45
|
"react-dom": "^18 || ^19",
|
|
46
46
|
"@types/react": "^18 || ^19",
|
|
47
|
-
"@types/react-dom": "^18 || ^19"
|
|
47
|
+
"@types/react-dom": "^18 || ^19",
|
|
48
|
+
"echarts": "^5"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"
|
|
51
|
-
"@easy-editor/materials-shared": "0.0.0"
|
|
51
|
+
"@easy-editor/materials-shared": "0.0.1"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
|
-
"dev": "
|
|
54
|
+
"dev": "easypack dev",
|
|
55
55
|
"dev:debug": "vite --port 5003",
|
|
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": "
|
|
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,31 +1,54 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Bar Chart Component
|
|
3
|
+
* 柱状图组件 - 支持数据源绑定和事件交互
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useEffect, useMemo, useRef, type CSSProperties } from 'react'
|
|
2
7
|
import * as echarts from 'echarts/core'
|
|
3
|
-
import { BarChart } from 'echarts/charts'
|
|
8
|
+
import { BarChart as EChartsBarChart } 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'
|
|
7
|
-
import {
|
|
12
|
+
import { type MaterialComponet, useDataSource } from '@easy-editor/materials-shared'
|
|
13
|
+
import { DEFAULT_COLORS, type DataPoint } from './constants'
|
|
8
14
|
import styles from './component.module.css'
|
|
9
15
|
|
|
10
16
|
// 按需注册 ECharts 组件
|
|
11
|
-
echarts.use([
|
|
17
|
+
echarts.use([EChartsBarChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
|
|
12
18
|
|
|
13
|
-
interface BarChartProps {
|
|
14
|
-
|
|
15
|
-
data?: DataPoint[]
|
|
19
|
+
export interface BarChartProps extends MaterialComponet {
|
|
20
|
+
/** X轴字段 */
|
|
16
21
|
xField?: string
|
|
22
|
+
/** Y轴字段列表 */
|
|
17
23
|
yFields?: string[]
|
|
24
|
+
/** 颜色列表 */
|
|
18
25
|
colors?: string[]
|
|
26
|
+
/** 布局方向 */
|
|
19
27
|
layout?: 'vertical' | 'horizontal'
|
|
28
|
+
/** 堆叠模式 */
|
|
20
29
|
stacked?: boolean
|
|
30
|
+
/** 渐变填充 */
|
|
21
31
|
gradient?: boolean
|
|
32
|
+
/** 圆角 */
|
|
22
33
|
borderRadius?: number
|
|
34
|
+
/** 柱间距 */
|
|
23
35
|
barGap?: string
|
|
36
|
+
/** 显示网格 */
|
|
24
37
|
showGrid?: boolean
|
|
38
|
+
/** 显示图例 */
|
|
25
39
|
showLegend?: boolean
|
|
40
|
+
/** 显示提示 */
|
|
26
41
|
showTooltip?: boolean
|
|
42
|
+
/** 发光效果 */
|
|
27
43
|
glowEffect?: boolean
|
|
28
|
-
|
|
44
|
+
/** 点击事件 */
|
|
45
|
+
onClick?: (e: React.MouseEvent) => void
|
|
46
|
+
/** 双击事件 */
|
|
47
|
+
onDoubleClick?: (e: React.MouseEvent) => void
|
|
48
|
+
/** 鼠标进入 */
|
|
49
|
+
onMouseEnter?: (e: React.MouseEvent) => void
|
|
50
|
+
/** 鼠标离开 */
|
|
51
|
+
onMouseLeave?: (e: React.MouseEvent) => void
|
|
29
52
|
}
|
|
30
53
|
|
|
31
54
|
interface SeriesOptions {
|
|
@@ -170,28 +193,47 @@ const buildOption = (
|
|
|
170
193
|
}
|
|
171
194
|
}
|
|
172
195
|
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
export const BarChart: React.FC<BarChartProps> = ({
|
|
197
|
+
ref,
|
|
198
|
+
$data,
|
|
199
|
+
__dataSource,
|
|
200
|
+
xField = 'name',
|
|
201
|
+
yFields = ['value1', 'value2'],
|
|
202
|
+
colors = DEFAULT_COLORS,
|
|
203
|
+
layout = 'vertical',
|
|
204
|
+
stacked = false,
|
|
205
|
+
gradient = true,
|
|
206
|
+
borderRadius = 4,
|
|
207
|
+
barGap = '20%',
|
|
208
|
+
showGrid = true,
|
|
209
|
+
showLegend = true,
|
|
210
|
+
showTooltip = true,
|
|
211
|
+
glowEffect = true,
|
|
212
|
+
rotation = 0,
|
|
213
|
+
opacity = 100,
|
|
214
|
+
background = 'transparent',
|
|
215
|
+
style: externalStyle,
|
|
216
|
+
onClick,
|
|
217
|
+
onDoubleClick,
|
|
218
|
+
onMouseEnter,
|
|
219
|
+
onMouseLeave,
|
|
220
|
+
}) => {
|
|
192
221
|
const chartRef = useRef<HTMLDivElement>(null)
|
|
193
222
|
const chartInstance = useRef<echarts.ECharts | null>(null)
|
|
194
223
|
|
|
224
|
+
// 解析数据源
|
|
225
|
+
const dataSource = useDataSource($data, __dataSource)
|
|
226
|
+
const data = useMemo<DataPoint[]>(() => {
|
|
227
|
+
if (dataSource.length > 0 && dataSource[0]?.name && dataSource[0]?.value1 && dataSource[0]?.value2) {
|
|
228
|
+
return dataSource.map(item => ({
|
|
229
|
+
name: String(item.name),
|
|
230
|
+
value1: Number(item.value1),
|
|
231
|
+
value2: Number(item.value2),
|
|
232
|
+
}))
|
|
233
|
+
}
|
|
234
|
+
return []
|
|
235
|
+
}, [dataSource])
|
|
236
|
+
|
|
195
237
|
useEffect(() => {
|
|
196
238
|
if (!chartRef.current) {
|
|
197
239
|
return
|
|
@@ -247,14 +289,25 @@ const BarChartComponent = (props: BarChartProps) => {
|
|
|
247
289
|
const containerStyle: CSSProperties = {
|
|
248
290
|
width: '100%',
|
|
249
291
|
height: '100%',
|
|
292
|
+
transform: rotation !== 0 ? `rotate(${rotation}deg)` : undefined,
|
|
293
|
+
opacity: opacity / 100,
|
|
294
|
+
backgroundColor: background,
|
|
250
295
|
...externalStyle,
|
|
251
296
|
}
|
|
252
297
|
|
|
253
298
|
return (
|
|
254
|
-
<div
|
|
299
|
+
<div
|
|
300
|
+
className={styles.container}
|
|
301
|
+
onClick={onClick}
|
|
302
|
+
onDoubleClick={onDoubleClick}
|
|
303
|
+
onMouseEnter={onMouseEnter}
|
|
304
|
+
onMouseLeave={onMouseLeave}
|
|
305
|
+
ref={ref}
|
|
306
|
+
style={containerStyle}
|
|
307
|
+
>
|
|
255
308
|
<div className={styles.chart} ref={chartRef} />
|
|
256
309
|
</div>
|
|
257
310
|
)
|
|
258
311
|
}
|
|
259
312
|
|
|
260
|
-
export default
|
|
313
|
+
export default BarChart
|