Skip to content

Commit 72bbfa4

Browse files
authored
docs: 增加动态交互图表 & 文档 typo 修整 (#2154)
* docs(🔖): 文案 typo 和 文档顺序 * docs(demo): 增加动态交互图的一级导航 demo * fix: 修复 lint error
1 parent 4a8ef9f commit 72bbfa4

File tree

14 files changed

+111
-54
lines changed

14 files changed

+111
-54
lines changed

docs/api/events.en.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Events
3-
order: 3
3+
order: 4
44
---
55

66
`markdown:docs/common/events.en.md`

docs/api/events.zh.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 图表事件
3-
order: 3
3+
order: 4
44
---
55

66
`markdown:docs/common/events.zh.md`

docs/api/plot-api.en.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ redirect_from:
66
---
77

88

9-
The core technology architecture of G2plot is very simple. All plots are inherited from a base class. The base class provides a common API method for all plots, and each specific visualization plot only processes its own configuration items. So all plots basically share the common API, except for some plots (such as Gauge and Liquid) that have subtle differences in the changedata API.
9+
The core technology architecture of G2Plot is very simple. All plots are inherited from a base class. The base class provides a common API method for all plots, and each specific visualization plot only processes its own configuration items. So all plots basically share the common API, except for some plots (such as Gauge and Liquid) that have subtle differences in the changedata API.
1010

1111

1212
### 1. create a plot instance
@@ -55,6 +55,8 @@ Through this method, you can modify the data of the plot and re-render the plot
5555
- Gauge、Liquid, which accept the updated percent value
5656
- Dual Axes, which has its own data structure
5757
58+
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
59+
5860
### 5. changeSize
5961
6062
```sign

docs/api/plot-api.zh.md

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ plot.changeData(data: object[] | number);
5555
- 仪表盘、水波图 等指标类的,直接传入更新的 percent 数值
5656
- 双轴图等复合类图表,直接传入自己的 data 数据结构
5757
58+
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
59+
5860
### 5. changeSize
5961
6062
```sign

examples/area/basic/demo/basic.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@ import { Area } from '@antv/g2plot';
22

33
fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
44
.then((res) => res.json())
5-
.then((originalData) => {
6-
let cnt = 2;
5+
.then((data) => {
76
const area = new Area('container', {
8-
data: originalData.slice(0, cnt),
7+
data,
98
xField: 'timePeriod',
109
yField: 'value',
1110
xAxis: {
1211
range: [0, 1],
1312
},
1413
});
1514
area.render();
16-
17-
const interval = setInterval(() => {
18-
if (cnt === originalData.length) {
19-
clearInterval(interval);
20-
} else {
21-
cnt += 1;
22-
area.changeData(originalData.slice(0, cnt));
23-
}
24-
}, 400);
2515
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Area } from '@antv/g2plot';
2+
3+
fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
4+
.then((res) => res.json())
5+
.then((originalData) => {
6+
let cnt = 2;
7+
const area = new Area('container', {
8+
data: originalData.slice(0, cnt),
9+
xField: 'timePeriod',
10+
yField: 'value',
11+
xAxis: {
12+
range: [0, 1],
13+
},
14+
});
15+
area.render();
16+
17+
const interval = setInterval(() => {
18+
if (cnt === originalData.length) {
19+
clearInterval(interval);
20+
} else {
21+
cnt += 1;
22+
area.changeData(originalData.slice(0, cnt));
23+
}
24+
}, 400);
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Line } from '@antv/g2plot';
2+
3+
function getData() {
4+
// generate an array of random data
5+
const data = [];
6+
const time = new Date().getTime();
7+
8+
for (let i = -19; i <= 0; i += 1) {
9+
data.push({
10+
x: time + i * 1000,
11+
y: Math.random() + 0.2,
12+
});
13+
}
14+
return data;
15+
}
16+
17+
const line = new Line('container', {
18+
data: getData(),
19+
padding: 'auto',
20+
xField: 'x',
21+
yField: 'y',
22+
xAxis: {
23+
type: 'time',
24+
mask: 'HH:MM:ss',
25+
},
26+
smooth: true,
27+
point: {},
28+
});
29+
30+
line.render();
31+
32+
setInterval(() => {
33+
const x = new Date().getTime(), // current time
34+
y = Math.random() + 0.2;
35+
const newData = line.options.data.slice(1).concat({ x, y });
36+
line.changeData(newData);
37+
}, 1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"title": {
3+
"zh": "中文分类",
4+
"en": "Category"
5+
},
6+
"demos": [
7+
{
8+
"filename": "dynamic-spline.ts",
9+
"title": {
10+
"zh": "实时刷新的曲线图",
11+
"en": "Spline updating real-time"
12+
},
13+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/uShhKpuVTc/dongtaigengxinzhexiantushuju.gif"
14+
},
15+
{
16+
"filename": "dynamic-area.ts",
17+
"title": {
18+
"zh": "动态更新的面积图",
19+
"en": "Area updating with dynamic"
20+
},
21+
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/ld0NQtdLO0/mianjitugengxinshuju-after.gif"
22+
}
23+
]
24+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: ChangeData
3+
order: 0
4+
---
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: 动态更新数据
3+
order: 0
4+
---

examples/line/basic/demo/dynamic-line.ts

-29
This file was deleted.

examples/line/basic/demo/meta.json

-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@
3636
},
3737
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*r8MPQ4n9CIQAAAAAAAAAAAAAARQnAQ"
3838
},
39-
{
40-
"filename": "dynamic-line.ts",
41-
"title": {
42-
"zh": "动态更新折线图",
43-
"en": "Line plot updated dynamic"
44-
},
45-
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/vOmMGBA1k6/dongtaigengxinzhexiantushuju2.gif"
46-
},
4739
{
4840
"filename": "line-with-data-marker.ts",
4941
"title": {

gatsby-config.js

+8
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ module.exports = {
205205
en: 'General Configuration',
206206
},
207207
},
208+
{
209+
slug: 'dynamic-plots',
210+
icon: 'other',
211+
title: {
212+
zh: '动态交互图',
213+
en: 'Dynamic Plots',
214+
},
215+
},
208216
{
209217
slug: 'plugin',
210218
icon: 'other',

src/plots/area/utils.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { percent } from '../../utils/transform/percent';
2-
import { AreaOptions } from './types';
32

43
/**
54
* 获取面积图数据,如果是百分比,进行数据转换
@@ -12,6 +11,5 @@ export function getAreaData(
1211
asField: string,
1312
isPercent?: boolean
1413
) {
15-
// const { data, isPercent, xField, yField } = options;
1614
return !isPercent ? data : percent(data, yField, groupField, asField);
1715
}

0 commit comments

Comments
 (0)