-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.ts
34 lines (29 loc) · 773 Bytes
/
style.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { DisplayObject, BaseStyleProps } from '@antv/g';
const defaultStyle: BaseStyleProps = {
visibility: 'visible',
opacity: 1,
fillOpacity: 1,
strokeOpacity: 1,
};
export function getStyle(element: DisplayObject, key: string) {
return element.style[key] ?? defaultStyle[key];
}
export function setStyle(
element: DisplayObject,
key: string,
value: any,
recursive: boolean,
) {
element.style[key] = value;
if (recursive) {
element.children.forEach((child: DisplayObject) =>
setStyle(child, key, value, recursive),
);
}
}
export function hide(element: DisplayObject) {
setStyle(element, 'visibility', 'hidden', true);
}
export function show(element: DisplayObject) {
setStyle(element, 'visibility', 'visible', true);
}