Skip to content

Commit fd9ad5a

Browse files
authored
Feat/rect shape for liquid (#2430)
* feat(liquid): add one built-in shape rect * chore(liquid): add test case for rect shape * docs(liquid): add rect shape for built-in shape
1 parent 55842a6 commit fd9ad5a

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

__tests__/unit/plots/liquid/liquid-shape-spec.ts

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ describe('liquid', () => {
2626
name: 'circle',
2727
clipPath: [['M', 300, 16], ['A', 134, 134, 0, 1, 0, 300, 284], ['A', 134, 134, 0, 1, 0, 300, 16], ['Z']],
2828
},
29+
{
30+
name: 'rect',
31+
clipPath: [['M', 217.188, 16], ['L', 382.812, 16], ['L', 382.812, 284], ['L', 217.188, 284], ['Z']],
32+
},
2933
];
3034

3135
const shapeProps = {

docs/api/plots/liquid.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Liguid graphic style.
3535

3636
<description>**optional** _String | Function_ default: `circle`</description>
3737

38-
There are four built-in shapes for liquid plot: `circle | diamond | triangle | pin`. It aslo supports custom shape if shape is a callback function to build path.
38+
There are five built-in shapes for liquid plot: `circle | diamond | triangle | pin | rect`. It aslo supports custom shape if shape is a callback function to build path.
3939

4040
示例代码如下:
4141

docs/api/plots/liquid.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ order: 6
3535

3636
<description>**optional** _String | Function_ default: `circle`</description>
3737

38-
水波图有四种内置形状`circle | diamond | triangle | pin`。同时也支持自定义图形,这个时候需要传入一个构建 Path 的回调函数。
38+
水波图有五种内置形状`circle | diamond | triangle | pin | rect`。同时也支持自定义图形,这个时候需要传入一个构建 Path 的回调函数。
3939

4040
示例代码如下:
4141

src/plots/liquid/shapes/liquid.ts

+21
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ function triangle(x: number, y: number, width: number, height: number) {
347347
`;
348348
}
349349

350+
/**
351+
*
352+
* @param x 中心 x
353+
* @param y 中心 y
354+
* @param width 外接矩形的宽
355+
* @param height 外接矩形的高
356+
*/
357+
function rect(x: number, y: number, width: number, height: number) {
358+
const GOLDEN_SECTION_RATIO = 0.618;
359+
const h = height / 2;
360+
const w = (width / 2) * GOLDEN_SECTION_RATIO;
361+
return `
362+
M ${x - w} ${y - h}
363+
L ${x + w} ${y - h}
364+
L ${x + w} ${y + h}
365+
L ${x - w} ${y + h}
366+
Z
367+
`;
368+
}
369+
350370
registerShape('interval', 'liquid-fill-gauge', {
351371
draw(cfg: any, container: IGroup) {
352372
const cx = 0.5;
@@ -382,6 +402,7 @@ registerShape('interval', 'liquid-fill-gauge', {
382402
circle,
383403
diamond,
384404
triangle,
405+
rect,
385406
};
386407
const buildPath = typeof shape === 'function' ? shape : builtInShapeByName[shape] || builtInShapeByName['circle'];
387408
const shapePath = buildPath(center.x, center.y, innerRadius * 2, innerRadius * 2);

0 commit comments

Comments
 (0)