-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphin):shared setStatusStyle code
- Loading branch information
1 parent
158a94a
commit 228f530
Showing
2 changed files
with
40 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* | ||
* @param shapes 元素组合的shape集合 | ||
* @param statusStyle 该节点的样式:可以是状态激活样式,也可以是默认样式 | ||
* @param parseAttr 将用户传递的JSON解析为G理解的Attr | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const setStatusStyle = (shapes: any, statusStyle: any, parseAttr: (style: any, shapeName: string) => any) => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
try { | ||
shapes.forEach((shapeItem: any) => { | ||
const itemShapeName = shapeItem.cfg.name; | ||
const style = statusStyle[itemShapeName]; | ||
if (style) { | ||
const { animate, visible, ...otherAttrs } = parseAttr(style, itemShapeName); | ||
shapeItem.attr(otherAttrs); | ||
shapeItem.cfg.visible = visible !== false; | ||
if (animate) { | ||
const { attrs, ...animateOptions } = animate; | ||
shapeItem.animate(attrs, animateOptions); | ||
} | ||
} | ||
}); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; |