Skip to content

Commit

Permalink
feat: edge supports portLinkToCenter attributes (#5447)
Browse files Browse the repository at this point in the history
* feat(port): add linkToCenter attribute

* fix: ci

* refactor: rename getCurveControlPoint function

* refactor: update snapshots related to port

---------

Co-authored-by: banxuan.zyx <[email protected]>
  • Loading branch information
yvonneyx and banxuan.zyx authored Feb 20, 2024
1 parent a4346dd commit 095581a
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 111 deletions.
56 changes: 28 additions & 28 deletions packages/g6/__tests__/integration/snapshots/static/edge-port.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions packages/g6/src/elements/edges/base-edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import type {
PrefixObject,
} from '../../types';
import { getCubicPath, getLabelPositionStyle, getLoopPoints } from '../../utils/edge';
import { findPort, isSameNode } from '../../utils/element';
import { getEllipseIntersectPoint } from '../../utils/point';
import { findPort, getNodeConnectionPoint, getPortConnectionPoint, isSameNode } from '../../utils/element';
import { omitStyleProps, subStyleProps } from '../../utils/prefix';
import type { SymbolFactor } from '../../utils/symbol';
import * as Symbol from '../../utils/symbol';
Expand Down Expand Up @@ -177,13 +176,13 @@ export abstract class BaseEdge<KT extends BaseEdgeProps<object>> extends BaseSha
const targetPort = findPort(targetNode, targetPortKey, sourceNode);

const sourcePoint = sourcePort
? getEllipseIntersectPoint(targetNode.getCenter(), sourcePort.getBounds())
: sourceNode.getIntersectPoint(targetPort?.getPosition() || targetNode.getCenter());
? getPortConnectionPoint(sourcePort, targetNode, targetPort)
: getNodeConnectionPoint(sourceNode, targetNode, targetPort);
const targetPoint = targetPort
? getEllipseIntersectPoint(sourceNode.getCenter(), targetPort.getBounds())
: targetNode.getIntersectPoint(sourcePort?.getPosition() || sourceNode.getCenter());
? getPortConnectionPoint(targetPort, sourceNode, sourcePort)
: getNodeConnectionPoint(targetNode, sourceNode, sourcePort);

return [sourcePoint || sourceNode.getCenter(), targetPoint || targetNode.getCenter()];
return [sourcePoint, targetPoint];
}

protected getHaloStyle(attributes: ParsedBaseEdgeStyleProps<KT>): false | PathStyleProps {
Expand Down
6 changes: 3 additions & 3 deletions packages/g6/src/elements/edges/cubic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { DisplayObjectConfig } from '@antv/g';
import type { PathArray } from '@antv/util';
import { deepMix } from '@antv/util';
import type { BaseEdgeProps, Point } from '../../types';
import { calculateControlPoint, getCubicPath, parseCurveOffset, parseCurvePosition } from '../../utils/edge';
import { getCubicPath, getCurveControlPoint, parseCurveOffset, parseCurvePosition } from '../../utils/edge';
import type { BaseEdgeStyleProps } from './base-edge';
import { BaseEdge } from './base-edge';

Expand Down Expand Up @@ -61,8 +61,8 @@ export class Cubic extends BaseEdge<CubicKeyStyleProps> {
return controlPoints?.length === 2
? controlPoints
: [
calculateControlPoint(sourcePoint, targetPoint, curvePosition[0], curveOffset[0]),
calculateControlPoint(sourcePoint, targetPoint, curvePosition[1], curveOffset[1]),
getCurveControlPoint(sourcePoint, targetPoint, curvePosition[0], curveOffset[0]),
getCurveControlPoint(sourcePoint, targetPoint, curvePosition[1], curveOffset[1]),
];
}
}
2 changes: 1 addition & 1 deletion packages/g6/src/elements/edges/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { BaseEdgeProps } from '../../types';
import type { BaseEdgeStyleProps, ParsedBaseEdgeStyleProps } from './base-edge';
import { BaseEdge } from './base-edge';

type LineKeyStyleProps = BaseEdgeProps<{}>;
type LineKeyStyleProps = BaseEdgeProps;
export type LineStyleProps = BaseEdgeStyleProps<LineKeyStyleProps>;
type LineOptions = DisplayObjectConfig<LineStyleProps>;

Expand Down
Loading

0 comments on commit 095581a

Please sign in to comment.