Skip to content

Commit

Permalink
chore: add test case for tag, marker
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc committed Oct 8, 2023
1 parent 59f69ed commit b7a71d4
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 16 deletions.
8 changes: 7 additions & 1 deletion __tests__/integration/components/checkbox/checkbox1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function Checkbox1() {
})
);

group.appendChild(
const ck = group.appendChild(
new Checkbox({
style: {
x: 10,
Expand All @@ -25,5 +25,11 @@ export function Checkbox1() {
})
);

ck.addEventListener('click', () => {
ck.update({
checked: !ck.attr('checked'),
});
});

return group;
}
1 change: 1 addition & 0 deletions __tests__/integration/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './marker';
export * from './text';
export * from './timebar';
export * from './select';
export * from './tag';
27 changes: 16 additions & 11 deletions __tests__/integration/components/marker/marker-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import { Marker } from '../../../../src';
export const Marker1 = () => {
const group = new Group();

group.appendChild(
new Marker({
style: {
x: 150,
y: 150,
symbol: 'circle',
size: 10,
fill: 'red',
},
})
);
const markers = Marker.getSymbols();

markers.forEach((marker, index) => {
group.appendChild(
new Marker({
style: {
x: 20 + (index % 10) * 50,
y: 150 + Math.floor(index / 10) * 50,
symbol: marker,
size: 16,
stroke: 'blue',
lineWidth: 2,
},
})
);
});

return group;
};
1 change: 1 addition & 0 deletions __tests__/integration/components/tag/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tag-1';
59 changes: 59 additions & 0 deletions __tests__/integration/components/tag/tag-1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Group } from '@antv/g';
import { Tag } from '../../../../src';

export const Tag1 = () => {
const group = new Group();

group.appendChild(
new Tag({
style: {
x: 100,
y: 100,
text: 'G2',
},
})
);

group.appendChild(
new Tag({
style: {
x: 200,
y: 100,
text: 'G6',
backgroundFill: '#DBF1B7',
labelFill: 'red',
marker: {
size: 8,
symbol: 'diamond',
stroke: '#5B8FF9',
},
},
})
);

const tag = group.appendChild(
new Tag({
style: {
x: 300,
y: 100,
text: 'L7',
radius: 6,
padding: [6, 24],
},
})
);

tag.addEventListener('mouseenter', () => {
tag.update({
backgroundFill: '#5B8FF9',
});
});

tag.addEventListener('mouseleave', () => {
tag.update({
backgroundFill: '#DBF1B7',
});
});

return group;
};
Binary file modified __tests__/integration/snapshots/Marker1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __tests__/integration/snapshots/Tag1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/ui/marker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export class Marker extends Component<MarkerStyleProps> {
public static getSymbol = (type: string): FunctionalSymbol | undefined => {
return Marker.MARKER_SYMBOL_MAP.get(type);
};

/**
* @returns 获取已经注册的 icon 的类型
*/
public static getSymbols = () => {
return Array.from(Marker.MARKER_SYMBOL_MAP.keys());
};
}

/** Shapes for Point Geometry */
Expand Down
2 changes: 1 addition & 1 deletion src/ui/switch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Switch extends Component<SwitchStyleProps> {
public static tag = 'switch';

/**
* 开关
* 开关
*/
private checked!: boolean;

Expand Down
6 changes: 3 additions & 3 deletions src/ui/tag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ export class Tag extends Component<TagStyleProps> {
.attr('className', 'tag-content')
.style('zIndex', 0)
.node();
const style = marker ? { marker } : { symbol: 'triangle', size: 0 };
const markerStyle = marker || { symbol: 'triangle', size: 0 };
// @ts-ignore
const markerShape = maybeAppend(group, '.tag-marker', () => new Marker({ style }))
const markerShape = maybeAppend(group, '.tag-marker', () => new Marker({ style: markerStyle }))
.attr('className', 'tag-marker')
.call((selection) => {
(selection.node() as Marker).clear();
})
.update(style)
.update(markerStyle)
.node() as Marker;

const { x, y } = getTextPosition(markerShape, spacing);
Expand Down

0 comments on commit b7a71d4

Please sign in to comment.