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

test: 提升bullet的测试覆盖率以及优化代码 #1844

Merged
merged 1 commit into from
Nov 3, 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
4 changes: 3 additions & 1 deletion __tests__/unit/plots/bullet/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ describe('bullet', () => {
expect(measureGeometry.getAttribute('color').getFields()[0]).toEqual('mKey');
const mColor = measureGeometry.theme.colors10;
expect(measureGeometry.getAttribute('color').values).toEqual(mColor);

//@ts-ignore
expect(measureGeometry.labelOption.cfg.position).toEqual('right');

//@ts-ignore
expect(measureGeometry.labelOption.fields[0]).toEqual('measures');

expect(targetGeometry.getAttribute('size').values[0]).toEqual(20 / 2);
expect(targetGeometry.getYScale().max).toEqual(100);
expect(targetGeometry.getYScale().min).toEqual(0);
Expand Down
47 changes: 47 additions & 0 deletions __tests__/unit/plots/bullet/label-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ describe('bullet*label', () => {
const chart = bullet.chart;
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries;

// @ts-ignore
expect(rangeGeometry.labelOption.fields[0]).toEqual('ranges');
// @ts-ignore
expect(rangeGeometry.labelOption.cfg.position).toEqual('middle');
// @ts-ignore
Expand All @@ -49,11 +51,56 @@ describe('bullet*label', () => {
yField: 'measures',
});

// @ts-ignore
expect(measureGeometry.labelOption.fields[0]).toEqual('measures');

// @ts-ignore
expect(measureGeometry.labelOption.cfg.position).toEqual('middle');
// @ts-ignore
expect(measureGeometry.labelOption.cfg.style.fill).toEqual('#fff');
// @ts-ignore
expect(targetGeometry.labelOption.fields[0]).toEqual('target');
// @ts-ignore
expect(targetGeometry.labelOption.cfg.position).toEqual('right');
// @ts-ignore
expect(targetGeometry.labelOption.cfg.style.fill).toEqual('#fff');
});

it('lable*measure*null', () => {
const bullet = new Bullet(createDiv('lable*measure*null'), {
width: 400,
height: 100,
data: bulletData,
measureField: 'measures',
rangeField: 'ranges',
targetField: 'target',
xField: 'title',
label: {
measure: null,
target: {
position: 'right',
style: {
fill: '#fff',
},
},
},
});

bullet.render();

const chart = bullet.chart;
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries;

expect(rangeGeometry.labelOption).toEqual(undefined);
expect(measureGeometry.getAdjust('stack')).toMatchObject({
xField: 'title',
yField: 'measures',
});

// @ts-ignore
expect(measureGeometry.labelOption).toEqual(undefined);
// @ts-ignore
expect(targetGeometry.labelOption.fields[0]).toEqual('target');
// @ts-ignore
expect(targetGeometry.labelOption.cfg.position).toEqual('right');
// @ts-ignore
Expand Down
26 changes: 13 additions & 13 deletions src/plots/bullet/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isNumber } from '@antv/util';
import { get } from '@antv/util';
import { Params } from '../../core/adaptor';
import { interaction, animation, theme, tooltip } from '../../adaptor/common';
import { flow, pick, transformLabel, deepAssign } from '../../utils';
Expand Down Expand Up @@ -42,9 +42,9 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
seriesField: 'rKey',
isStack: true,
interval: {
color: color?.range,
style: bulletStyle?.range,
size: size?.range,
color: get(color, 'range'),
style: get(bulletStyle, 'range'),
size: get(size, 'range'),
},
},
});
Expand All @@ -60,9 +60,9 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
seriesField: 'mKey',
isStack: true,
interval: {
color: color?.measure,
style: bulletStyle?.measure,
size: size?.measure,
color: get(color, 'measure'),
style: get(bulletStyle, 'measure'),
size: get(size, 'measure'),
},
},
});
Expand All @@ -75,9 +75,9 @@ function geometry(params: Params<BulletOptions>): Params<BulletOptions> {
yField: targetField,
seriesField: 'tKey',
point: {
color: color?.target,
style: bulletStyle?.target,
size: isNumber(size?.target) ? Number(size.target) / 2 : size.target,
color: get(color, 'target'),
style: get(bulletStyle, 'target'),
size: get(size, 'target') / 2,
shape: layout === 'horizontal' ? 'line' : 'hyphen',
},
},
Expand Down Expand Up @@ -168,13 +168,13 @@ function label(params: Params<BulletOptions>): Params<BulletOptions> {
const { label, measureField, targetField, rangeField } = options;
const [rangeGeometry, measureGeometry, targetGeometry] = chart.geometries;

if (label?.range) {
if (get(label, 'range')) {
rangeGeometry.label(`${rangeField}`, transformLabel(label.range));
}
if (label?.measure) {
if (get(label, 'measure')) {
measureGeometry.label(`${measureField}`, transformLabel(label.measure));
}
if (label?.target) {
if (get(label, 'target')) {
targetGeometry.label(`${targetField}`, transformLabel(label.target));
}

Expand Down