Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support CornerPlacement for port #6825

Open
wants to merge 3 commits into
base: v5
Choose a base branch
from

Conversation

Crystal-RainSlide
Copy link
Contributor

@Crystal-RainSlide Crystal-RainSlide commented Mar 4, 2025

Unlike badges (whose placement is handled by getTextStyleByPlacement(), which supports CornerPlacement), ports don't support CornerPlacement like top-left. This PR fixes this by adding keys in CornerPlacement to PORT_MAP.

Also, document related to ports is missing content. It don't mention its key and placement prop:
https://g6.antv.antgroup.com/api/elements/nodes/base-node#连接桩样式-ports
Readers can only guess the placement prop from the document about badges beside it.

This fix don't calculate the position with node border. Thus it only works for the corner of rect-shaped nodes. Better note about this when adding document about ports.


The 2nd commits improves packages/g6/src/utils/element.ts with:

  • rename param for PORT_MAP from ports to the more accurate portMap.
  • getConnectionPoint() is calling getNodeConnectionPoint() with param node: Node | Combo,
    but getNodeConnectionPoint() only has param node: Node. Changed it to nodeLike: Node | Combo.
  • optimized getTextStyleByPlacement(), saved one ternary operator with the top and bottom constants.
  • for setAttributes(), add type Partial<BaseShapeStyleProps> to param style to match with element: BaseShape<any>.
  • improve comments for some params.

For packages/g6/src/utils/edge.ts, the 3rd commit replaces array[array.length - 1] with array.at(-1).
array.at()'s typing is static, it always return a type that includes undefined, regardless of situation.
Since controlPoints are [Point, Point], controlPoints.at(-1) can only be Point.

For packages/g6/src/runtime/layout.ts, the 3rd commit replace two slow, irrational for of loop + array.indexOf() with faster, reasonable for loop.

@zhongyunWan
Copy link
Contributor

It is truly excellent news. We have observed that you possess a remarkable level of enthusiasm for contributing, and we eagerly anticipate collaborating with you on additional G6-related projects in the subsequent period.😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants