@easy-editor/materials-dashboard-line-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.
- package/.vite/plugins/vite-plugin-external-deps.ts +224 -0
- package/.vite/plugins/vite-plugin-material-dev.ts +218 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +9 -0
- package/dist/component.esm.js +35200 -0
- package/dist/component.esm.js.map +1 -0
- package/dist/component.js +35207 -0
- package/dist/component.js.map +1 -0
- package/dist/component.min.js +24 -0
- package/dist/component.min.js.map +1 -0
- package/dist/index.cjs +35572 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.esm.js +35569 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +35576 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +24 -0
- package/dist/index.min.js.map +1 -0
- package/dist/meta.esm.js +403 -0
- package/dist/meta.esm.js.map +1 -0
- package/dist/meta.js +413 -0
- package/dist/meta.js.map +1 -0
- package/dist/meta.min.js +2 -0
- package/dist/meta.min.js.map +1 -0
- package/dist/src/component.d.ts +19 -0
- package/dist/src/configure.d.ts +7 -0
- package/dist/src/constants.d.ts +27 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/meta.d.ts +3 -0
- package/dist/src/snippets.d.ts +3 -0
- package/package.json +68 -0
- package/rollup.config.js +212 -0
- package/src/component.module.css +16 -0
- package/src/component.tsx +232 -0
- package/src/configure.ts +349 -0
- package/src/constants.ts +40 -0
- package/src/index.tsx +7 -0
- package/src/meta.ts +23 -0
- package/src/snippets.ts +51 -0
- package/src/type.d.ts +8 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +9 -0
- package/tsconfig.test.json +7 -0
- package/vite.config.ts +54 -0
package/rollup.config.js
ADDED
|
@@ -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 = 'EasyEditorMaterialsTechLineChart'
|
|
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-line-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-line-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-line-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-line-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-line-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-line-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-line-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-line-chart v${pkg.version} (minified) */`,
|
|
206
|
+
exports: 'named',
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
plugins: [...plugins, terser()],
|
|
210
|
+
external,
|
|
211
|
+
},
|
|
212
|
+
]
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { useEffect, useRef, type CSSProperties, type Ref } from 'react'
|
|
2
|
+
import * as echarts from 'echarts/core'
|
|
3
|
+
import { LineChart } 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([LineChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer])
|
|
12
|
+
|
|
13
|
+
interface LineChartProps {
|
|
14
|
+
ref?: Ref<HTMLDivElement>
|
|
15
|
+
data?: DataPoint[]
|
|
16
|
+
xField?: string
|
|
17
|
+
yFields?: string[]
|
|
18
|
+
colors?: string[]
|
|
19
|
+
showGrid?: boolean
|
|
20
|
+
showLegend?: boolean
|
|
21
|
+
showTooltip?: boolean
|
|
22
|
+
glowEffect?: boolean
|
|
23
|
+
strokeWidth?: number
|
|
24
|
+
areaFill?: boolean
|
|
25
|
+
smooth?: boolean
|
|
26
|
+
style?: CSSProperties
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 构建 series 配置
|
|
30
|
+
const buildSeries = (
|
|
31
|
+
yFields: string[],
|
|
32
|
+
data: DataPoint[],
|
|
33
|
+
colors: string[],
|
|
34
|
+
options: {
|
|
35
|
+
smooth: boolean
|
|
36
|
+
strokeWidth: number
|
|
37
|
+
glowEffect: boolean
|
|
38
|
+
areaFill: boolean
|
|
39
|
+
},
|
|
40
|
+
): SeriesOption[] => {
|
|
41
|
+
const { smooth, strokeWidth, glowEffect, areaFill } = options
|
|
42
|
+
return yFields.map((field, index) => {
|
|
43
|
+
const color = colors[index % colors.length]
|
|
44
|
+
return {
|
|
45
|
+
name: field,
|
|
46
|
+
type: 'line' as const,
|
|
47
|
+
data: data.map(item => item[field] as number),
|
|
48
|
+
smooth,
|
|
49
|
+
lineStyle: {
|
|
50
|
+
width: strokeWidth,
|
|
51
|
+
color,
|
|
52
|
+
shadowColor: glowEffect ? color : 'transparent',
|
|
53
|
+
shadowBlur: glowEffect ? 10 : 0,
|
|
54
|
+
},
|
|
55
|
+
itemStyle: {
|
|
56
|
+
color,
|
|
57
|
+
},
|
|
58
|
+
areaStyle: areaFill
|
|
59
|
+
? {
|
|
60
|
+
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
61
|
+
{ offset: 0, color: `${color}40` },
|
|
62
|
+
{ offset: 1, color: `${color}05` },
|
|
63
|
+
]),
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
66
|
+
symbol: 'circle',
|
|
67
|
+
symbolSize: 6,
|
|
68
|
+
}
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 构建图表配置
|
|
73
|
+
const buildOption = (
|
|
74
|
+
data: DataPoint[],
|
|
75
|
+
xField: string,
|
|
76
|
+
series: SeriesOption[],
|
|
77
|
+
options: {
|
|
78
|
+
showGrid: boolean
|
|
79
|
+
showLegend: boolean
|
|
80
|
+
showTooltip: boolean
|
|
81
|
+
},
|
|
82
|
+
) => {
|
|
83
|
+
const { showGrid, showLegend, showTooltip } = options
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
backgroundColor: 'transparent',
|
|
87
|
+
grid: {
|
|
88
|
+
top: showLegend ? 40 : 20,
|
|
89
|
+
right: 20,
|
|
90
|
+
bottom: 30,
|
|
91
|
+
left: 50,
|
|
92
|
+
containLabel: false,
|
|
93
|
+
},
|
|
94
|
+
xAxis: {
|
|
95
|
+
type: 'category',
|
|
96
|
+
data: data.map(item => item[xField]),
|
|
97
|
+
axisLine: {
|
|
98
|
+
lineStyle: {
|
|
99
|
+
color: '#8899aa',
|
|
100
|
+
opacity: 0.3,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
axisTick: { show: false },
|
|
104
|
+
axisLabel: {
|
|
105
|
+
color: '#8899aa',
|
|
106
|
+
fontSize: 12,
|
|
107
|
+
},
|
|
108
|
+
splitLine: {
|
|
109
|
+
show: showGrid,
|
|
110
|
+
lineStyle: {
|
|
111
|
+
color: '#00d4ff',
|
|
112
|
+
opacity: 0.1,
|
|
113
|
+
type: 'dashed',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
yAxis: {
|
|
118
|
+
type: 'value',
|
|
119
|
+
axisLine: {
|
|
120
|
+
lineStyle: {
|
|
121
|
+
color: '#8899aa',
|
|
122
|
+
opacity: 0.3,
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
axisTick: { show: false },
|
|
126
|
+
axisLabel: {
|
|
127
|
+
color: '#8899aa',
|
|
128
|
+
fontSize: 11,
|
|
129
|
+
},
|
|
130
|
+
splitLine: {
|
|
131
|
+
show: showGrid,
|
|
132
|
+
lineStyle: {
|
|
133
|
+
color: '#00d4ff',
|
|
134
|
+
opacity: 0.1,
|
|
135
|
+
type: 'dashed',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
tooltip: showTooltip
|
|
140
|
+
? {
|
|
141
|
+
trigger: 'axis',
|
|
142
|
+
backgroundColor: 'rgba(0, 20, 40, 0.9)',
|
|
143
|
+
borderColor: '#00d4ff',
|
|
144
|
+
borderWidth: 1,
|
|
145
|
+
textStyle: {
|
|
146
|
+
color: '#fff',
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
: undefined,
|
|
150
|
+
legend: showLegend
|
|
151
|
+
? {
|
|
152
|
+
show: true,
|
|
153
|
+
top: 10,
|
|
154
|
+
textStyle: {
|
|
155
|
+
color: '#8899aa',
|
|
156
|
+
fontSize: 11,
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
: undefined,
|
|
160
|
+
series,
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
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
|
+
|
|
181
|
+
const chartRef = useRef<HTMLDivElement>(null)
|
|
182
|
+
const chartInstance = useRef<echarts.ECharts | null>(null)
|
|
183
|
+
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
if (!chartRef.current) {
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
chartInstance.current = echarts.init(chartRef.current)
|
|
190
|
+
|
|
191
|
+
// 构建 series
|
|
192
|
+
const series = buildSeries(yFields, data, colors, {
|
|
193
|
+
smooth,
|
|
194
|
+
strokeWidth,
|
|
195
|
+
glowEffect,
|
|
196
|
+
areaFill,
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
const option = buildOption(data, xField, series, {
|
|
200
|
+
showGrid,
|
|
201
|
+
showLegend,
|
|
202
|
+
showTooltip,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
chartInstance.current.setOption(option)
|
|
206
|
+
|
|
207
|
+
// 响应式调整
|
|
208
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
209
|
+
chartInstance.current?.resize()
|
|
210
|
+
})
|
|
211
|
+
resizeObserver.observe(chartRef.current)
|
|
212
|
+
|
|
213
|
+
return () => {
|
|
214
|
+
resizeObserver.disconnect()
|
|
215
|
+
chartInstance.current?.dispose()
|
|
216
|
+
}
|
|
217
|
+
}, [data, xField, yFields, colors, showGrid, showLegend, showTooltip, glowEffect, strokeWidth, areaFill, smooth])
|
|
218
|
+
|
|
219
|
+
const containerStyle: CSSProperties = {
|
|
220
|
+
width: '100%',
|
|
221
|
+
height: '100%',
|
|
222
|
+
...externalStyle,
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<div className={styles.container} ref={ref} style={containerStyle}>
|
|
227
|
+
<div className={styles.chart} ref={chartRef} />
|
|
228
|
+
</div>
|
|
229
|
+
)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export default LineChartComponent
|