Skip to content

Commit f4e797f

Browse files
authored
feat(Liquid): Add shapeStyle config (#3411)
* feat(Liquid): Add shapeStyle config * fix(Liquid): factor should be 1 when waveCount <= 1 Co-authored-by: 诸岳 <[email protected]>
1 parent b3b51ba commit f4e797f

File tree

7 files changed

+43
-7
lines changed

7 files changed

+43
-7
lines changed

docs/api/plots/liquid.en.md

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ function shape(x: number, y: number, width: number, height: number) {
6262

6363
<embed src="@/docs/common/color.en.md"></embed>
6464

65+
#### shapeStyle
66+
67+
<description>**optional** _StyleAttr | Function_</description>
68+
69+
Shape graphic style.
70+
71+
<embed src="@/docs/common/shape-style.en.md"></embed>
72+
6573
#### pattern ✨
6674

6775
<description>**optional** _object | Function_</description>

docs/api/plots/liquid.zh.md

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ function shape(x: number, y: number, width: number, height: number) {
6262

6363
<embed src="@/docs/common/color.zh.md"></embed>
6464

65+
#### shapeStyle
66+
67+
<description>**optional** _StyleAttr | Function_</description>
68+
69+
形状的样式。
70+
71+
<embed src="@/docs/common/shape-style.zh.md"></embed>
72+
6573
#### pattern ✨
6674

6775
<description>**optional** _object | Function_</description>

examples/progress-plots/liquid/demo/custom.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const liquidPlot = new Liquid('container', {
1515
['Z'],
1616
];
1717
},
18+
shapeStyle: {
19+
fill: 'pink',
20+
},
1821
outline: {
1922
border: 4,
2023
distance: 8,

examples/progress-plots/liquid/demo/meta.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"zh": "形状自定义的水波图",
5151
"en": "Liquid plot - custom shape"
5252
},
53-
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*9MbOSZwdKmYAAAAAAAAAAAAAARQnAQ"
53+
"screenshot": "https://mdn.alipayobjects.com/huamei_twhmfu/afts/img/A*NvzFTJjCr3MAAAAAAAAAAAAADu2HAQ/original"
5454
},
5555
{
5656
"filename": "style.ts",

src/plots/liquid/adaptor.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { getLiquidData } from './utils';
1313
*/
1414
function geometry(params: Params<LiquidOptions>): Params<LiquidOptions> {
1515
const { chart, options } = params;
16-
const { percent, liquidStyle, radius, outline, wave, shape, animation } = options;
16+
const { percent, liquidStyle, radius, outline, wave, shape, shapeStyle, animation } = options;
1717

1818
chart.scale({
1919
percent: {
@@ -48,6 +48,7 @@ function geometry(params: Params<LiquidOptions>): Params<LiquidOptions> {
4848
outline,
4949
wave,
5050
shape,
51+
shapeStyle,
5152
background,
5253
animation,
5354
};

src/plots/liquid/shapes/liquid.ts

+16-5
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function addWaterWave(
223223

224224
// 循环 waveCount 个数
225225
for (let idx = 0; idx < waveCount; idx++) {
226-
const factor = waveCount <= 1 ? 0 : idx / (waveCount - 1);
226+
const factor = waveCount <= 1 ? 1 : idx / (waveCount - 1);
227227

228228
// 画波
229229
const wave = group.addShape('path', {
@@ -389,7 +389,7 @@ registerShape('interval', 'liquid-fill-gauge', {
389389
const cy = 0.5;
390390

391391
const { customInfo } = cfg;
392-
const { radius: radio, shape, background, animation } = customInfo as CustomInfo;
392+
const { radius: radio, shape, shapeStyle, background, animation } = customInfo as CustomInfo;
393393
const outline: LiquidOptions['outline'] = customInfo.outline;
394394
const wave: LiquidOptions['wave'] = customInfo.wave;
395395
const { border, distance } = outline;
@@ -417,7 +417,18 @@ registerShape('interval', 'liquid-fill-gauge', {
417417
const buildPath = typeof shape === 'function' ? shape : builtInShapeByName[shape] || builtInShapeByName['circle'];
418418
const shapePath = buildPath(center.x, center.y, innerRadius * 2, innerRadius * 2);
419419

420-
// 1. 绘制一个波
420+
// 1. 当 shapeStyle 不为空时,绘制形状样式作为背景
421+
if (shapeStyle) {
422+
container.addShape('path', {
423+
name: 'shape',
424+
attrs: {
425+
path: shapePath,
426+
...shapeStyle,
427+
},
428+
});
429+
}
430+
431+
// 2. 绘制一个波
421432
const waves = container.addGroup({
422433
name: 'waves',
423434
});
@@ -444,7 +455,7 @@ registerShape('interval', 'liquid-fill-gauge', {
444455
animation
445456
);
446457

447-
// 2. 绘制一个 distance 宽的 border
458+
// 5. 绘制一个 distance 宽的 border
448459
container.addShape('path', {
449460
name: 'distance',
450461
attrs: {
@@ -455,7 +466,7 @@ registerShape('interval', 'liquid-fill-gauge', {
455466
},
456467
});
457468

458-
// 3. 绘制一个 border 宽的 border
469+
// 6. 绘制一个 border 宽的 border
459470
container.addShape('path', {
460471
name: 'wrap',
461472
attrs: mix(outlineAttrs, {

src/plots/liquid/types.ts

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export interface LiquidOptions extends Omit<Options, 'data'> {
6161
* @title 水波图的样式
6262
*/
6363
readonly liquidStyle?: StyleAttr;
64+
/**
65+
* @title 形状的样式
66+
*/
67+
readonly shapeStyle?: StyleAttr;
6468
/**
6569
* @title 指标文本组件
6670
*/
@@ -88,6 +92,7 @@ export type CustomInfo = {
8892
outline?: LiquidOptions['outline'];
8993
wave?: LiquidOptions['wave'];
9094
shape?: LiquidOptions['shape'];
95+
shapeStyle?: LiquidOptions['shapeStyle'];
9196
background?: string;
9297
animation?: LiquidOptions['animation'];
9398
};

0 commit comments

Comments
 (0)