Skip to content
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

feat: add mark.liquid #5508

Merged
merged 6 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,12 @@ export { alphabetIntervalTitleAuto } from './alphabet-interval-title-auto';
export { alphabetIntervalAutoPaddingLabelHide } from './alphabet-interval-auto-padding-label-hide';
export { settleWeatherCellLineXY } from './seattle-weather-cell-lineXY';
export { alphabetIntervalFunnelConnectorLabel } from './alphabet-interval-funnel-connector-label';
export { liquidDefault } from './liquid-default';
export { liquidPin } from './liquid-pin';
export { liquidRect } from './liquid-rect';
export { liquidCircle } from './liquid-circle';
export { liquidDiamond } from './liquid-diamond';
export { liquidTriangle } from './liquid-triangle';
export { liquidCustomShape } from './liquid-custom-shape';
export { alphabetIntervalAxisOptions } from './alphabet-interval-axis-options';
export { profitIntervalAxisTransform } from './profit-interval-axis-transform';
15 changes: 15 additions & 0 deletions __tests__/plots/static/liquid-circle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { G2Spec } from '../../../src';

export function liquidCircle(): G2Spec {
return {
type: 'liquid',
data: {
value: {
percent: 0.3,
},
},
style: {
shape: 'circle',
},
};
}
32 changes: 32 additions & 0 deletions __tests__/plots/static/liquid-custom-shape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { G2Spec } from '../../../src';

export function liquidCustomShape(): G2Spec {
return {
type: 'liquid',
autoFit: true,
data: { value: { percent: 0.3 } },
style: {
shape: (x, y, r) => {
const path = [] as any;
const w = r * 2;
for (let i = 0; i < 5; i++) {
path.push([
i === 0 ? 'M' : 'L',
(Math.cos(((18 + i * 72) * Math.PI) / 180) * w) / 2 + x,
(-Math.sin(((18 + i * 72) * Math.PI) / 180) * w) / 2 + y,
]);
path.push([
'L',
(Math.cos(((54 + i * 72) * Math.PI) / 180) * w) / 4 + x,
(-Math.sin(((54 + i * 72) * Math.PI) / 180) * w) / 4 + y,
]);
}
path.push(['Z']);
return path;
},
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
},
};
}
14 changes: 14 additions & 0 deletions __tests__/plots/static/liquid-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { G2Spec } from '../../../src';

export function liquidDefault(): G2Spec {
return {
type: 'liquid',
autoFit: true,
data: { value: { percent: 0.3 } },
style: {
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
},
};
}
15 changes: 15 additions & 0 deletions __tests__/plots/static/liquid-diamond.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { G2Spec } from '../../../src';

export function liquidDiamond(): G2Spec {
return {
type: 'liquid',
data: {
value: {
percent: 0.3,
},
},
style: {
shape: 'diamond',
},
};
}
19 changes: 19 additions & 0 deletions __tests__/plots/static/liquid-pin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { G2Spec } from '../../../src';

export function liquidPin(): G2Spec {
return {
type: 'liquid',
data: {
value: {
percent: 0.7,
},
},
style: {
shape: 'pin',
textFill: '#fff',
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
},
};
}
15 changes: 15 additions & 0 deletions __tests__/plots/static/liquid-rect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { G2Spec } from '../../../src';

export function liquidRect(): G2Spec {
return {
type: 'liquid',
data: {
value: {
percent: 0.3,
},
},
style: {
shape: 'rect',
},
};
}
15 changes: 15 additions & 0 deletions __tests__/plots/static/liquid-triangle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { G2Spec } from '../../../src';

