Skip to content

Commit

Permalink
docs(demo): 增加动态交互图的一级导航 demo
Browse files Browse the repository at this point in the history
  • Loading branch information
visiky committed Dec 29, 2020
1 parent 50df3f7 commit 6644f5e
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 49 deletions.
2 changes: 2 additions & 0 deletions docs/api/plot-api.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Through this method, you can modify the data of the plot and re-render the plot
- Gauge、Liquid, which accept the updated percent value
- Dual Axes, which has its own data structure
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
### 5. changeSize
```sign
Expand Down
2 changes: 2 additions & 0 deletions docs/api/plot-api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ plot.changeData(data: object[] | number);
- 仪表盘、水波图 等指标类的,直接传入更新的 percent 数值
- 双轴图等复合类图表,直接传入自己的 data 数据结构
<playground path="dynamic-plots/basic/demo/dynamic-spline.ts" rid="rect"></playground>
### 5. changeSize
```sign
Expand Down
14 changes: 2 additions & 12 deletions examples/area/basic/demo/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,14 @@ import { Area } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
.then((res) => res.json())
.then((originalData) => {
let cnt = 2;
.then((data) => {
const area = new Area('container', {
data: originalData.slice(0, cnt),
data,
xField: 'timePeriod',
yField: 'value',
xAxis: {
range: [0, 1],
},
});
area.render();

const interval = setInterval(() => {
if (cnt === originalData.length) {
clearInterval(interval);
} else {
cnt += 1;
area.changeData(originalData.slice(0, cnt));
}
}, 400);
});
25 changes: 25 additions & 0 deletions examples/dynamic-plots/basic/demo/dynamic-area.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Area } from '@antv/g2plot';

fetch('https://gw.alipayobjects.com/os/bmw-prod/360c3eae-0c73-46f0-a982-4746a6095010.json')
.then((res) => res.json())
.then((originalData) => {
let cnt = 2;
const area = new Area('container', {
data: originalData.slice(0, cnt),
xField: 'timePeriod',
yField: 'value',
xAxis: {
range: [0, 1],
},
});
area.render();

const interval = setInterval(() => {
if (cnt === originalData.length) {
clearInterval(interval);
} else {
cnt += 1;
area.changeData(originalData.slice(0, cnt));
}
}, 400);
});
37 changes: 37 additions & 0 deletions examples/dynamic-plots/basic/demo/dynamic-spline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Line } from '@antv/g2plot';

function getData() {
// generate an array of random data
const data = [];
const time = new Date().getTime();

for (let i = -19; i <= 0; i += 1) {
data.push({
x: time + i * 1000,
y: Math.random() + 0.2,
});
}
return data;
}

const line = new Line('container', {
data: getData(),
padding: 'auto',
xField: 'x',
yField: 'y',
xAxis: {
type: 'time',
mask: 'HH:MM:ss',
},
smooth: true,
point: {},
});

line.render();

setInterval(() => {
const x = new Date().getTime(), // current time
y = Math.random() + 0.2;
const newData = line.options.data.slice(1).concat({ x, y });
line.changeData(newData);
}, 1000);
24 changes: 24 additions & 0 deletions examples/dynamic-plots/basic/demo/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"title": {
"zh": "中文分类",
"en": "Category"
},
"demos": [
{
"filename": "dynamic-spline.ts",
"title": {
"zh": "实时刷新的曲线图",
"en": "Spline updating real-time"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/vOmMGBA1k6/dongtaigengxinzhexiantushuju2.gif"
},
{
"filename": "dynamic-area.ts",
"title": {
"zh": "动态更新的面积图",
"en": "Area updating with dynamic"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/ld0NQtdLO0/mianjitugengxinshuju-after.gif"
}
]
}
4 changes: 4 additions & 0 deletions examples/dynamic-plots/basic/index.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: ChangeData
order: 0
---
4 changes: 4 additions & 0 deletions examples/dynamic-plots/basic/index.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: 动态更新数据
order: 0
---
29 changes: 0 additions & 29 deletions examples/line/basic/demo/dynamic-line.ts

This file was deleted.

8 changes: 0 additions & 8 deletions examples/line/basic/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@
},
"screenshot": "https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*r8MPQ4n9CIQAAAAAAAAAAAAAARQnAQ"
},
{
"filename": "dynamic-line.ts",
"title": {
"zh": "动态更新折线图",
"en": "Line plot updated dynamic"
},
"screenshot": "https://gw.alipayobjects.com/zos/antfincdn/vOmMGBA1k6/dongtaigengxinzhexiantushuju2.gif"
},
{
"filename": "line-with-data-marker.ts",
"title": {
Expand Down
8 changes: 8 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ module.exports = {
en: 'General Configuration',
},
},
{
slug: 'dynamic-plots',
icon: 'other',
title: {
zh: '动态交互图',
en: 'Dynamic Plots',
},
},
{
slug: 'plugin',
icon: 'other',
Expand Down

0 comments on commit 6644f5e

Please sign in to comment.