Skip to content

Commit

Permalink
test: 给radial-bar添加pattern的单测,增加文档
Browse files Browse the repository at this point in the history
  • Loading branch information
酥云 committed Aug 17, 2021
1 parent c5cf813 commit e1c5b24
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
71 changes: 71 additions & 0 deletions __tests__/unit/plots/radial-bar/pattern-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { RadialBar } from '../../../../src';
import { createDiv } from '../../../utils/dom';
import { antvStar } from '../../../data/antv-star';

const xField = 'name';
const yField = 'star';

describe('radial-bar pattern', () => {
it('pattern: obj', () => {
const bar = new RadialBar(createDiv(), {
width: 400,
height: 300,
data: antvStar,
xField,
yField,
pattern: {
type: 'line',
},
});
bar.render();

const geometry = bar.chart.geometries[0];
const elements = geometry.elements;
expect(elements[0].shape.attr('fill') instanceof CanvasPattern).toEqual(true);
expect(elements[1].shape.attr('fill') instanceof CanvasPattern).toEqual(true);
expect(elements[2].shape.attr('fill') instanceof CanvasPattern).toEqual(true);

bar.update({
pattern: false,
});

expect(bar.chart.geometries[0].elements[1].shape.attr('fill') instanceof CanvasPattern).toEqual(false);

bar.destroy();
});

it('pattern: callback', () => {
const bar = new RadialBar(createDiv(), {
width: 400,
height: 300,
data: antvStar,
xField,
yField,
pattern: (d) => {
if (d.star > 7346) {
return { type: 'dot' };
}
},
});
bar.render();

const geometry = bar.chart.geometries[0];
const elements = geometry.elements;
expect(elements[7].shape.attr('fill') instanceof CanvasPattern).toEqual(true);
expect(elements[0].shape.attr('fill') instanceof CanvasPattern).toEqual(false);

bar.update({
pattern: (d) => {
if (d.star > 7100) {
return { type: 'dot' };
}
},
});

expect(bar.chart.geometries[0].elements[7].shape.attr('fill') instanceof CanvasPattern).toEqual(true);
expect(bar.chart.geometries[0].elements[6].shape.attr('fill') instanceof CanvasPattern).toEqual(false);
expect(bar.chart.geometries[0].elements[5].shape.attr('fill') instanceof CanvasPattern).toEqual(true);

bar.destroy();
});
});
2 changes: 2 additions & 0 deletions docs/api/plots/radial-bar.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Display type of plot. You can specify `type: 'line'` to display a `Radial-Line`

`markdown:docs/common/color.en.md`

`markdown:docs/common/pattern.en.md`

### Plot Components

`markdown:docs/common/component.en.md`
Expand Down
2 changes: 2 additions & 0 deletions docs/api/plots/radial-bar.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ order: 25

`markdown:docs/common/color.zh.md`

`markdown:docs/common/pattern.zh.md`

### 图表组件

`markdown:docs/common/component.zh.md`
Expand Down

0 comments on commit e1c5b24

Please sign in to comment.