@gm-pc/vision 1.27.0 → 1.27.1-beta.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 +259 -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 +139 -135
- package/src/chart/line/core/config.ts +211 -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
package/src/chart/base/index.ts
CHANGED
|
@@ -1,135 +1,139 @@
|
|
|
1
|
-
import { Chart } from '@antv/g2'
|
|
2
|
-
import { bind } from 'size-sensor'
|
|
3
|
-
import { ChartOptions, Instance } from '../../types/common'
|
|
4
|
-
import { getContainerSize } from '../../common/utils/dom'
|
|
5
|
-
import _ from 'lodash'
|
|
6
|
-
|
|
7
|
-
export abstract class Base {
|
|
8
|
-
chart: Chart
|
|
9
|
-
|
|
10
|
-
options: ChartOptions
|
|
11
|
-
|
|
12
|
-
container: HTMLElement
|
|
13
|
-
|
|
14
|
-
unbind: (() => void) | undefined
|
|
15
|
-
|
|
16
|
-
abstract name: string
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 处理配置,geometry annotation axis...
|
|
20
|
-
* */
|
|
21
|
-
abstract getProcessor(): (params: Instance) => Instance
|
|
22
|
-
|
|
23
|
-
constructor(container: string | HTMLElement, options: ChartOptions) {
|
|
24
|
-
this.container =
|
|
25
|
-
typeof container === 'string'
|
|
26
|
-
? (document.querySelector(container)! as HTMLElement)
|
|
27
|
-
: container
|
|
28
|
-
this.options = options
|
|
29
|
-
this.chart = null!
|
|
30
|
-
this.unbind = undefined
|
|
31
|
-
|
|
32
|
-
this.createG2()
|
|
33
|
-
|
|
34
|
-
this.bindSizeSensor()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
createG2() {
|
|
38
|
-
const { width, height, padding } = this.options
|
|
39
|
-
// 通用配置
|
|
40
|
-
this.chart = new Chart({
|
|
41
|
-
container: this.container,
|
|
42
|
-
width,
|
|
43
|
-
height,
|
|
44
|
-
autoFit: false,
|
|
45
|
-
appendPadding: padding || [24, 24, 24, 24],
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
initConfig() {
|
|
50
|
-
let { data, theme = '', position } = this.options
|
|
51
|
-
data = this.processData(data, position)
|
|
52
|
-
|
|
53
|
-
this.chart.data(data).theme(theme)
|
|
54
|
-
|
|
55
|
-
const processor = this.getProcessor()
|
|
56
|
-
processor({
|
|
57
|
-
chart: this.chart,
|
|
58
|
-
options: this.options,
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
processData(data: any, position: string) {
|
|
63
|
-
if (position) {
|
|
64
|
-
const [x, y] = position.split('*')
|
|
65
|
-
// 数字要转成number类型,antv要求
|
|
66
|
-
return _.map(data, (d) => {
|
|
67
|
-
d[x] = _.isNaN(+d[x]) ? d[x] : +d[x]
|
|
68
|
-
d[y] = _.isNaN(+d[y]) ? d[y] : +d[y]
|
|
69
|
-
return d
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
return data
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
render() {
|
|
76
|
-
this.chart.clear()
|
|
77
|
-
|
|
78
|
-
this.initConfig()
|
|
79
|
-
|
|
80
|
-
this.chart.render()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
updateOptions(options: ChartOptions) {
|
|
84
|
-
this.options = _.merge(options, this.options)
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.chart.
|
|
134
|
-
}
|
|
135
|
-
|
|
1
|
+
import { Chart } from '@antv/g2'
|
|
2
|
+
import { bind } from 'size-sensor'
|
|
3
|
+
import { ChartOptions, Instance } from '../../types/common'
|
|
4
|
+
import { getContainerSize } from '../../common/utils/dom'
|
|
5
|
+
import _ from 'lodash'
|
|
6
|
+
|
|
7
|
+
export abstract class Base {
|
|
8
|
+
chart: Chart
|
|
9
|
+
|
|
10
|
+
options: ChartOptions
|
|
11
|
+
|
|
12
|
+
container: HTMLElement
|
|
13
|
+
|
|
14
|
+
unbind: (() => void) | undefined
|
|
15
|
+
|
|
16
|
+
abstract name: string
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 处理配置,geometry annotation axis...
|
|
20
|
+
* */
|
|
21
|
+
abstract getProcessor(): (params: Instance) => Instance
|
|
22
|
+
|
|
23
|
+
constructor(container: string | HTMLElement, options: ChartOptions) {
|
|
24
|
+
this.container =
|
|
25
|
+
typeof container === 'string'
|
|
26
|
+
? (document.querySelector(container)! as HTMLElement)
|
|
27
|
+
: container
|
|
28
|
+
this.options = options
|
|
29
|
+
this.chart = null!
|
|
30
|
+
this.unbind = undefined
|
|
31
|
+
|
|
32
|
+
this.createG2()
|
|
33
|
+
|
|
34
|
+
this.bindSizeSensor()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
createG2() {
|
|
38
|
+
const { width, height, padding } = this.options
|
|
39
|
+
// 通用配置
|
|
40
|
+
this.chart = new Chart({
|
|
41
|
+
container: this.container,
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
44
|
+
autoFit: false,
|
|
45
|
+
appendPadding: padding || [24, 24, 24, 24],
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
initConfig() {
|
|
50
|
+
let { data, theme = '', position } = this.options
|
|
51
|
+
data = this.processData(data, position)
|
|
52
|
+
|
|
53
|
+
this.chart.data(data).theme(theme)
|
|
54
|
+
|
|
55
|
+
const processor = this.getProcessor()
|
|
56
|
+
processor({
|
|
57
|
+
chart: this.chart,
|
|
58
|
+
options: this.options,
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
processData(data: any, position: string) {
|
|
63
|
+
if (position) {
|
|
64
|
+
const [x, y] = position.split('*')
|
|
65
|
+
// 数字要转成number类型,antv要求
|
|
66
|
+
return _.map(data, (d) => {
|
|
67
|
+
d[x] = _.isNaN(+d[x]) ? d[x] : +d[x]
|
|
68
|
+
d[y] = _.isNaN(+d[y]) ? d[y] : +d[y]
|
|
69
|
+
return d
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
return data
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
this.chart.clear()
|
|
77
|
+
|
|
78
|
+
this.initConfig()
|
|
79
|
+
|
|
80
|
+
this.chart.render()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
updateOptions(options: ChartOptions) {
|
|
84
|
+
// this.options = _.merge(options, this.options)
|
|
85
|
+
this.options = {
|
|
86
|
+
...this.options,
|
|
87
|
+
...options,
|
|
88
|
+
}
|
|
89
|
+
this.render()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateData(data: any) {
|
|
93
|
+
this.options.data = data
|
|
94
|
+
this.render()
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
unbindSizeSensor() {
|
|
98
|
+
if (this.unbind) {
|
|
99
|
+
this.unbind()
|
|
100
|
+
this.unbind = undefined
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
bindSizeSensor() {
|
|
105
|
+
if (this.unbind) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const { autoFit = true } = this.options
|
|
110
|
+
if (autoFit) {
|
|
111
|
+
this.unbind = bind(this.container, () => {
|
|
112
|
+
// 获取最新的宽高信息
|
|
113
|
+
const { width, height } = getContainerSize(this.container)
|
|
114
|
+
|
|
115
|
+
// 主要是防止绑定的时候触发 resize 回调
|
|
116
|
+
if (width !== this.chart.width || height !== this.chart.height) {
|
|
117
|
+
this.triggerResize()
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
triggerResize() {
|
|
124
|
+
// 解决pie宽高变化后导致annotation没有重写render
|
|
125
|
+
if (this.name === 'pie') {
|
|
126
|
+
this.render()
|
|
127
|
+
}
|
|
128
|
+
this.chart.forceFit()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
destroy() {
|
|
132
|
+
this.unbindSizeSensor()
|
|
133
|
+
this.chart.destroy()
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
resize() {
|
|
137
|
+
this.chart.forceFit()
|
|
138
|
+
}
|
|
139
|
+
}
|