diff options
| author | blackhao <13851610112@163.com> | 2025-12-08 15:07:12 -0600 |
|---|---|---|
| committer | blackhao <13851610112@163.com> | 2025-12-08 15:07:12 -0600 |
| commit | f97b7a1bfa220a0947f2cd63c23f4faa9fcd42e7 (patch) | |
| tree | d1d6eb9e5196afb7bac8a22d0d7587aedcada450 /frontend/src/components/edges/MergedEdge.tsx | |
| parent | 93dbe11014cf967690727c25e89d9d1075008c24 (diff) | |
merge logic
Diffstat (limited to 'frontend/src/components/edges/MergedEdge.tsx')
| -rw-r--r-- | frontend/src/components/edges/MergedEdge.tsx | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/frontend/src/components/edges/MergedEdge.tsx b/frontend/src/components/edges/MergedEdge.tsx new file mode 100644 index 0000000..06c2bf8 --- /dev/null +++ b/frontend/src/components/edges/MergedEdge.tsx @@ -0,0 +1,77 @@ +import { BaseEdge, getBezierPath } from 'reactflow'; +import type { EdgeProps } from 'reactflow'; + +interface MergedEdgeData { + gradient?: string; + isMerged?: boolean; + colors?: string[]; +} + +const MergedEdge = ({ + id, + sourceX, + sourceY, + targetX, + targetY, + sourcePosition, + targetPosition, + style = {}, + data, + markerEnd, +}: EdgeProps<MergedEdgeData>) => { + const [edgePath] = getBezierPath({ + sourceX, + sourceY, + sourcePosition, + targetX, + targetY, + targetPosition, + }); + + // If this is a merged trace, create a gradient + const isMerged = data?.isMerged; + const colors = data?.colors || []; + + if (isMerged && colors.length >= 2) { + const gradientId = `gradient-${id}`; + + return ( + <> + <defs> + <linearGradient id={gradientId} x1="0%" y1="0%" x2="100%" y2="0%"> + {colors.map((color, idx) => ( + <stop + key={idx} + offset={`${(idx / (colors.length - 1)) * 100}%`} + stopColor={color} + /> + ))} + </linearGradient> + </defs> + <BaseEdge + id={id} + path={edgePath} + style={{ + ...style, + stroke: `url(#${gradientId})`, + strokeWidth: 3, + }} + markerEnd={markerEnd} + /> + </> + ); + } + + // Regular edge + return ( + <BaseEdge + id={id} + path={edgePath} + style={style} + markerEnd={markerEnd} + /> + ); +}; + +export default MergedEdge; + |
