@gm-pc/vision 1.25.0-beta.0 → 1.25.0
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/package.json +2 -2
- package/src/chart/bar/components/table_chart.tsx +106 -106
- package/src/chart/bar/core/config.ts +257 -257
- package/src/chart/bar/core/index.ts +9 -9
- package/src/chart/bar/core/utils.ts +8 -8
- package/src/chart/bar/index.less +132 -132
- package/src/chart/bar/index.tsx +18 -18
- package/src/chart/bar/stories.tsx +420 -420
- package/src/chart/base/index.ts +135 -135
- package/src/chart/line/core/config.ts +209 -209
- package/src/chart/line/core/index.ts +9 -9
- package/src/chart/line/core/utils.ts +49 -49
- package/src/chart/line/index.tsx +12 -12
- package/src/chart/line/stories.tsx +234 -234
- package/src/chart/pie/core/config.ts +199 -199
- package/src/chart/pie/core/index.ts +9 -9
- package/src/chart/pie/index.tsx +12 -12
- package/src/chart/pie/stories.tsx +39 -39
- package/src/common/hooks/useChart.ts +40 -40
- package/src/common/utils/dom.ts +22 -22
- package/src/index.ts +11 -11
- package/src/theme/index.ts +8 -8
- package/src/theme/ocean/chart.ts +40 -40
- package/src/theme/ocean/index.ts +495 -495
- package/src/theme/sunset/chart.ts +40 -40
- package/src/theme/sunset/index.ts +495 -495
- package/src/theme/utils/create-style-by-sheet.ts +1303 -1303
- package/src/types/common.ts +41 -41
- package/src/types/theme.ts +552 -552
- package/tsconfig.json +3 -3
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import { getEngine } from '@antv/g2'
|
|
3
|
-
import { Instance } from '../../../types/common'
|
|
4
|
-
import themes from '../../../theme'
|
|
5
|
-
|
|
6
|
-
const G = getEngine('canvas')
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* - 几何标记 Geometry
|
|
10
|
-
* - 度量 Scale
|
|
11
|
-
* - 坐标系 Coordinate
|
|
12
|
-
* - 可视化组件 Component
|
|
13
|
-
* - 包括坐标轴 Axis,
|
|
14
|
-
* - 图例 Legend,
|
|
15
|
-
* - 提示信息 Tooltip,
|
|
16
|
-
* - 图形标记 Annotation,
|
|
17
|
-
* - 滑动条 Slider 等。
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
function geometry(params: Instance) {
|
|
21
|
-
const { chart, options } = params
|
|
22
|
-
const { position, color, data } = options
|
|
23
|
-
// 对Pie的数据进行百分比处理
|
|
24
|
-
const total = data.reduce((t: number, c: any) => t + c[position], 0)
|
|
25
|
-
const newData = data.map((d) => {
|
|
26
|
-
d[position] = +((d[position] / total) * 100).toFixed(2)
|
|
27
|
-
return d
|
|
28
|
-
})
|
|
29
|
-
chart.data(newData)
|
|
30
|
-
const geometry = chart.interval().position(position).adjust('stack')
|
|
31
|
-
geometry.color(color)
|
|
32
|
-
|
|
33
|
-
return { ...params, geometry }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function coordinate(params: Instance) {
|
|
37
|
-
const { chart } = params
|
|
38
|
-
chart.coordinate('theta', {
|
|
39
|
-
radius: 0.75,
|
|
40
|
-
innerRadius: 0.6,
|
|
41
|
-
})
|
|
42
|
-
return params
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function interaction(params: Instance) {
|
|
46
|
-
const { chart } = params
|
|
47
|
-
chart.interaction('element-active')
|
|
48
|
-
return params
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function scale(params: Instance) {
|
|
52
|
-
const { chart, options } = params
|
|
53
|
-
// position = x*y
|
|
54
|
-
const { position } = options
|
|
55
|
-
const y = position.split('*')[1]
|
|
56
|
-
// TODO 通用配置 y轴nice: true
|
|
57
|
-
chart.scale(y, {
|
|
58
|
-
nice: true,
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
return params
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function axis(params: Instance) {
|
|
65
|
-
const { options, geometry } = params
|
|
66
|
-
let { position, label = true, color } = options
|
|
67
|
-
|
|
68
|
-
if (label) {
|
|
69
|
-
label =
|
|
70
|
-
label === true
|
|
71
|
-
? (data: Record<string, any>) => {
|
|
72
|
-
return `${data[color]}`
|
|
73
|
-
}
|
|
74
|
-
: label
|
|
75
|
-
geometry!.label(position[1], {
|
|
76
|
-
content: label,
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
return params
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function annotation(params: Instance) {
|
|
83
|
-
return params
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function tooltip(params: Instance) {
|
|
87
|
-
const { chart } = params
|
|
88
|
-
// tooltip样式
|
|
89
|
-
chart.tooltip({
|
|
90
|
-
showTitle: false,
|
|
91
|
-
showMarkers: false,
|
|
92
|
-
itemTpl:
|
|
93
|
-
'<li class="g2-tooltip-list-item"><span style="background-color:{color};" class="g2-tooltip-marker"></span>{name}: {value}</li>',
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
return params
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function legend(params: Instance) {
|
|
100
|
-
const { chart, options } = params
|
|
101
|
-
const { color, legend } = options
|
|
102
|
-
|
|
103
|
-
if (!_.isNil(legend)) {
|
|
104
|
-
chart.legend(legend)
|
|
105
|
-
} else {
|
|
106
|
-
chart.legend(color, {
|
|
107
|
-
position: 'right',
|
|
108
|
-
}) // 只更改 x 维度对应的图例的显示位置
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return params
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function theme(params: Instance) {
|
|
115
|
-
const { geometry, options, chart } = params
|
|
116
|
-
const { theme, position } = options
|
|
117
|
-
const themeConfig = themes[theme as 'ocean']?.chart
|
|
118
|
-
chart.tooltip({
|
|
119
|
-
showTitle: false,
|
|
120
|
-
showMarkers: false,
|
|
121
|
-
itemTpl: '<li class="g2-tooltip-list-item">{name}: {value}%</li>',
|
|
122
|
-
})
|
|
123
|
-
if (themeConfig) {
|
|
124
|
-
const { ghost } = themeConfig.pie
|
|
125
|
-
|
|
126
|
-
if (ghost) {
|
|
127
|
-
// ---------- 标注配置 -----------------
|
|
128
|
-
chart.annotation().shape({
|
|
129
|
-
top: false,
|
|
130
|
-
render: (container, chart, c) => {
|
|
131
|
-
const group = container.addGroup({})
|
|
132
|
-
const center = { x: c.parsePosition({}).x, y: chart.height / 2 } // NOTE: ts报错应该是antv的类型定义有问题,明明有这个属性
|
|
133
|
-
// 外圈
|
|
134
|
-
group.addShape({
|
|
135
|
-
type: 'circle',
|
|
136
|
-
attrs: {
|
|
137
|
-
x: center.x,
|
|
138
|
-
y: center.y,
|
|
139
|
-
r: chart.height / 2 - 35 - chart.appendPadding[0] / 2,
|
|
140
|
-
fill: '#15347f', // TODO 颜色配置都扔到/theme目录下
|
|
141
|
-
},
|
|
142
|
-
})
|
|
143
|
-
// 内圈
|
|
144
|
-
group.addShape({
|
|
145
|
-
type: 'circle',
|
|
146
|
-
attrs: {
|
|
147
|
-
x: center.x,
|
|
148
|
-
y: center.y,
|
|
149
|
-
r: chart.height / 2 - 80,
|
|
150
|
-
fill: '#030646',
|
|
151
|
-
},
|
|
152
|
-
})
|
|
153
|
-
},
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// ---------- tiptop配置 ----------------
|
|
158
|
-
chart.tooltip({
|
|
159
|
-
showTitle: false,
|
|
160
|
-
showMarkers: false,
|
|
161
|
-
itemTpl: '<li class="g2-tooltip-list-item">{name}: {value}%</li>',
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
geometry!.label(position, {
|
|
165
|
-
offset: '80%',
|
|
166
|
-
labelLine: null,
|
|
167
|
-
content: (a, b) => {
|
|
168
|
-
const group = new G.Group({})
|
|
169
|
-
group.addShape({
|
|
170
|
-
type: 'text',
|
|
171
|
-
position: 'relative',
|
|
172
|
-
attrs: {
|
|
173
|
-
x: 0,
|
|
174
|
-
y: 0,
|
|
175
|
-
textBaseline: 'top',
|
|
176
|
-
text: a.item,
|
|
177
|
-
fontSize: 12,
|
|
178
|
-
fill: b.color,
|
|
179
|
-
},
|
|
180
|
-
})
|
|
181
|
-
return group
|
|
182
|
-
},
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function processor(params: Instance) {
|
|
188
|
-
return _.flow(
|
|
189
|
-
geometry,
|
|
190
|
-
coordinate,
|
|
191
|
-
interaction,
|
|
192
|
-
axis,
|
|
193
|
-
legend,
|
|
194
|
-
annotation,
|
|
195
|
-
tooltip,
|
|
196
|
-
scale,
|
|
197
|
-
theme
|
|
198
|
-
)(params)
|
|
199
|
-
}
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { getEngine } from '@antv/g2'
|
|
3
|
+
import { Instance } from '../../../types/common'
|
|
4
|
+
import themes from '../../../theme'
|
|
5
|
+
|
|
6
|
+
const G = getEngine('canvas')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* - 几何标记 Geometry
|
|
10
|
+
* - 度量 Scale
|
|
11
|
+
* - 坐标系 Coordinate
|
|
12
|
+
* - 可视化组件 Component
|
|
13
|
+
* - 包括坐标轴 Axis,
|
|
14
|
+
* - 图例 Legend,
|
|
15
|
+
* - 提示信息 Tooltip,
|
|
16
|
+
* - 图形标记 Annotation,
|
|
17
|
+
* - 滑动条 Slider 等。
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function geometry(params: Instance) {
|
|
21
|
+
const { chart, options } = params
|
|
22
|
+
const { position, color, data } = options
|
|
23
|
+
// 对Pie的数据进行百分比处理
|
|
24
|
+
const total = data.reduce((t: number, c: any) => t + c[position], 0)
|
|
25
|
+
const newData = data.map((d) => {
|
|
26
|
+
d[position] = +((d[position] / total) * 100).toFixed(2)
|
|
27
|
+
return d
|
|
28
|
+
})
|
|
29
|
+
chart.data(newData)
|
|
30
|
+
const geometry = chart.interval().position(position).adjust('stack')
|
|
31
|
+
geometry.color(color)
|
|
32
|
+
|
|
33
|
+
return { ...params, geometry }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function coordinate(params: Instance) {
|
|
37
|
+
const { chart } = params
|
|
38
|
+
chart.coordinate('theta', {
|
|
39
|
+
radius: 0.75,
|
|
40
|
+
innerRadius: 0.6,
|
|
41
|
+
})
|
|
42
|
+
return params
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function interaction(params: Instance) {
|
|
46
|
+
const { chart } = params
|
|
47
|
+
chart.interaction('element-active')
|
|
48
|
+
return params
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function scale(params: Instance) {
|
|
52
|
+
const { chart, options } = params
|
|
53
|
+
// position = x*y
|
|
54
|
+
const { position } = options
|
|
55
|
+
const y = position.split('*')[1]
|
|
56
|
+
// TODO 通用配置 y轴nice: true
|
|
57
|
+
chart.scale(y, {
|
|
58
|
+
nice: true,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return params
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function axis(params: Instance) {
|
|
65
|
+
const { options, geometry } = params
|
|
66
|
+
let { position, label = true, color } = options
|
|
67
|
+
|
|
68
|
+
if (label) {
|
|
69
|
+
label =
|
|
70
|
+
label === true
|
|
71
|
+
? (data: Record<string, any>) => {
|
|
72
|
+
return `${data[color]}`
|
|
73
|
+
}
|
|
74
|
+
: label
|
|
75
|
+
geometry!.label(position[1], {
|
|
76
|
+
content: label,
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
return params
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function annotation(params: Instance) {
|
|
83
|
+
return params
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function tooltip(params: Instance) {
|
|
87
|
+
const { chart } = params
|
|
88
|
+
// tooltip样式
|
|
89
|
+
chart.tooltip({
|
|
90
|
+
showTitle: false,
|
|
91
|
+
showMarkers: false,
|
|
92
|
+
itemTpl:
|
|
93
|
+
'<li class="g2-tooltip-list-item"><span style="background-color:{color};" class="g2-tooltip-marker"></span>{name}: {value}</li>',
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
return params
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function legend(params: Instance) {
|
|
100
|
+
const { chart, options } = params
|
|
101
|
+
const { color, legend } = options
|
|
102
|
+
|
|
103
|
+
if (!_.isNil(legend)) {
|
|
104
|
+
chart.legend(legend)
|
|
105
|
+
} else {
|
|
106
|
+
chart.legend(color, {
|
|
107
|
+
position: 'right',
|
|
108
|
+
}) // 只更改 x 维度对应的图例的显示位置
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return params
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function theme(params: Instance) {
|
|
115
|
+
const { geometry, options, chart } = params
|
|
116
|
+
const { theme, position } = options
|
|
117
|
+
const themeConfig = themes[theme as 'ocean']?.chart
|
|
118
|
+
chart.tooltip({
|
|
119
|
+
showTitle: false,
|
|
120
|
+
showMarkers: false,
|
|
121
|
+
itemTpl: '<li class="g2-tooltip-list-item">{name}: {value}%</li>',
|
|
122
|
+
})
|
|
123
|
+
if (themeConfig) {
|
|
124
|
+
const { ghost } = themeConfig.pie
|
|
125
|
+
|
|
126
|
+
if (ghost) {
|
|
127
|
+
// ---------- 标注配置 -----------------
|
|
128
|
+
chart.annotation().shape({
|
|
129
|
+
top: false,
|
|
130
|
+
render: (container, chart, c) => {
|
|
131
|
+
const group = container.addGroup({})
|
|
132
|
+
const center = { x: c.parsePosition({}).x, y: chart.height / 2 } // NOTE: ts报错应该是antv的类型定义有问题,明明有这个属性
|
|
133
|
+
// 外圈
|
|
134
|
+
group.addShape({
|
|
135
|
+
type: 'circle',
|
|
136
|
+
attrs: {
|
|
137
|
+
x: center.x,
|
|
138
|
+
y: center.y,
|
|
139
|
+
r: chart.height / 2 - 35 - chart.appendPadding[0] / 2,
|
|
140
|
+
fill: '#15347f', // TODO 颜色配置都扔到/theme目录下
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
// 内圈
|
|
144
|
+
group.addShape({
|
|
145
|
+
type: 'circle',
|
|
146
|
+
attrs: {
|
|
147
|
+
x: center.x,
|
|
148
|
+
y: center.y,
|
|
149
|
+
r: chart.height / 2 - 80,
|
|
150
|
+
fill: '#030646',
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ---------- tiptop配置 ----------------
|
|
158
|
+
chart.tooltip({
|
|
159
|
+
showTitle: false,
|
|
160
|
+
showMarkers: false,
|
|
161
|
+
itemTpl: '<li class="g2-tooltip-list-item">{name}: {value}%</li>',
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
geometry!.label(position, {
|
|
165
|
+
offset: '80%',
|
|
166
|
+
labelLine: null,
|
|
167
|
+
content: (a, b) => {
|
|
168
|
+
const group = new G.Group({})
|
|
169
|
+
group.addShape({
|
|
170
|
+
type: 'text',
|
|
171
|
+
position: 'relative',
|
|
172
|
+
attrs: {
|
|
173
|
+
x: 0,
|
|
174
|
+
y: 0,
|
|
175
|
+
textBaseline: 'top',
|
|
176
|
+
text: a.item,
|
|
177
|
+
fontSize: 12,
|
|
178
|
+
fill: b.color,
|
|
179
|
+
},
|
|
180
|
+
})
|
|
181
|
+
return group
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function processor(params: Instance) {
|
|
188
|
+
return _.flow(
|
|
189
|
+
geometry,
|
|
190
|
+
coordinate,
|
|
191
|
+
interaction,
|
|
192
|
+
axis,
|
|
193
|
+
legend,
|
|
194
|
+
annotation,
|
|
195
|
+
tooltip,
|
|
196
|
+
scale,
|
|
197
|
+
theme
|
|
198
|
+
)(params)
|
|
199
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Base } from '../../base/index'
|
|
2
|
-
import { processor } from './config'
|
|
3
|
-
|
|
4
|
-
export default class Pie extends Base {
|
|
5
|
-
name = 'pie'
|
|
6
|
-
getProcessor() {
|
|
7
|
-
return processor
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
import { Base } from '../../base/index'
|
|
2
|
+
import { processor } from './config'
|
|
3
|
+
|
|
4
|
+
export default class Pie extends Base {
|
|
5
|
+
name = 'pie'
|
|
6
|
+
getProcessor() {
|
|
7
|
+
return processor
|
|
8
|
+
}
|
|
9
|
+
}
|
package/src/chart/pie/index.tsx
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React, { FC, forwardRef } from 'react'
|
|
2
|
-
import _Pie from './core'
|
|
3
|
-
import useChart from '../../common/hooks/useChart'
|
|
4
|
-
import { ChartProps } from '../../types/common'
|
|
5
|
-
|
|
6
|
-
const Pie: FC<ChartProps> = forwardRef((props, ref) => {
|
|
7
|
-
const { container } = useChart(_Pie, props)
|
|
8
|
-
|
|
9
|
-
return <div ref={container} />
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
export { Pie }
|
|
1
|
+
import React, { FC, forwardRef } from 'react'
|
|
2
|
+
import _Pie from './core'
|
|
3
|
+
import useChart from '../../common/hooks/useChart'
|
|
4
|
+
import { ChartProps } from '../../types/common'
|
|
5
|
+
|
|
6
|
+
const Pie: FC<ChartProps> = forwardRef((props, ref) => {
|
|
7
|
+
const { container } = useChart(_Pie, props)
|
|
8
|
+
|
|
9
|
+
return <div ref={container} />
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
export { Pie }
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Pie as PieChart } from './index'
|
|
3
|
-
|
|
4
|
-
const data = [
|
|
5
|
-
{ item: '事例一', count: 40, percent: 0.4 },
|
|
6
|
-
{ item: '事例二', count: 21, percent: 0.21 },
|
|
7
|
-
{ item: '事例三', count: 107, percent: 0.17 },
|
|
8
|
-
{ item: '事例四', count: 13, percent: 0.13 },
|
|
9
|
-
{ item: '事例五', count: 9, percent: 0.09 },
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
export const Pie = () => (
|
|
13
|
-
<div>
|
|
14
|
-
<h1>基础</h1>
|
|
15
|
-
<PieChart
|
|
16
|
-
data={data}
|
|
17
|
-
options={{
|
|
18
|
-
height: 300,
|
|
19
|
-
position: 'count',
|
|
20
|
-
color: 'item',
|
|
21
|
-
}}
|
|
22
|
-
/>
|
|
23
|
-
<h1>深蓝主题</h1>
|
|
24
|
-
<PieChart
|
|
25
|
-
data={data}
|
|
26
|
-
options={{
|
|
27
|
-
height: 300,
|
|
28
|
-
theme: 'ocean',
|
|
29
|
-
position: 'count',
|
|
30
|
-
color: 'item',
|
|
31
|
-
legend: false,
|
|
32
|
-
}}
|
|
33
|
-
/>
|
|
34
|
-
</div>
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
export default {
|
|
38
|
-
title: 'Chart/饼状图 Pie',
|
|
39
|
-
}
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Pie as PieChart } from './index'
|
|
3
|
+
|
|
4
|
+
const data = [
|
|
5
|
+
{ item: '事例一', count: 40, percent: 0.4 },
|
|
6
|
+
{ item: '事例二', count: 21, percent: 0.21 },
|
|
7
|
+
{ item: '事例三', count: 107, percent: 0.17 },
|
|
8
|
+
{ item: '事例四', count: 13, percent: 0.13 },
|
|
9
|
+
{ item: '事例五', count: 9, percent: 0.09 },
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
export const Pie = () => (
|
|
13
|
+
<div>
|
|
14
|
+
<h1>基础</h1>
|
|
15
|
+
<PieChart
|
|
16
|
+
data={data}
|
|
17
|
+
options={{
|
|
18
|
+
height: 300,
|
|
19
|
+
position: 'count',
|
|
20
|
+
color: 'item',
|
|
21
|
+
}}
|
|
22
|
+
/>
|
|
23
|
+
<h1>深蓝主题</h1>
|
|
24
|
+
<PieChart
|
|
25
|
+
data={data}
|
|
26
|
+
options={{
|
|
27
|
+
height: 300,
|
|
28
|
+
theme: 'ocean',
|
|
29
|
+
position: 'count',
|
|
30
|
+
color: 'item',
|
|
31
|
+
legend: false,
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
title: 'Chart/饼状图 Pie',
|
|
39
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react'
|
|
2
|
-
import { Base } from '../../chart/base/index'
|
|
3
|
-
import { ChartOptions, ChartProps } from '../../types/common'
|
|
4
|
-
import _ from 'lodash'
|
|
5
|
-
|
|
6
|
-
function useChart<T extends Base>(ChartClass: any, props: ChartProps) {
|
|
7
|
-
const container = useRef<HTMLDivElement>(null)
|
|
8
|
-
const chart = useRef<T>(null!)
|
|
9
|
-
const chartOptions = useRef<ChartOptions>(null!)
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
if (container && !container.current) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const instance: T = new ChartClass(container.current, {
|
|
16
|
-
data: props.data,
|
|
17
|
-
...props.options,
|
|
18
|
-
})
|
|
19
|
-
chart.current = instance
|
|
20
|
-
instance.render()
|
|
21
|
-
}, [])
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (chart.current && !_.isEqual(chartOptions.current, props.options)) {
|
|
25
|
-
chart.current.updateOptions(props.options)
|
|
26
|
-
chartOptions.current = props.options
|
|
27
|
-
}
|
|
28
|
-
}, [props.options])
|
|
29
|
-
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
chart.current.updateData(props.data)
|
|
32
|
-
}, [props.data])
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
container,
|
|
36
|
-
chart,
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export default useChart
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { Base } from '../../chart/base/index'
|
|
3
|
+
import { ChartOptions, ChartProps } from '../../types/common'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
|
|
6
|
+
function useChart<T extends Base>(ChartClass: any, props: ChartProps) {
|
|
7
|
+
const container = useRef<HTMLDivElement>(null)
|
|
8
|
+
const chart = useRef<T>(null!)
|
|
9
|
+
const chartOptions = useRef<ChartOptions>(null!)
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (container && !container.current) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const instance: T = new ChartClass(container.current, {
|
|
16
|
+
data: props.data,
|
|
17
|
+
...props.options,
|
|
18
|
+
})
|
|
19
|
+
chart.current = instance
|
|
20
|
+
instance.render()
|
|
21
|
+
}, [])
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (chart.current && !_.isEqual(chartOptions.current, props.options)) {
|
|
25
|
+
chart.current.updateOptions(props.options)
|
|
26
|
+
chartOptions.current = props.options
|
|
27
|
+
}
|
|
28
|
+
}, [props.options])
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
chart.current.updateData(props.data)
|
|
32
|
+
}, [props.data])
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
container,
|
|
36
|
+
chart,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default useChart
|
package/src/common/utils/dom.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
export type Size = {
|
|
2
|
-
width: number
|
|
3
|
-
height: number
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function getContainerSize(ele: HTMLElement): Size {
|
|
7
|
-
if (!ele) {
|
|
8
|
-
return { width: 0, height: 0 }
|
|
9
|
-
}
|
|
10
|
-
const style = getComputedStyle(ele)
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
width:
|
|
14
|
-
(ele.clientWidth || parseInt(style.width, 10)) -
|
|
15
|
-
parseInt(style.paddingLeft, 10) -
|
|
16
|
-
parseInt(style.paddingRight, 10),
|
|
17
|
-
height:
|
|
18
|
-
(ele.clientHeight || parseInt(style.height, 10)) -
|
|
19
|
-
parseInt(style.paddingTop, 10) -
|
|
20
|
-
parseInt(style.paddingBottom, 10),
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
export type Size = {
|
|
2
|
+
width: number
|
|
3
|
+
height: number
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function getContainerSize(ele: HTMLElement): Size {
|
|
7
|
+
if (!ele) {
|
|
8
|
+
return { width: 0, height: 0 }
|
|
9
|
+
}
|
|
10
|
+
const style = getComputedStyle(ele)
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
width:
|
|
14
|
+
(ele.clientWidth || parseInt(style.width, 10)) -
|
|
15
|
+
parseInt(style.paddingLeft, 10) -
|
|
16
|
+
parseInt(style.paddingRight, 10),
|
|
17
|
+
height:
|
|
18
|
+
(ele.clientHeight || parseInt(style.height, 10)) -
|
|
19
|
+
parseInt(style.paddingTop, 10) -
|
|
20
|
+
parseInt(style.paddingBottom, 10),
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { registerTheme } from '@antv/g2'
|
|
2
|
-
import theme, { createThemeByStyleSheet } from './theme'
|
|
3
|
-
|
|
4
|
-
// 注册深蓝主题
|
|
5
|
-
registerTheme('ocean', createThemeByStyleSheet(theme.ocean))
|
|
6
|
-
// 注册橙色主题
|
|
7
|
-
registerTheme('sunset', createThemeByStyleSheet(theme.sunset))
|
|
8
|
-
|
|
9
|
-
export { Line } from './chart/line/index'
|
|
10
|
-
export { Pie } from './chart/pie/index'
|
|
11
|
-
export { Bar } from './chart/bar/index'
|
|
1
|
+
import { registerTheme } from '@antv/g2'
|
|
2
|
+
import theme, { createThemeByStyleSheet } from './theme'
|
|
3
|
+
|
|
4
|
+
// 注册深蓝主题
|
|
5
|
+
registerTheme('ocean', createThemeByStyleSheet(theme.ocean))
|
|
6
|
+
// 注册橙色主题
|
|
7
|
+
registerTheme('sunset', createThemeByStyleSheet(theme.sunset))
|
|
8
|
+
|
|
9
|
+
export { Line } from './chart/line/index'
|
|
10
|
+
export { Pie } from './chart/pie/index'
|
|
11
|
+
export { Bar } from './chart/bar/index'
|