Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: 完善词云图和玫瑰图的单测用例 #1664

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 85 additions & 102 deletions __tests__/unit/plots/rose/label-spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
import { deepMix } from '@antv/util';
import { Rose } from '../../../../src';
import { salesByArea, subSalesByArea } from '../../../data/sales';
import { createDiv } from '../../../utils/dom';

describe('rose label', () => {
const options = {
width: 400,
height: 300,
data: salesByArea,
xField: 'area',
yField: 'sales',
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
},
},
};

it('false', () => {
const rose = new Rose(
createDiv('false'),
deepMix({}, options, {
label: false,
})
);

rose.render();
const geometry = rose.chart.geometries[0];

// @ts-ignore
expect(geometry.labelOption.cfg).toBeUndefined();
});

it('position top', () => {
const rose = new Rose(createDiv('position top'), {
width: 400,
height: 300,
data: salesByArea,
xField: 'area',
yField: 'sales',
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('position top'),
deepMix({}, options, {
label: {
fields: ['sales'],
position: 'top',
},
},
label: {
fields: ['sales'],
position: 'top',
},
});
})
);

rose.render();

Expand All @@ -38,77 +60,52 @@ describe('rose label', () => {
});

it('position middle', () => {
const rose = new Rose(createDiv('position middle'), {
width: 400,
height: 300,
data: salesByArea,
xField: 'area',
yField: 'sales',
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('position middle'),
deepMix({}, options, {
label: {
position: 'middle',
},
},
label: {
position: 'middle',
},
});
})
);

rose.render();

const geometry = rose.chart.geometries[0];

// @ts-ignore
expect(geometry.labelOption.cfg).toEqual({ position: 'middle' });
});

it('position bottom', () => {
const rose = new Rose(createDiv('position bottom'), {
width: 400,
height: 300,
data: salesByArea,
xField: 'area',
yField: 'sales',
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('position bottom'),
deepMix({}, options, {
label: {
position: 'bottom',
},
},
label: {
position: 'bottom',
},
});
})
);

rose.render();

const geometry = rose.chart.geometries[0];

// @ts-ignore
expect(geometry.labelOption.cfg).toEqual({ position: 'bottom' });
});

it('group rose position top', () => {
const rose = new Rose(createDiv('group rose position top'), {
width: 400,
height: 300,
data: subSalesByArea,
xField: 'area',
yField: 'sales',
seriesField: 'series',
isGroup: true,
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('group rose position top'),
deepMix({}, options, {
data: subSalesByArea,
seriesField: 'series',
isGroup: true,
label: {
fields: ['sales'],
position: 'top',
},
},
label: {
fields: ['sales'],
position: 'top',
},
});
})
);

rose.render();

Expand All @@ -127,25 +124,18 @@ describe('rose label', () => {
});

it('group rose position middle', () => {
const rose = new Rose(createDiv('group rose position middle'), {
width: 400,
height: 300,
data: subSalesByArea,
xField: 'area',
yField: 'sales',
seriesField: 'series',
isGroup: true,
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('group rose position middle'),
deepMix({}, options, {
data: subSalesByArea,
seriesField: 'series',
isGroup: true,
label: {
fields: ['sales'],
position: 'middle',
},
},
label: {
fields: ['sales'],
position: 'middle',
},
});
})
);

rose.render();

Expand All @@ -164,25 +154,18 @@ describe('rose label', () => {
});

it('group rose position bottom', () => {
const rose = new Rose(createDiv('group rose position bottom'), {
width: 400,
height: 300,
data: subSalesByArea,
xField: 'area',
yField: 'sales',
seriesField: 'series',
isGroup: true,
meta: {
sales: {
nice: true,
formatter: (v) => `${Math.floor(v / 10000)}万`,
const rose = new Rose(
createDiv('group rose position bottom'),
deepMix({}, options, {
data: subSalesByArea,
seriesField: 'series',
isGroup: true,
label: {
fields: ['sales'],
position: 'bottom',
},
},
label: {
fields: ['sales'],
position: 'bottom',
},
});
})
);

rose.render();

Expand Down
29 changes: 29 additions & 0 deletions __tests__/unit/plots/rose/legend-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { deepMix } from '@antv/util';
import { Rose } from '../../../../src';
import { salesByArea } from '../../../data/sales';
import { createDiv } from '../../../utils/dom';

describe('rose label', () => {
const options = {
width: 400,
height: 300,
data: salesByArea,
xField: 'area',
yField: 'sales',
};

it('false', () => {
const rose = new Rose(
createDiv('false'),
deepMix({}, options, {
legend: false,
})
);

rose.render();
const legendController = rose.chart.getController('legend');
// @ts-ignore
const { option } = legendController;
expect(option).toBe(false);
});
});
33 changes: 25 additions & 8 deletions __tests__/unit/plots/word-cloud/index-spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { deepMix } from '@antv/util';
import { WordCloud } from '../../../../src';
import { CountryEconomy } from '../../../data/country-economy';
import { createDiv } from '../../../utils/dom';

describe('word-cloud', () => {
it('x*y', () => {
const cloud = new WordCloud(createDiv('x*y'), {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
});
const options = {
width: 400,
height: 300,
data: CountryEconomy,
wordField: 'Country',
weightField: 'GDP',
};

it('x*y', () => {
const cloud = new WordCloud(createDiv('x*y'), options);
cloud.render();

const geometry = cloud.chart.geometries[0];
Expand All @@ -25,4 +27,19 @@ describe('word-cloud', () => {
expect(positionFields[0]).toBe('x');
expect(positionFields[1]).toBe('y');
});

it('imageMask', () => {
const options1 = deepMix({}, options, {
imageMask: new Image(),
});
const options2 = deepMix({}, options, {
imageMask: 'ssss', // 无效值
});
const cloud1 = new WordCloud(createDiv('x*y'), options1);
const cloud2 = new WordCloud(createDiv('x*y'), options2);
expect(() => {
cloud1.render();
cloud2.render();
}).not.toThrow();
});
});
Loading