export function liquidTriangle(): G2Spec {
return {
type: 'liquid',
data: {
value: {
percent: 0.3,
},
},
style: {
shape: 'triangle',
},
};
}
2 changes: 2 additions & 0 deletions __tests__/unit/api/chart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('Chart', () => {
expect(chart.tree().type).toBe('tree');
expect(chart.wordCloud().type).toBe('wordCloud');
expect(chart.gauge().type).toBe('gauge');
expect(chart.liquid().type).toBe('liquid');
expect(chart.density().type).toBe('density');
expect(chart.heatmap().type).toBe('heatmap');
expect(chart.axisX().type).toBe('axisX');
Expand Down Expand Up @@ -154,6 +155,7 @@ describe('Chart', () => {
{ type: 'tree' },
{ type: 'wordCloud' },
{ type: 'gauge' },
{ type: 'liquid' },
{ type: 'density' },
{ type: 'heatmap' },
{ type: 'axisX' },
Expand Down
6 changes: 6 additions & 0 deletions __tests__/unit/api/mark.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,12 @@ describe('mark.[node]()', () => {
expect(setCompositeOptions(node).value).toEqual(getOptions());
});

it('chart.liquid() should specify options by API', () => {
const node = chart.liquid();
expect(node.type).toBe('liquid');
expect(setCompositeOptions(node).value).toEqual(getOptions());
});

it('chart.axisX() should specify options by API', () => {
const node = chart.axisX();
expect(node.type).toBe('axisX');
Expand Down
3 changes: 2 additions & 1 deletion __tests__/unit/lib/plot.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { plotlib } from '../../../src/lib';
import { Boxplot, WordCloud, Gauge } from '../../../src/mark';
import { Boxplot, WordCloud, Gauge, Liquid } from '../../../src/mark';
import { Venn } from '../../../src/data';

describe('plotlib', () => {
Expand All @@ -9,6 +9,7 @@ describe('plotlib', () => {
'mark.boxplot': Boxplot,
'mark.wordCloud': WordCloud,
'mark.gauge': Gauge,
'mark.liquid': Liquid,
});
});
});
2 changes: 2 additions & 0 deletions __tests__/unit/lib/std.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
Gauge,
Density as DensityGeometry,
Heatmap,
Liquid,
} from '../../../src/mark';
import { Category10, Category20 } from '../../../src/palette';
import {
Expand Down Expand Up @@ -257,6 +258,7 @@ describe('stdlib', () => {
'mark.wordCloud': WordCloudGeometry,
'mark.density': DensityGeometry,
'mark.gauge': Gauge,
'mark.liquid': Liquid,
'mark.heatmap': Heatmap,
'palette.category10': Category10,
'palette.category20': Category20,
Expand Down
2 changes: 1 addition & 1 deletion site/docs/spec/mark/gauge.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ order: 1

## 开始使用

<img alt="wordCloud" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*hpjTRr6LM7IAAAAAAAAAAAAADmJ7AQ/original
<img alt="gauge" src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*hpjTRr6LM7IAAAAAAAAAAAAADmJ7AQ/original
" width="600" />

```js
Expand Down
6 changes: 6 additions & 0 deletions site/docs/spec/mark/liquid.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: liquid
order: 1
---

<embed src="@/docs/spec/mark/liquid.zh.md"></embed>
76 changes: 76 additions & 0 deletions site/docs/spec/mark/liquid.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: liquid
order: 1
---

水波图

## 开始使用

<img alt="liquid" src="https://mdn.alipayobjects.com/huamei_za7we3/afts/img/A*cHArRaizyBsAAAAAAAAAAAAADo2bAQ/original
" width="600" />

```js
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.liquid()
.data({
value: {
percent: .3,
},
})
.style({
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
});

chart.render();
```

## 选项

| 属性 | 描述 | 类型 | 默认值 |
| ----- | ---------------------- | ----------- | ------ |
| data | 数据 | `GaugeData` | - |
| style | 配置图形样式和标签样式 | - | - |

## data

| 属性 | 描述 | 类型 | 默认值 |
| ------- | ------ | -------- | ------ |
| percent | 百分比 | `number` | - |


## style

对水波图中的三个部分

| 属性 | 描述 | 类型 | 默认值 |
| --------------- | -------- | -------- | ------ |
| outlineBorder | 边框宽度 | `number` | - |
| outlineDistance | 内间距 | `number` | - |
| outlineStroke | 边框颜色 | `string` | - |
| waveLength | 波长 | `number` | - |
| backgroundFill | 背景颜色 | `string` | - |
| textFill | 文本颜色 | `string` | - |
| textFontSize | 文本大小 | `string` | - |

## shape

目前 liquid 有以下几个内置 shape 图形,默认为 `circle`。

| 图形 | 描述 | 示例 |
| -------- | ---- | ---- |
| rect | 矩形 | |
| circle | 圆形 | |
| pin | 水滴 | |
| triangle | 三角 | |

为自定义 shape 形状提供回调, `(x, y, r, w, h) => string`, 传入参数分别为 x y 中心点坐标, r 图表可画圆最大半径, w h 图表可画宽高。
19 changes: 19 additions & 0 deletions site/examples/general/Liquid/demo/liquid-background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.liquid()
.data({
value: {
percent: 0.3,
},
})
.style({
backgroundFill: 'pink',
});

chart.render();
40 changes: 40 additions & 0 deletions site/examples/general/Liquid/demo/liquid-custom-shape.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.liquid()
.data({
value: {
percent: 0.3,
},
})
.style({
shape: (x, y, r) => {
const path = [];
const w = r * 2;

for (let i = 0; i < 5; i++) {
path.push([
i === 0 ? 'M' : 'L',
(Math.cos(((18 + i * 72) * Math.PI) / 180) * w) / 2 + x,
(-Math.sin(((18 + i * 72) * Math.PI) / 180) * w) / 2 + y,
]);
path.push([
'L',
(Math.cos(((54 + i * 72) * Math.PI) / 180) * w) / 4 + x,
(-Math.sin(((54 + i * 72) * Math.PI) / 180) * w) / 4 + y,
]);
}
path.push(['Z']);
return path;
},
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
});

chart.render();
21 changes: 21 additions & 0 deletions site/examples/general/Liquid/demo/liquid-default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.liquid()
.data({
value: {
percent: 0.3,
},
})
.style({
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
});

chart.render();
Loading