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

feat: 完善散点图功能、新增测试用例 #1322

Merged
merged 24 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
509 changes: 509 additions & 0 deletions __tests__/data/gender.ts

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions __tests__/unit/plots/scatter/axis-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Scatter } from '../../../../src';
import { data } from '../../../data/gender';
import { createDiv } from '../../../utils/dom';

describe('scatter', () => {
it('axis: axis options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
shape: ['circle', 'square'],
xAxis: {
nice: true,
label: {
formatter: (text: string, item: any, index: number) => {
return text;
},
style: {
fill: 'green',
fontSize: 16,
},
},
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

// @ts-ignore
expect(scatter.chart.options.axes.weight.label.style.fill).toBe('green');
// @ts-ignore
expect(scatter.chart.options.axes.weight.label.style.fontSize).toBe(16);
});
});
58 changes: 58 additions & 0 deletions __tests__/unit/plots/scatter/color-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Scatter } from '../../../../src';
import { data } from '../../../data/gender';
import { createDiv } from '../../../utils/dom';

describe('scatter', () => {
it('color: string options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
color: 'red',
xAxis: {
nice: true,
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().color).toBe('red');
});

it('color: string array options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
color: ['#e764ff', '#2b0033'],
xAxis: {
nice: true,
},
});

scatter.render();

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

// @ts-ignore
expect(geometry.attributeOption.color.values.length).toBe(2);

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().color).not.toBe('red');
});
});
131 changes: 131 additions & 0 deletions __tests__/unit/plots/scatter/shape-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Scatter } from '../../../../src';
import { data } from '../../../data/gender';
import { createDiv } from '../../../utils/dom';

describe('scatter', () => {
it('shape: string options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
shape: 'weight',
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
xAxis: {
nice: true,
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

const shapeArr = [];

elements.forEach((ele) => {
shapeArr.push(ele.getModel().shape);
});

expect(shapeArr).toContain('circle');

const set = new Set(shapeArr);

expect(set.size > 2).toBeTruthy();
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
});

it('shpae: number options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
shape: 'hollow-diamond',
xAxis: {
nice: true,
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[~~Math.random() * (elements.length - 1)].getModel().shape).toBe('hollow-diamond');
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
});

it('shape: number array options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
shape: ['circle', 'square'],
xAxis: {
nice: true,
},
});

scatter.render();

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

// @ts-ignore
expect(geometry.attributeOption.shape.values.length).toBe(2);

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

const shapeArr = [];

elements.forEach((ele) => {
shapeArr.push(ele.getModel().shape);
});

const set = new Set(shapeArr);

expect(set.size).toBe(2);
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
});

it('shape: callback options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
shape: () => {
return 'circle';
},
xAxis: {
nice: true,
},
});

scatter.render();

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

// @ts-ignore
expect(geometry.attributeOption.shape.callback).toBeFunction();

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().shape).toBe('circle');
});
});
117 changes: 117 additions & 0 deletions __tests__/unit/plots/scatter/size-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Scatter } from '../../../../src';
import { data } from '../../../data/gender';
import { createDiv } from '../../../utils/dom';

describe('scatter', () => {
it('size: string options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
pointSize: 'weight',
xAxis: {
nice: true,
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().size).not.toBe(0);

expect(elements[0].getModel().size).not.toBe(elements[elements.length - 1].getModel().size);
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
});

it('size: number options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
pointSize: 5,
xAxis: {
nice: true,
},
});

scatter.render();

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

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().size).toBe(5);

expect(elements[0].getModel().size).toBe(elements[elements.length - 1].getModel().size);
});

it('size: number array options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
pointSize: [5, 10],
xAxis: {
nice: true,
},
});

scatter.render();

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

// @ts-ignore
expect(geometry.attributeOption.size.values.length).toBe(2);

const elements = geometry.elements;

expect(elements.length).not.toBe(0);
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved

expect(elements[0].getModel().size).not.toBe(elements[elements.length - 1].getModel().size);
});

it('size: callback options', () => {
const scatter = new Scatter(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data,
xField: 'weight',
yField: 'height',
pointSize: () => {
return 6;
lxfu1 marked this conversation as resolved.
Show resolved Hide resolved
},
xAxis: {
nice: true,
},
});

scatter.render();

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

// @ts-ignore
expect(geometry.attributeOption.size.callback).toBeFunction();

const elements = geometry.elements;

expect(elements.length).not.toBe(0);

expect(elements[0].getModel().size).toBe(6);
});
});
Loading