@@ -3,53 +3,46 @@ import { IGroup } from '@antv/g-base';
3
3
import { reduce , isNumber , mix } from '@antv/util' ;
4
4
import { transform } from '../../../utils/matrix' ;
5
5
import { Point } from '../../../types' ;
6
- import { ShapeStyle } from '../../../types' ;
7
-
8
- function addFillAttrs ( attrs : ShapeStyle , cfg : any ) {
9
- if ( cfg . color && ! attrs . fill ) {
10
- attrs . fill = cfg . color ;
11
- }
12
- if ( isNumber ( cfg . opacity ) ) {
13
- attrs . opacity = attrs . fillOpacity = cfg . opacity ;
14
- }
15
- }
16
-
17
- function addStrokeAttrs ( attrs : ShapeStyle , cfg : any ) {
18
- if ( cfg . color && ! attrs . stroke ) {
19
- attrs . stroke = cfg . color ;
20
- }
21
- if ( isNumber ( cfg . opacity ) ) {
22
- attrs . opacity = attrs . strokeOpacity = cfg . opacity ;
23
- }
24
- }
25
6
26
7
function lerp ( a : number , b : number , factor : number ) {
27
8
return ( 1 - factor ) * a + factor * b ;
28
9
}
29
10
30
- const getFillAttrs = ( cfg ) => {
31
- const defaultAttrs = {
32
- lineWidth : 0 ,
33
- fillOpacity : 0.85 ,
34
- } ;
35
- const attrs = mix ( { } , defaultAttrs , cfg . style ) ;
36
- addFillAttrs ( attrs , cfg ) ;
37
- if ( cfg . color && ! attrs . stroke ) {
38
- attrs . stroke = attrs . stroke || cfg . color ;
11
+ /**
12
+ * 波浪的 attrs
13
+ * @param cfg
14
+ */
15
+ function getFillAttrs ( cfg ) {
16
+ const attrs = { opacity : 1 , ... cfg . style } ;
17
+
18
+ if ( cfg . color && ! attrs . fill ) {
19
+ attrs . fill = cfg . color ;
39
20
}
21
+
40
22
return attrs ;
41
- } ;
23
+ }
42
24
43
- const getLineAttrs = ( cfg ) => {
25
+ /**
26
+ * 圆圈的 attrs
27
+ * @param cfg
28
+ */
29
+ function getLineAttrs ( cfg ) {
44
30
const defaultAttrs = {
45
31
fill : '#fff' ,
46
32
fillOpacity : 0 ,
47
33
lineWidth : 2 ,
48
34
} ;
49
35
const attrs = mix ( { } , defaultAttrs , cfg . style ) ;
50
- addStrokeAttrs ( attrs , cfg ) ;
36
+
37
+ if ( cfg . color && ! attrs . stroke ) {
38
+ attrs . stroke = cfg . color ;
39
+ }
40
+ if ( isNumber ( cfg . opacity ) ) {
41
+ attrs . opacity = attrs . strokeOpacity = cfg . opacity ;
42
+ }
43
+
51
44
return attrs ;
52
- } ;
45
+ }
53
46
54
47
/**
55
48
* 用贝塞尔曲线模拟正弦波
@@ -65,11 +58,11 @@ const getLineAttrs = (cfg) => {
65
58
*
66
59
* whose positions are a: (0, 0), b: (0.5, 0.5), c: (1, 1), d: (PI / 2, 1)
67
60
*
68
- * @param { number } x x position of the left-most point (a)
69
- * @param { number } stage 0-3, stating which part of the wave it is
70
- * @param { number } waveLength wave length of the sine wave
71
- * @param { number } amplitude wave amplitude
72
- * @return { Array } 正弦片段曲线
61
+ * @param x x position of the left-most point (a)
62
+ * @param stage 0-3, stating which part of the wave it is
63
+ * @param waveLength wave length of the sine wave
64
+ * @param amplitude wave amplitude
65
+ * @return 正弦片段曲线
73
66
*/
74
67
function getWaterWavePositions ( x : number , stage : number , waveLength : number , amplitude : number ) {
75
68
if ( stage === 0 ) {
@@ -101,14 +94,14 @@ function getWaterWavePositions(x: number, stage: number, waveLength: number, amp
101
94
}
102
95
/**
103
96
* 获取水波路径
104
- * @param { number } radius 半径
105
- * @param { number } waterLevel 水位
106
- * @param { number } waveLength 波长
107
- * @param { number } phase 相位
108
- * @param { number } amplitude 震幅
109
- * @param { number } cx 圆心x
110
- * @param { number } cy 圆心y
111
- * @return { Array } path 路径
97
+ * @param radius 半径
98
+ * @param waterLevel 水位
99
+ * @param waveLength 波长
100
+ * @param phase 相位
101
+ * @param amplitude 震幅
102
+ * @param cx 圆心x
103
+ * @param cy 圆心y
104
+ * @return path 路径
112
105
* @reference http://gitlab.alipay-inc.com/datavis/g6/blob/1.2.0/src/graph/utils/path.js#L135
113
106
*/
114
107
function getWaterWavePath (
@@ -191,16 +184,17 @@ function getWaterWavePath(
191
184
192
185
/**
193
186
* 添加水波
194
- * @param { number } x 中心x
195
- * @param { number } y 中心y
196
- * @param { number } level 水位等级 0~1
197
- * @param { number } waveCount 水波数
198
- * @param { number } colors 色值
199
- * @param { number } group 图组
200
- * @param { number } clip 用于剪切的图形
201
- * @param { number } radius 绘制图形的高度
187
+ * @param x 中心x
188
+ * @param y 中心y
189
+ * @param level 水位等级 0~1
190
+ * @param waveCount 水波数
191
+ * @param waveAttrs 色值
192
+ * @param group 图组
193
+ * @param clip 用于剪切的图形
194
+ * @param radius 绘制图形的高度
202
195
*/
203
- function addWaterWave ( x , y , level , waveCount , color , group , clip , radius ) {
196
+ function addWaterWave ( x , y , level , waveCount , waveAttrs , group , clip , radius ) {
197
+ const { fill, opacity } = waveAttrs ;
204
198
const bbox = clip . getBBox ( ) ;
205
199
const width = bbox . maxX - bbox . minX ;
206
200
const height = bbox . maxY - bbox . minY ;
@@ -211,8 +205,8 @@ function addWaterWave(x, y, level, waveCount, color, group, clip, radius) {
211
205
name : `wave-path-${ i } ` ,
212
206
attrs : {
213
207
path : getWaterWavePath ( radius , bbox . minY + height * level , width / 4 , 0 , width / lerp ( 56 , 64 , factor ) , x , y ) ,
214
- fill : color ,
215
- opacity : lerp ( 0.6 , 0.3 , factor ) ,
208
+ fill,
209
+ opacity : lerp ( 0.6 , 0.3 , factor ) * opacity ,
216
210
} ,
217
211
} ) ;
218
212
@@ -255,7 +249,7 @@ registerShape('interval', 'liquid-fill-gauge', {
255
249
256
250
// 保证半径是 画布宽高最小值的 radius 值
257
251
const radius = Math . min ( halfWidth , minXPoint . y * radio ) ;
258
- const { fill } = getFillAttrs ( cfg ) ;
252
+ const waveAttrs = getFillAttrs ( cfg ) ;
259
253
260
254
const waves = container . addGroup ( {
261
255
name : 'waves' ,
@@ -275,7 +269,7 @@ registerShape('interval', 'liquid-fill-gauge', {
275
269
center . y ,
276
270
1 - ( cfg . points [ 1 ] as Point ) . y , // cfg.y / (2 * cp.y),
277
271
3 ,
278
- fill ,
272
+ waveAttrs ,
279
273
waves ,
280
274
clipCircle ,
281
275
radius * 4
0 commit comments