-
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.
feat: 玫瑰图修改 changeData && 添加单测 (#2200)
* feat: rose changeData && 添加单测 * fix: 将public方法置前 Co-authored-by: 沈建斌 <wb-sjb709429@antfin.com>
- Loading branch information
1 parent
a817274
commit eb44c0f
Showing
2 changed files
with
138 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { salesByArea, subSalesByArea } from '../../../data/sales'; | ||
import { Rose } from '../../../../src'; | ||
import { createDiv } from '../../../utils/dom'; | ||
|
||
describe('rose-changeData', () => { | ||
it('basic rose: change Data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: salesByArea, | ||
xField: 'area', | ||
yField: 'sales', | ||
}); | ||
|
||
rosePlot.render(); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(salesByArea.length); | ||
|
||
const newData = salesByArea.slice(0, 3); | ||
rosePlot.changeData(newData); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); | ||
expect(rosePlot.options.data).toEqual(newData); | ||
|
||
rosePlot.destroy(); | ||
}); | ||
|
||
it('basic rose: from empty to have data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: [], | ||
xField: 'area', | ||
yField: 'sales', | ||
}); | ||
|
||
rosePlot.render(); | ||
|
||
rosePlot.changeData(salesByArea); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(salesByArea.length); | ||
expect(rosePlot.options.data).toEqual(salesByArea); | ||
|
||
rosePlot.destroy(); | ||
}); | ||
|
||
it('group rose: change data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: subSalesByArea, | ||
xField: 'area', | ||
yField: 'sales', | ||
isGroup: true, | ||
seriesField: 'series', | ||
}); | ||
|
||
rosePlot.render(); | ||
|
||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); | ||
|
||
const newData = subSalesByArea.filter((item) => item.area !== '东北' || item.series !== '消费者'); | ||
rosePlot.changeData(newData); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); | ||
expect(rosePlot.options.data).toEqual(newData); | ||
|
||
rosePlot.destroy(); | ||
}); | ||
|
||
it('group rose: from empty to have data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: [], | ||
xField: 'area', | ||
yField: 'sales', | ||
isGroup: true, | ||
seriesField: 'series', | ||
}); | ||
|
||
rosePlot.render(); | ||
|
||
rosePlot.changeData(subSalesByArea); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); | ||
expect(rosePlot.options.data).toEqual(subSalesByArea); | ||
|
||
rosePlot.destroy(); | ||
}); | ||
|
||
it('stacked rose: change data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: subSalesByArea, | ||
xField: 'area', | ||
yField: 'sales', | ||
isStack: true, | ||
seriesField: 'series', | ||
}); | ||
|
||
rosePlot.render(); | ||
|
||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); | ||
|
||
const newData = subSalesByArea.filter((item) => item.area !== '东北' || item.series !== '消费者'); | ||
rosePlot.changeData(newData); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(newData.length); | ||
expect(rosePlot.options.data).toEqual(newData); | ||
|
||
rosePlot.destroy(); | ||
}); | ||
|
||
it('stack rose: from empty to have data', () => { | ||
const rosePlot = new Rose(createDiv(), { | ||
width: 400, | ||
height: 300, | ||
data: [], | ||
xField: 'area', | ||
yField: 'sales', | ||
isStack: true, | ||
seriesField: 'series', | ||
}); | ||
|
||
rosePlot.render(); | ||
|
||
rosePlot.changeData(subSalesByArea); | ||
expect(rosePlot.chart.geometries[0].elements.length).toEqual(subSalesByArea.length); | ||
expect(rosePlot.options.data).toEqual(subSalesByArea); | ||
|
||
rosePlot.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