-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs(line-demo): 优化基础折线图 demo * feat(core): plot core 提供 updateOptions 方法 & 提供 changedata 复写 * feat(line): 折线图支持动态更新数据 - overrider changedata - provide demo * feat(gauge): 仪表盘支持动态更新数据 - 抽取获取 view data 的工具方法 - override changeData * feat(gauge): 优化仪表盘的 changedata, 每一次 changedata 只做一次 paint 绘制 - [x] 单测 * fix(gauge): 修改文档 & demo * feat(🔨): 增加测试用例 * feat(gauge): 添加仪表盘 utils 测试用例 * fix: 修改 cr 建议 * docs: 更新网站 demo 截图
- Loading branch information
Showing
19 changed files
with
421 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { PERCENT, RANGE_TYPE, RANGE_VALUE } from '../../../../src/plots/gauge/constant'; | ||
import { getIndicatorData, getRangeData } from '../../../../src/plots/gauge/utils'; | ||
|
||
describe('gauge utils to getData', () => { | ||
it('get indicatorData', () => { | ||
expect(getIndicatorData(0.1)).toEqual([{ [PERCENT]: 0.1 }]); | ||
expect(getIndicatorData(1.4)).toEqual([{ [PERCENT]: 1 }]); | ||
expect(getIndicatorData(-0.4)).toEqual([{ [PERCENT]: 0 }]); | ||
}); | ||
|
||
it('get rangeData', () => { | ||
expect(getRangeData(0.5, { ticks: [0, 0.3, 1] })).toEqual([ | ||
{ [RANGE_VALUE]: 0.3, [RANGE_TYPE]: '1' }, | ||
{ [RANGE_VALUE]: 0.7, [RANGE_TYPE]: '2' }, | ||
]); | ||
|
||
expect(getRangeData(0.5)).toEqual([ | ||
{ [RANGE_VALUE]: 0.5, [RANGE_TYPE]: '1' }, | ||
{ [RANGE_VALUE]: 0.5, [RANGE_TYPE]: '2' }, | ||
]); | ||
|
||
expect(getRangeData(-0.5)).toEqual([{ [RANGE_VALUE]: 1, [RANGE_TYPE]: '2' }]); | ||
expect(getRangeData(1.5)).toEqual([{ [RANGE_VALUE]: 1, [RANGE_TYPE]: '1' }]); | ||
|
||
expect(getRangeData(0)).toEqual([{ [RANGE_VALUE]: 1, [RANGE_TYPE]: '2' }]); | ||
expect(getRangeData(1)).toEqual([{ [RANGE_VALUE]: 1, [RANGE_TYPE]: '1' }]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Line } from '../../../../src'; | ||
import { partySupport } from '../../../data/party-support'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('line', () => { | ||
it('change data', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: partySupport.filter((o) => ['FF'].includes(o.type)), | ||
xField: 'date', | ||
yField: 'value', | ||
seriesField: 'type', | ||
color: ['blue', 'red'], | ||
appendPadding: 10, | ||
connectNulls: true, | ||
}); | ||
|
||
line.render(); | ||
|
||
expect(line.chart.geometries[0].elements.length).toBe(1); | ||
|
||
line.changeData(partySupport.filter((o) => ['FF', 'Lab'].includes(o.type))); | ||
expect(line.chart.geometries[0].elements.length).toBe(2); | ||
expect(line.options.data).toEqual(partySupport.filter((o) => ['FF', 'Lab'].includes(o.type))); | ||
|
||
line.destroy(); | ||
}); | ||
|
||
it('add point', () => { | ||
const line = new Line(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: [ | ||
{ type: '1', value: 10 }, | ||
{ type: '2', value: 3 }, | ||
], | ||
xField: 'type', | ||
yField: 'value', | ||
point: {}, | ||
}); | ||
|
||
line.render(); | ||
expect(line.chart.geometries[1].elements.length).toBe(2); | ||
|
||
line.changeData([...line.options.data, { type: '3', value: 10 }]); | ||
expect(line.chart.geometries[1].elements.length).toBe(3); | ||
|
||
line.destroy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Line } from '@antv/g2plot'; | ||
|
||
fetch('https://gw.alipayobjects.com/os/bmw-prod/1d565782-dde4-4bb6-8946-ea6a38ccf184.json') | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const line = new Line('container', { | ||
data, | ||
padding: 'auto', | ||
xField: 'Date', | ||
yField: 'scales', | ||
xAxis: { | ||
type: 'timeCat', | ||
tickCount: 5, | ||
}, | ||
}); | ||
|
||
line.render(); | ||
|
||
let year = 2017; | ||
let month = 2; | ||
const interval = setInterval(() => { | ||
if (year > 2211) { | ||
clearInterval(interval); | ||
} | ||
month = (month + 1) % 12; | ||
year += Math.ceil(month / 12); | ||
line.changeData([...line.options.data, { Date: `${year}-${month}`, scales: 1300 * Math.random() + 500 }]); | ||
}, 500); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { G2, Line } from '@antv/g2plot'; | ||
|
||
G2.registerShape('point', 'breath-point', { | ||
draw(cfg, container) { | ||
const data = cfg.data; | ||
const point = { x: cfg.x, y: cfg.y }; | ||
const group = container.addGroup(); | ||
if (data.time === '14.20' && data.date === 'today') { | ||
const decorator1 = group.addShape('circle', { | ||
attrs: { | ||
x: point.x, | ||
y: point.y, | ||
r: 10, | ||
fill: cfg.color, | ||
opacity: 0.5, | ||
}, | ||
}); | ||
const decorator2 = group.addShape('circle', { | ||
attrs: { | ||
x: point.x, | ||
y: point.y, | ||
r: 10, | ||
fill: cfg.color, | ||
opacity: 0.5, | ||
}, | ||
}); | ||
const decorator3 = group.addShape('circle', { | ||
attrs: { | ||
x: point.x, | ||
y: point.y, | ||
r: 10, | ||
fill: cfg.color, | ||
opacity: 0.5, | ||
}, | ||
}); | ||
decorator1.animate( | ||
{ | ||
r: 20, | ||
opacity: 0, | ||
}, | ||
{ | ||
duration: 1800, | ||
easing: 'easeLinear', | ||
repeat: true, | ||
} | ||
); | ||
decorator2.animate( | ||
{ | ||
r: 20, | ||
opacity: 0, | ||
}, | ||
{ | ||
duration: 1800, | ||
easing: 'easeLinear', | ||
repeat: true, | ||
delay: 600, | ||
} | ||
); | ||
decorator3.animate( | ||
{ | ||
r: 20, | ||
opacity: 0, | ||
}, | ||
{ | ||
duration: 1800, | ||
easing: 'easeLinear', | ||
repeat: true, | ||
delay: 1200, | ||
} | ||
); | ||
group.addShape('circle', { | ||
attrs: { | ||
x: point.x, | ||
y: point.y, | ||
r: 6, | ||
fill: cfg.color, | ||
opacity: 0.7, | ||
}, | ||
}); | ||
group.addShape('circle', { | ||
attrs: { | ||
x: point.x, | ||
y: point.y, | ||
r: 1.5, | ||
fill: cfg.color, | ||
}, | ||
}); | ||
} | ||
|
||
return group; | ||
}, | ||
}); | ||
|
||
fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/cpu-data.json') | ||
.then((res) => res.json()) | ||
.then((data) => { | ||
const plot = new Line('container', { | ||
autoFit: true, | ||
height: 500, | ||
data, | ||
meta: { | ||
cpu: { | ||
time: { type: 'cat' }, | ||
max: 100, | ||
min: 0, | ||
}, | ||
}, | ||
xField: 'time', | ||
yField: 'cpu', | ||
seriesField: 'date', | ||
tooltip: { showMarkers: false }, | ||
point: { | ||
shape: 'breath-point', | ||
}, | ||
}); | ||
|
||
plot.render(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.