Skip to content

Commit

Permalink
Merge branch 'v5' into feat-bullet
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Sep 12, 2023
2 parents cd96316 + 69540e3 commit 8b0062d
Show file tree
Hide file tree
Showing 49 changed files with 1,029 additions and 36 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions __tests__/plots/static/index.ts
Expand Up @@ -281,8 +281,16 @@ 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';
export { intervalPointBullet } from './interval-point-bullet';
export { intervalPointBullets } from './interval-point-bullets';
export { intervalPointBulletDatas } from './interval-point-bullet-datas';
export { mockIntervalLine } from './mock-interval-line';
11 changes: 11 additions & 0 deletions __tests__/plots/static/liquid-circle.ts
@@ -0,0 +1,11 @@
import { G2Spec } from '../../../src';

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

export function liquidCustomShape(): G2Spec {
return {
type: 'liquid',
autoFit: true,
data: 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
@@ -0,0 +1,14 @@
import { G2Spec } from '../../../src';

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

export function liquidDiamond(): G2Spec {
return {
type: 'liquid',
data: 0.3,
style: {
shape: 'diamond',
},
};
}
15 changes: 15 additions & 0 deletions __tests__/plots/static/liquid-pin.ts
@@ -0,0 +1,15 @@
import { G2Spec } from '../../../src';

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

export function liquidRect(): G2Spec {
return {
type: 'liquid',
data: 0.3,
style: {
shape: 'rect',
},
};
}
11 changes: 11 additions & 0 deletions __tests__/plots/static/liquid-triangle.ts
@@ -0,0 +1,11 @@
import { G2Spec } from '../../../src';

export function liquidTriangle(): G2Spec {
return {
type: 'liquid',
data: 0.3,
style: {
shape: 'triangle',
},
};
}
39 changes: 39 additions & 0 deletions __tests__/plots/static/mock-interval-line.ts
@@ -0,0 +1,39 @@
import { G2Spec } from '../../../src';

export function mockIntervalLine(): G2Spec {
return {
type: 'view',
children: [
{
type: 'interval',
data: [
{ time: '2019-03', value: 350, type: 'uv' },
{ time: '2019-04', value: 900, type: 'uv' },
{ time: '2019-05', value: 300, type: 'uv' },
{ time: '2019-06', value: 450, type: 'uv' },
{ time: '2019-07', value: 470, type: 'uv' },
{ time: '2019-03', value: 220, type: 'bill' },
{ time: '2019-04', value: 300, type: 'bill' },
{ time: '2019-05', value: 250, type: 'bill' },
{ time: '2019-06', value: 220, type: 'bill' },
{ time: '2019-07', value: 362, type: 'bill' },
],
encode: { x: 'time', y: 'value', color: 'type' },
transform: [{ type: 'dodgeX' }],
axis: { y: { labelFormatter: '.0%' } },
},
{
type: 'line',
data: [
{ time: '2019-03', count: 800 },
{ time: '2019-04', count: 600 },
{ time: '2019-05', count: 400 },
{ time: '2019-06', count: 380 },
{ time: '2019-07', count: 220 },
],
encode: { x: 'time', y: 'count', color: () => 'line' },
axis: { y: { labelFormatter: '.0%' } },
},
],
};
}
2 changes: 2 additions & 0 deletions __tests__/unit/api/chart.spec.ts
Expand Up @@ -129,6 +129,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 @@ -162,6 +163,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
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
15 changes: 15 additions & 0 deletions __tests__/unit/api/type.spec.ts
@@ -0,0 +1,15 @@
import { Chart, CompositionNode, MarkNode } from '../../../src';

describe('types', () => {
const chart = new Chart();

test('CompositionNode', () => {
const rect: CompositionNode = chart.facetRect();
rect.boxplot();
});

test('MarkNode', () => {
const interval: MarkNode = chart.interval();
interval.encode('x', 'name');
});
});
3 changes: 2 additions & 1 deletion __tests__/unit/lib/plot.spec.ts
@@ -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
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
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
@@ -0,0 +1,6 @@
---
title: liquid
order: 1
---

<embed src="@/docs/spec/mark/liquid.zh.md"></embed>
65 changes: 65 additions & 0 deletions site/docs/spec/mark/liquid.zh.md
@@ -0,0 +1,65 @@
---
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(.3)
.style({
outlineBorder: 4,
outlineDistance: 8,
waveLength: 128,
});

chart.render();
```

## 选项

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

## 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 图表可画宽高。
15 changes: 15 additions & 0 deletions site/examples/general/Liquid/demo/liquid-background.ts
@@ -0,0 +1,15 @@
import { Chart } from '@antv/g2';

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

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

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

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

chart
.liquid()
.data(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();
17 changes: 17 additions & 0 deletions site/examples/general/Liquid/demo/liquid-default.ts
@@ -0,0 +1,17 @@
import { Chart } from '@antv/g2';

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

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

chart.render();

0 comments on commit 8b0062d

Please sign in to comment.