Skip to content

feat(Liquid): Add shapeStyle config #3411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/api/plots/liquid.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function shape(x: number, y: number, width: number, height: number) {

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

#### shapeStyle

<description>**optional** _StyleAttr | Function_</description>

Shape graphic style.

<embed src="@/docs/common/shape-style.en.md"></embed>

#### pattern ✨

<description>**optional** _object | Function_</description>
Expand Down
8 changes: 8 additions & 0 deletions docs/api/plots/liquid.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ function shape(x: number, y: number, width: number, height: number) {

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

#### shapeStyle

<description>**optional** _StyleAttr | Function_</description>

形状的样式。

<embed src="@/docs/common/shape-style.zh.md"></embed>

#### pattern ✨

<description>**optional** _object | Function_</description>
Expand Down
3 changes: 3 additions & 0 deletions examples/progress-plots/liquid/demo/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const liquidPlot = new Liquid('container', {
['Z'],
];
},
shapeStyle: {
fill: 'pink',
},
outline: {
border: 4,
distance: 8,
Expand Down
2 changes: 1 addition & 1 deletion examples/progress-plots/liquid/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"zh": "形状自定义的水波图",
"en": "Liquid plot - custom shape"
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*9MbOSZwdKmYAAAAAAAAAAAAAARQnAQ"
"screenshot": "https://mdn.alipayobjects.com/huamei_twhmfu/afts/img/A*NvzFTJjCr3MAAAAAAAAAAAAADu2HAQ/original"
},
{
"filename": "style.ts",
Expand Down
3 changes: 2 additions & 1 deletion src/plots/liquid/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getLiquidData } from './utils';
*/
function geometry(params: Params<LiquidOptions>): Params<LiquidOptions> {
const { chart, options } = params;
const { percent, liquidStyle, radius, outline, wave, shape, animation } = options;
const { percent, liquidStyle, radius, outline, wave, shape, shapeStyle, animation } = options;

chart.scale({
percent: {
Expand Down Expand Up @@ -48,6 +48,7 @@ function geometry(params: Params<LiquidOptions>): Params<LiquidOptions> {
outline,
wave,
shape,
shapeStyle,
background,
animation,
};
Expand Down
21 changes: 16 additions & 5 deletions src/plots/liquid/shapes/liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function addWaterWave(

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

// 画波
const wave = group.addShape('path', {
Expand Down Expand Up @@ -389,7 +389,7 @@ registerShape('interval', 'liquid-fill-gauge', {
const cy = 0.5;

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

// 1. 绘制一个波
// 1. 当 shapeStyle 不为空时,绘制形状样式作为背景
if (shapeStyle) {
container.addShape('path', {
name: 'shape',
attrs: {
path: shapePath,
...shapeStyle,
},
});
}

// 2. 绘制一个波
const waves = container.addGroup({
name: 'waves',
});
Expand All @@ -444,7 +455,7 @@ registerShape('interval', 'liquid-fill-gauge', {
animation
);

// 2. 绘制一个 distance 宽的 border
// 5. 绘制一个 distance 宽的 border
container.addShape('path', {
name: 'distance',
attrs: {
Expand All @@ -455,7 +466,7 @@ registerShape('interval', 'liquid-fill-gauge', {
},
});

// 3. 绘制一个 border 宽的 border
// 6. 绘制一个 border 宽的 border
container.addShape('path', {
name: 'wrap',
attrs: mix(outlineAttrs, {
Expand Down
5 changes: 5 additions & 0 deletions src/plots/liquid/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export interface LiquidOptions extends Omit<Options, 'data'> {
* @title 水波图的样式
*/
readonly liquidStyle?: StyleAttr;
/**
* @title 形状的样式
*/
readonly shapeStyle?: StyleAttr;
/**
* @title 指标文本组件
*/
Expand Down Expand Up @@ -88,6 +92,7 @@ export type CustomInfo = {
outline?: LiquidOptions['outline'];
wave?: LiquidOptions['wave'];
shape?: LiquidOptions['shape'];
shapeStyle?: LiquidOptions['shapeStyle'];
background?: string;
animation?: LiquidOptions['animation'];
};