Skip to content

Commit 6447793

Browse files
committed
fix: charts issue
1 parent 4978516 commit 6447793

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

__tests__/bugs/issue-292-spec.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Heatmap } from '../../src';
2+
import { createDiv } from '../utils/dom';
3+
4+
describe('heatmap', () => {
5+
it('x*y*color and type', async () => {
6+
const data = await fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/heatmap.json').then((res) =>
7+
res.json()
8+
);
9+
const heatmap = new Heatmap(createDiv('type density'), {
10+
width: 600,
11+
height: 500,
12+
data: [],
13+
autoFit: false,
14+
type: 'density',
15+
xField: 'g',
16+
yField: 'l',
17+
colorField: 'tmp',
18+
color: '#F51D27-#FA541C-#FF8C12-#FFC838-#FAFFA8-#80FF73-#12CCCC-#1890FF-#6E32C2',
19+
annotations: [
20+
{
21+
type: 'image',
22+
start: ['min', 'max'],
23+
end: ['max', 'min'],
24+
src: 'https://gw.alipayobjects.com/zos/rmsportal/NeUTMwKtPcPxIFNTWZOZ.png',
25+
},
26+
],
27+
});
28+
29+
heatmap.render();
30+
const geometry = heatmap.chart.geometries[0];
31+
// @ts-ignore
32+
const { attributeOption } = geometry;
33+
expect(heatmap.options.type).toBe('density');
34+
expect(geometry.type).toBe('heatmap');
35+
expect(attributeOption.position.fields).toEqual(['g', 'l']);
36+
expect(attributeOption.color.fields).toEqual(['tmp']);
37+
expect(attributeOption.color.values).toBe(
38+
'#F51D27-#FA541C-#FF8C12-#FFC838-#FAFFA8-#80FF73-#12CCCC-#1890FF-#6E32C2'
39+
);
40+
heatmap.changeData(data);
41+
console.log(heatmap);
42+
expect(heatmap.chart.geometries[0].data.length).toBe(500);
43+
expect(heatmap.chart.getOptions().data.length).toBe(500);
44+
});
45+
});

__tests__/bugs/issue-294-spec.ts

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { DualAxes } from '../../src';
2+
import { createDiv } from '../utils/dom';
3+
import { delay } from '../utils/delay';
4+
5+
describe('DualAxes', () => {
6+
it('change data', async () => {
7+
const uvData = [
8+
{ time: '2019-03', value: 35 },
9+
{ time: '2019-04', value: 90 },
10+
{ time: '2019-05', value: 30 },
11+
{ time: '2019-06', value: 45 },
12+
{ time: '2019-07', value: 47 },
13+
];
14+
15+
const transformData = [
16+
{ time: '2019-03', count: 800, name: 'a' },
17+
{ time: '2019-04', count: 600, name: 'a' },
18+
{ time: '2019-05', count: 400, name: 'a' },
19+
{ time: '2019-06', count: 380, name: 'a' },
20+
{ time: '2019-07', count: 220, name: 'a' },
21+
{ time: '2019-03', count: 750, name: 'b' },
22+
{ time: '2019-04', count: 650, name: 'b' },
23+
{ time: '2019-05', count: 450, name: 'b' },
24+
{ time: '2019-06', count: 400, name: 'b' },
25+
{ time: '2019-07', count: 320, name: 'b' },
26+
{ time: '2019-03', count: 900, name: 'c' },
27+
{ time: '2019-04', count: 600, name: 'c' },
28+
{ time: '2019-05', count: 450, name: 'c' },
29+
{ time: '2019-06', count: 300, name: 'c' },
30+
{ time: '2019-07', count: 200, name: 'c' },
31+
];
32+
const DualAxesPlot = new DualAxes(createDiv(), {
33+
width: 400,
34+
height: 400,
35+
data: [[], []],
36+
xField: 'time',
37+
yField: ['value', 'count'],
38+
animation: false,
39+
geometryOptions: [
40+
{
41+
geometry: 'column',
42+
color: '#5B8FF9',
43+
columnWidthRatio: 0.4,
44+
},
45+
{
46+
geometry: 'line',
47+
seriesField: 'name',
48+
color: ['#CDDDFD', '#CDF3E4', '#CED4DE'],
49+
},
50+
],
51+
});
52+
DualAxesPlot.render();
53+
expect(DualAxesPlot.options.yField).toEqual(['value', 'count']);
54+
await delay(500);
55+
DualAxesPlot.changeData([uvData, transformData]);
56+
expect(DualAxesPlot.options.geometryOptions[0].geometry).toBe('column');
57+
expect(DualAxesPlot.chart.views[0].geometries[0].shapeType).toBe('interval');
58+
});
59+
});

__tests__/unit/plots/sunburst/change-data-spec.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ describe('sunburst', () => {
2626
sunburstPlot.changeData(data);
2727
const geometry = sunburstPlot.chart.geometries[0];
2828
expect(geometry.type).toBe('polygon');
29+
expect(sunburstPlot.options.color).toEqual(['#BAE7FF', '#1890FF', '#0050B3']);
2930
const {
3031
// @ts-ignore
3132
labelOption: { fields, cfg },

0 commit comments

Comments
 (0)