summaryrefslogtreecommitdiff
path: root/frontend/src/components/edges/MergedEdge.tsx
blob: 06c2bf86121bbfb614c977d464693dacd60866cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;