Skip to content

Commit 4a72273

Browse files
committed
bugfix: react-flow bidirectional edge (CMEM-7005)
1 parent 7391a4c commit 4a72273

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

src/extensions/react-flow/edges/EdgeDefaultV12.tsx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export type EdgeDefaultV12DataProps = Record<string, unknown> & {
2525
* Size of the "glow" effect when the edge is hovered.
2626
*/
2727
pathGlowWidth?: number;
28-
/*
29-
* Direction of the SVG path is inversed.
30-
* This is important for the placement of the markers and the animation movement.
28+
/**
29+
* Controls where arrow heads appear on the edge.
30+
* - `normal`: arrow at the end (target)
31+
* - `inversed`: arrow at the start (source)
32+
* - `bidirectional`: arrows at both start and end
3133
*/
32-
inversePath?: boolean;
34+
arrowDirection?: "normal" | "inversed" | "bidirectional";
3335
/**
3436
* Callback handler that returns a React element used as edge title.
3537
*/
@@ -64,7 +66,15 @@ export const EdgeDefaultV12 = memo(
6466
data = {},
6567
...edgeOriginalProperties
6668
}: EdgeProps<Edge<EdgeDefaultV12DataProps>>) => {
67-
const { pathGlowWidth = 10, highlightColor, renderLabel, edgeSvgProps, intent, inversePath, strokeType } = data;
69+
const {
70+
pathGlowWidth = 10,
71+
highlightColor,
72+
renderLabel,
73+
edgeSvgProps,
74+
intent,
75+
strokeType,
76+
arrowDirection = "normal",
77+
} = data;
6878

6979
const [edgePath, labelX, labelY] = getBezierPath({
7080
sourceX,
@@ -103,6 +113,13 @@ export const EdgeDefaultV12 = memo(
103113
/>
104114
) : null);
105115

116+
const markerStart =
117+
arrowDirection === "inversed" || arrowDirection === "bidirectional"
118+
? "url(#arrow-closed-reverse)"
119+
: undefined;
120+
const markerEnd =
121+
arrowDirection === "normal" || arrowDirection === "bidirectional" ? "url(#arrow-closed)" : undefined;
122+
106123
return (
107124
<g
108125
className={
@@ -136,8 +153,8 @@ export const EdgeDefaultV12 = memo(
136153
<BaseEdge
137154
id={id}
138155
path={edgePath}
139-
markerStart={inversePath ? "url(#arrow-closed-reverse)" : undefined}
140-
markerEnd={!inversePath ? "url(#arrow-closed)" : undefined}
156+
markerStart={markerStart}
157+
markerEnd={markerEnd}
141158
className={edgeDefaultUtils.createEdgeDefaultClassName({ strokeType })}
142159
interactionWidth={pathGlowWidth}
143160
style={{

src/extensions/react-flow/edges/stories/EdgeDefaultV12.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ InverseEdge.args = {
154154
...Default.args,
155155
id: "inverse",
156156
data: {
157-
inversePath: true,
157+
arrowDirection: "inversed",
158+
},
159+
};
160+
161+
export const Bidirectional = Template.bind({});
162+
Bidirectional.args = {
163+
...Default.args,
164+
id: "bidirectional",
165+
data: {
166+
arrowDirection: "bidirectional",
158167
},
159168
};
160169

0 commit comments

Comments
 (0)