@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.
@@ -1,209 +1,211 @@
1
- import _ from 'lodash'
2
- import { Instance } from '../../../types/common'
3
- import { flatData, getPositionAndColor } from './utils'
4
- import themes from '../../../theme'
5
-
6
- /**
7
- * Geek Blue 极客蓝 #5B8FF9
8
- * Cyan 翡翠绿 #5AD8A6
9
- * Grey 商务灰 #5D7092
10
- * Sunrise Yellow 旭日黄 #F6BD16
11
- * Dust Red 薄暮红 #E86452
12
- * Daybreak Blue 破晓蓝 #6DC8EC
13
- * Golden Purple 罗兰紫 #945FB9
14
- * Sunset Orange 落日橘 #FF9845
15
- * Dark Green 天水青 #1E9493
16
- * Magenta 桃花粉 #FF99C3
17
- */
18
- const colors = [
19
- '#5B8FF9',
20
- '#5AD8A6',
21
- '#5D7092',
22
- '#F6BD16',
23
- '#E86452',
24
- '#6DC8EC',
25
- '#945FB9',
26
- '#FF9845',
27
- '#1E9493',
28
- '#FF99C3',
29
- ]
30
-
31
- /**
32
- * - 几何标记 Geometry
33
- * - 度量 Scale
34
- * - 坐标系 Coordinate
35
- * - 可视化组件 Component
36
- * - 包括坐标轴 Axis,
37
- * - 图例 Legend,
38
- * - 提示信息 Tooltip,
39
- * - 图形标记 Annotation,
40
- * - 滑动条 Slider 等。
41
- */
42
-
43
- function geometry(params: Instance) {
44
- const { chart, options } = params
45
-
46
- const { position, color } = getPositionAndColor(params)
47
-
48
- let geometry
49
- if (color) {
50
- geometry = chart.line().position(position).color(color)
51
- } else {
52
- geometry = chart.line().position(position)
53
- }
54
-
55
- return { ...params, geometry }
56
- }
57
-
58
- function scale(params: Instance) {
59
- const { chart, options } = params
60
-
61
- const { position, data, xFieldName, yFieldName, scale = {} } = options
62
- if (_.isArray(position) || !position) {
63
- if (data.length) {
64
- const x = position ? position[0].split('*')[0] : xFieldName
65
- const d = flatData(data, x, yFieldName)
66
- chart.scale({
67
- value: {
68
- nice: true,
69
- formatter: (value) => value,
70
- },
71
- ...scale,
72
- })
73
- chart.scale({
74
- [x]: {
75
- nice: true,
76
- formatter: (value) => value,
77
- },
78
- ...scale,
79
- })
80
- chart.data(d)
81
- }
82
- } else {
83
- const y = position.split('*')[1]
84
- // TODO 通用配置 y轴nice: true
85
- chart.scale({
86
- [y]: {
87
- nice: true,
88
- },
89
- ...scale,
90
- })
91
- }
92
-
93
- return params
94
- }
95
-
96
- function axis(params: Instance) {
97
- const { chart, options } = params
98
- const { position, color } = options
99
- if (_.isArray(position)) {
100
- chart.axis('value', {
101
- label: {
102
- formatter: (text) => text,
103
- },
104
- })
105
- }
106
- return params
107
- }
108
-
109
- function annotation(params: Instance) {
110
- const { chart, options } = params
111
- const { data, annotation } = options
112
- // 辅助线
113
- if (annotation) {
114
- const { text, value } = annotation
115
- const yPosition = typeof value === 'string' ? value : value(data)
116
- chart.annotation().line({
117
- start: ['min', yPosition],
118
- end: ['max', yPosition],
119
- style: {
120
- stroke: 'red',
121
- lineWidth: 1,
122
- lineDash: [3, 3],
123
- },
124
- text: {
125
- position: 'right',
126
- content: text,
127
- },
128
- })
129
- }
130
-
131
- return params
132
- }
133
-
134
- function tooltip(params: Instance) {
135
- const { chart } = params
136
- // tooltip样式
137
- chart.tooltip({
138
- showMarkers: true,
139
- showCrosshairs: true,
140
- shared: true,
141
- domStyles: {
142
- 'g2-tooltip-marker': {
143
- width: '10px',
144
- height: '2px',
145
- borderRadius: '0%',
146
- display: 'inline-block',
147
- marginBottom: '4px',
148
- marginRight: '6px',
149
- },
150
- },
151
- })
152
-
153
- return params
154
- }
155
-
156
- function legend(params: Instance) {
157
- const { chart, options } = params
158
- const { legend } = options
159
-
160
- if (legend !== undefined) {
161
- chart.legend(legend)
162
- }
163
-
164
- return params
165
- }
166
-
167
- function theme(params: Instance) {
168
- const { chart, options, geometry } = params
169
- const { theme } = options
170
- if (theme) {
171
- const themeConfig = themes[theme as 'ocean'].chart
172
-
173
- if (themeConfig) {
174
- // ---------- geometry配置 ----------------
175
- geometry!.shape(themeConfig.line.shape).style(themeConfig.line.style)
176
-
177
- // ---------- tiptop配置 ----------------
178
- chart.tooltip({
179
- showMarkers: true,
180
- showCrosshairs: true,
181
- shared: true,
182
- domStyles: {
183
- 'g2-tooltip-marker': {
184
- display: 'none',
185
- },
186
- },
187
- })
188
-
189
- // ---------- area图 ----------------
190
- if (themeConfig.line.area) {
191
- const { position, color } = getPositionAndColor(params)
192
- chart
193
- .area()
194
- .position(position)
195
- .color(color)
196
- .shape(themeConfig.line.area.shape)
197
- .style({
198
- fill: themeConfig.line.area.fill,
199
- fillOpacity: 1,
200
- })
201
- }
202
- }
203
- }
204
- return params
205
- }
206
-
207
- export function processor(params: Instance) {
208
- return _.flow(geometry, annotation, tooltip, scale, axis, legend, theme)(params)
209
- }
1
+ import _ from 'lodash'
2
+ import { Instance } from '../../../types/common'
3
+ import { flatData, getPositionAndColor } from './utils'
4
+ import themes from '../../../theme'
5
+
6
+ /**
7
+ * Geek Blue 极客蓝 #5B8FF9
8
+ * Cyan 翡翠绿 #5AD8A6
9
+ * Grey 商务灰 #5D7092
10
+ * Sunrise Yellow 旭日黄 #F6BD16
11
+ * Dust Red 薄暮红 #E86452
12
+ * Daybreak Blue 破晓蓝 #6DC8EC
13
+ * Golden Purple 罗兰紫 #945FB9
14
+ * Sunset Orange 落日橘 #FF9845
15
+ * Dark Green 天水青 #1E9493
16
+ * Magenta 桃花粉 #FF99C3
17
+ */
18
+ const colors = [
19
+ '#5B8FF9',
20
+ '#5AD8A6',
21
+ '#5D7092',
22
+ '#F6BD16',
23
+ '#E86452',
24
+ '#6DC8EC',
25
+ '#945FB9',
26
+ '#FF9845',
27
+ '#1E9493',
28
+ '#FF99C3',
29
+ ]
30
+
31
+ /**
32
+ * - 几何标记 Geometry
33
+ * - 度量 Scale
34
+ * - 坐标系 Coordinate
35
+ * - 可视化组件 Component
36
+ * - 包括坐标轴 Axis,
37
+ * - 图例 Legend,
38
+ * - 提示信息 Tooltip,
39
+ * - 图形标记 Annotation,
40
+ * - 滑动条 Slider 等。
41
+ */
42
+
43
+ function geometry(params: Instance) {
44
+ const { chart, options } = params
45
+
46
+ const { position, color } = getPositionAndColor(params)
47
+
48
+ let geometry
49
+ if (color) {
50
+ geometry = chart.line().position(position).color(color)
51
+ } else {
52
+ geometry = chart.line().position(position)
53
+ }
54
+
55
+ return { ...params, geometry }
56
+ }
57
+
58
+ function scale(params: Instance) {
59
+ const { chart, options } = params
60
+
61
+ const { position, data, xFieldName, yFieldName, scale = {} } = options
62
+ if (_.isArray(position) || !position) {
63
+ if (data.length) {
64
+ const x = position ? position[0].split('*')[0] : xFieldName
65
+ const d = flatData(data, x, yFieldName)
66
+ chart.scale({
67
+ value: {
68
+ nice: true,
69
+ formatter: (value) => value,
70
+ },
71
+ ...scale,
72
+ })
73
+ chart.scale({
74
+ [x]: {
75
+ nice: true,
76
+ formatter: (value) => value,
77
+ },
78
+ ...scale,
79
+ })
80
+ chart.data(d)
81
+ }
82
+ } else {
83
+ const y = position.split('*')[1]
84
+ // TODO 通用配置 y轴nice: true
85
+ chart.scale({
86
+ [y]: {
87
+ nice: true,
88
+ },
89
+ ...scale,
90
+ })
91
+ }
92
+
93
+ return params
94
+ }
95
+
96
+ function axis(params: Instance) {
97
+ const { chart, options } = params
98
+ const { position, color } = options
99
+ if (_.isArray(position)) {
100
+ chart.axis('value', {
101
+ label: {
102
+ formatter: (text) => text,
103
+ },
104
+ })
105
+ }
106
+ return params
107
+ }
108
+
109
+ function annotation(params: Instance) {
110
+ const { chart, options } = params
111
+ const { data, annotation } = options
112
+ // 辅助线
113
+ if (annotation) {
114
+ const { text, value } = annotation
115
+ const yPosition = typeof value === 'string' ? value : value(data)
116
+ chart.annotation().line({
117
+ start: ['min', yPosition],
118
+ end: ['max', yPosition],
119
+ style: {
120
+ stroke: 'red',
121
+ lineWidth: 1,
122
+ lineDash: [3, 3],
123
+ },
124
+ text: {
125
+ position: 'right',
126
+ content: text,
127
+ },
128
+ })
129
+ }
130
+
131
+ return params
132
+ }
133
+
134
+ function tooltip(params: Instance) {
135
+ const { chart } = params
136
+ // tooltip样式
137
+ chart.tooltip({
138
+ showMarkers: true,
139
+ showCrosshairs: true,
140
+ shared: true,
141
+ domStyles: {
142
+ 'g2-tooltip-marker': {
143
+ width: '10px',
144
+ height: '2px',
145
+ borderRadius: '0%',
146
+ display: 'inline-block',
147
+ marginBottom: '4px',
148
+ marginRight: '6px',
149
+ },
150
+ },
151
+ ...(params?.options?.customTooltip || {}),
152
+ })
153
+
154
+ return params
155
+ }
156
+
157
+ function legend(params: Instance) {
158
+ const { chart, options } = params
159
+ const { legend } = options
160
+
161
+ if (legend !== undefined) {
162
+ chart.legend(legend)
163
+ }
164
+
165
+ return params
166
+ }
167
+
168
+ function theme(params: Instance) {
169
+ const { chart, options, geometry } = params
170
+ const { theme } = options
171
+ if (theme) {
172
+ const themeConfig = themes[theme as 'ocean'].chart
173
+
174
+ if (themeConfig) {
175
+ // ---------- geometry配置 ----------------
176
+ geometry!.shape(themeConfig.line.shape).style(themeConfig.line.style)
177
+
178
+ // ---------- tiptop配置 ----------------
179
+ chart.tooltip({
180
+ showMarkers: true,
181
+ showCrosshairs: true,
182
+ shared: true,
183
+ domStyles: {
184
+ 'g2-tooltip-marker': {
185
+ display: 'none',
186
+ },
187
+ },
188
+ ...(options?.customTooltip || {}),
189
+ })
190
+
191
+ // ---------- area图 ----------------
192
+ if (themeConfig.line.area) {
193
+ const { position, color } = getPositionAndColor(params)
194
+ chart
195
+ .area()
196
+ .position(position)
197
+ .color(color)
198
+ .shape(themeConfig.line.area.shape)
199
+ .style({
200
+ fill: themeConfig.line.area.fill,
201
+ fillOpacity: 1,
202
+ })
203
+ }
204
+ }
205
+ }
206
+ return params
207
+ }
208
+
209
+ export function processor(params: Instance) {
210
+ return _.flow(geometry, annotation, tooltip, scale, axis, legend, theme)(params)
211
+ }
@@ -1,9 +1,9 @@
1
- import { Base } from '../../base/index'
2
- import { processor } from './config'
3
-
4
- export default class Line extends Base {
5
- name = 'line'
6
- getProcessor() {
7
- return processor
8
- }
9
- }
1
+ import { Base } from '../../base/index'
2
+ import { processor } from './config'
3
+
4
+ export default class Line extends Base {
5
+ name = 'line'
6
+ getProcessor() {
7
+ return processor
8
+ }
9
+ }
@@ -1,49 +1,49 @@
1
- import _ from 'lodash'
2
- import { ChartOptions } from '../../../types/common'
3
-
4
- export function flatData(data: any, x: string, position: string[] | string[][]) {
5
- const result: { [key: string]: any }[] = []
6
- _.forEach(data, (item) => {
7
- _.forEach(position, (pos) => {
8
- let y = ''
9
- let type = y
10
- if (_.isArray(pos)) {
11
- type = pos[1]
12
- y = pos[0]
13
- } else {
14
- y = (pos as string).split('*')[1]
15
- }
16
-
17
- result.push({
18
- [x]: item[x],
19
- value: item[y],
20
- type,
21
- })
22
- })
23
- })
24
- return result
25
- }
26
-
27
- export function getPosition(xFieldName: string, yFieldName: string[][]) {
28
- const position: string[] = []
29
- yFieldName.map((field) => {
30
- const name = field[0]
31
- position.push(`${xFieldName}*${name}`)
32
- })
33
- return position
34
- }
35
-
36
- export function getPositionAndColor(params: ChartOptions) {
37
- const { options } = params
38
- const { position, color, xFieldName, theme } = options
39
- const x = position ? position[0].split('*')[0] : xFieldName
40
-
41
- if (_.isArray(position) || !position) {
42
- return {
43
- position: `${x}*value`,
44
- color: 'type',
45
- }
46
- } else {
47
- return { position, color }
48
- }
49
- }
1
+ import _ from 'lodash'
2
+ import { ChartOptions } from '../../../types/common'
3
+
4
+ export function flatData(data: any, x: string, position: string[] | string[][]) {
5
+ const result: { [key: string]: any }[] = []
6
+ _.forEach(data, (item) => {
7
+ _.forEach(position, (pos) => {
8
+ let y = ''
9
+ let type = y
10
+ if (_.isArray(pos)) {
11
+ type = pos[1]
12
+ y = pos[0]
13
+ } else {
14
+ y = (pos as string).split('*')[1]
15
+ }
16
+
17
+ result.push({
18
+ [x]: item[x],
19
+ value: item[y],
20
+ type,
21
+ })
22
+ })
23
+ })
24
+ return result
25
+ }
26
+
27
+ export function getPosition(xFieldName: string, yFieldName: string[][]) {
28
+ const position: string[] = []
29
+ yFieldName.map((field) => {
30
+ const name = field[0]
31
+ position.push(`${xFieldName}*${name}`)
32
+ })
33
+ return position
34
+ }
35
+
36
+ export function getPositionAndColor(params: ChartOptions) {
37
+ const { options } = params
38
+ const { position, color, xFieldName, theme } = options
39
+ const x = position ? position[0].split('*')[0] : xFieldName
40
+
41
+ if (_.isArray(position) || !position) {
42
+ return {
43
+ position: `${x}*value`,
44
+ color: 'type',
45
+ }
46
+ } else {
47
+ return { position, color }
48
+ }
49
+ }
@@ -1,12 +1,12 @@
1
- import React, { FC, forwardRef, useRef, useEffect } from 'react'
2
- import _Line from './core'
3
- import useChart from '../../common/hooks/useChart'
4
- import { ChartProps, ChartOptions } from '../../types/common'
5
-
6
- const Line: FC<ChartProps> = forwardRef((props, ref) => {
7
- const { container } = useChart(_Line, props)
8
-
9
- return <div ref={container} />
10
- })
11
-
12
- export { Line }
1
+ import React, { FC, forwardRef, useRef, useEffect } from 'react'
2
+ import _Line from './core'
3
+ import useChart from '../../common/hooks/useChart'
4
+ import { ChartProps, ChartOptions } from '../../types/common'
5
+
6
+ const Line: FC<ChartProps> = forwardRef((props, ref) => {
7
+ const { container } = useChart(_Line, props)
8
+
9
+ return <div ref={container} />
10
+ })
11
+
12
+ export { Line }