Skip to content

Commit

Permalink
test(gauge): coverage increase (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored Nov 18, 2020
1 parent e0a1e9d commit fe08aa6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
85 changes: 85 additions & 0 deletions __tests__/unit/plots/gauge/shapes/index-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Gauge } from '../../../../../src';
import { pick } from '../../../../../src/utils';
import { createDiv } from '../../../../utils/dom';

describe('gauge', () => {
it('no indicator', async () => {
const gauge = new Gauge(createDiv(), {
width: 600,
height: 300,
autoFit: false,
percent: 0.75,

indicator: false,
});

gauge.render();
expect(gauge.chart.views.length).toBe(1);
gauge.destroy();
});

it('no pin', async () => {
const gauge = new Gauge(createDiv(), {
width: 600,
height: 300,
autoFit: false,
percent: 0.75,

indicator: {
pointer: {
style: {
stroke: 'pink',
},
},
// @ts-ignore
pin: false,
},
});

gauge.render();

// @ts-ignore
expect(gauge.chart.views[0].geometries[0].elements[0].container.getChildren()[0].getChildren().length).toBe(1);
// @ts-ignore
expect(gauge.chart.views[0].geometries[0].elements[0].container.getChildren()[0].getChildren()[0].get('name')).toBe(
'pointer'
);

gauge.destroy();
});

it('no pointer', async () => {
const gauge = new Gauge(createDiv(), {
width: 600,
height: 300,
autoFit: false,
percent: 0.75,

indicator: {
// @ts-ignore
pointer: false,

pin: {
style: {
stroke: 'blue',
},
},
},
// @ts-ignore
statistic: false,
});

gauge.render();

// @ts-ignore
expect(gauge.chart.views[0].geometries[0].elements[0].container.getChildren()[0].getChildren().length).toBe(1);
// @ts-ignore
expect(gauge.chart.views[0].geometries[0].elements[0].container.getChildren()[0].getChildren()[0].get('name')).toBe(
'pin'
);

expect(gauge.chart.getController('annotation').getComponents().length).toBe(0);

gauge.destroy();
});
});
7 changes: 2 additions & 5 deletions src/plots/gauge/adaptor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isString, clamp } from '@antv/util';
import { isString, clamp, size } from '@antv/util';
import { interaction, animation, theme, scale } from '../../adaptor/common';
import { Params } from '../../core/adaptor';
import { Data } from '../../types';
Expand All @@ -15,10 +15,7 @@ function geometry(params: Params<GaugeOptions>): Params<GaugeOptions> {
const { chart, options } = params;
const { percent, range, radius, innerRadius, startAngle, endAngle, axis, indicator } = options;
const { ticks, color } = range;
let clampTicks = ticks;
if (!clampTicks?.length) {
clampTicks = [0, clamp(percent, 0, 1), 1];
}
const clampTicks = size(ticks) ? ticks : [0, clamp(percent, 0, 1), 1];

// 指标 & 指针
// 如果开启在应用
Expand Down
2 changes: 2 additions & 0 deletions src/plots/gauge/shapes/gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ registerShape('point', 'gauge-indicator', {
if (pointer) {
// pointer
group.addShape('line', {
name: 'pointer',
attrs: {
x1: center.x,
y1: center.y,
Expand All @@ -30,6 +31,7 @@ registerShape('point', 'gauge-indicator', {
// pin
if (pin) {
group.addShape('circle', {
name: 'pin',
attrs: {
x: center.x,
y: center.y,
Expand Down

0 comments on commit fe08aa6

Please sign in to comment.