fix: support CornerPlacement for port #6825
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Unlike badges (whose placement is handled by
getTextStyleByPlacement()
, which supportsCornerPlacement
), ports don't supportCornerPlacement
liketop-left
. This PR fixes this by adding keys inCornerPlacement
toPORT_MAP
.Also, document related to ports is missing content. It don't mention its
key
andplacement
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:PORT_MAP
fromports
to the more accurateportMap
.getConnectionPoint()
is callinggetNodeConnectionPoint()
with paramnode: Node | Combo
,but
getNodeConnectionPoint()
only has paramnode: Node
. Changed it tonodeLike: Node | Combo
.getTextStyleByPlacement()
, saved one ternary operator with thetop
andbottom
constants.setAttributes()
, add typePartial<BaseShapeStyleProps>
to paramstyle
to match withelement: BaseShape<any>
.For
packages/g6/src/utils/edge.ts
, the 3rd commit replacesarray[array.length - 1]
witharray.at(-1)
.array.at()
's typing is static, it always return a type that includesundefined
, regardless of situation.Since
controlPoints
are[Point, Point]
,controlPoints.at(-1)
can only bePoint
.For
packages/g6/src/runtime/layout.ts
, the 3rd commit replace two slow, irrational for of loop +array.indexOf()
with faster, reasonable for loop.