Skip to content

Commit

Permalink
test: 给heatmap添加pattern的单测和文档,并给patternAttr的类型增加布尔值
Browse files Browse the repository at this point in the history
  • Loading branch information
酥云 committed Aug 16, 2021
1 parent 6dae31d commit c5cf813
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
67 changes: 67 additions & 0 deletions __tests__/unit/plots/heatmap/pattern-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Heatmap } from '../../../../src';
import { semanticBasicHeatmapData } from '../../../data/basic-heatmap';
import { createDiv } from '../../../utils/dom';

describe('heatmap: pattern', () => {
it('pattern: obj', () => {
const heatmap = new Heatmap(createDiv('style'), {
width: 400,
height: 300,
data: semanticBasicHeatmapData,
xField: 'name',
yField: 'day',
colorField: 'sales',
pattern: {
type: 'line',
},
});

heatmap.render();

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

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

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

heatmap.destroy();
});

it('pattern: callback', () => {
const heatmap = new Heatmap(createDiv('style'), {
width: 400,
height: 300,
data: semanticBasicHeatmapData,
xField: 'name',
yField: 'day',
colorField: 'sales',
pattern: ({ sales }) => {
if (sales === 10) {
return { type: 'dot' };
}
},
});

heatmap.render();

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

heatmap.update({
pattern: ({ sales }) => {
if (sales === 19) {
return { type: 'dot' };
}
},
});

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

heatmap.destroy();
});
});
2 changes: 2 additions & 0 deletions docs/api/plots/heatmap.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Axis mapping.

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

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

#### shape

<description>**optional** _rect | square | circle_</description>
Expand Down
2 changes: 2 additions & 0 deletions docs/api/plots/heatmap.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ order: 23

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

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

#### shape

<description>**可选** _rect | square | circle_</description>
Expand Down
1 change: 1 addition & 0 deletions src/types/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type ShapeStyle = ShapeAttrs;
export type ColorAttr = string | string[] | ((datum: Datum) => string) | object;
/** pattern 映射*/
export type PatternAttr =
| boolean
| CanvasPattern
| PatternOption
| ((datum: Datum, color: string /** inherit color */) => PatternOption | CanvasPattern);
Expand Down

0 comments on commit c5cf813

Please sign in to comment.