@graph-render/react 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +6 -0
- package/CHANGELOG.md +58 -0
- package/README.md +0 -0
- package/dist/index.js +2509 -0
- package/dist/src/components/EdgePath.d.ts +25 -0
- package/dist/src/components/EdgePath.d.ts.map +1 -0
- package/dist/src/components/Graph.d.ts +6 -0
- package/dist/src/components/Graph.d.ts.map +1 -0
- package/dist/src/components/GraphLabels.d.ts +30 -0
- package/dist/src/components/GraphLabels.d.ts.map +1 -0
- package/dist/src/components/GraphNode.d.ts +35 -0
- package/dist/src/components/GraphNode.d.ts.map +1 -0
- package/dist/src/constants/defaults.d.ts +3 -0
- package/dist/src/constants/defaults.d.ts.map +1 -0
- package/dist/src/hooks/useGraphCollapse.d.ts +15 -0
- package/dist/src/hooks/useGraphCollapse.d.ts.map +1 -0
- package/dist/src/hooks/useGraphHover.d.ts +24 -0
- package/dist/src/hooks/useGraphHover.d.ts.map +1 -0
- package/dist/src/hooks/useGraphModel.d.ts +51 -0
- package/dist/src/hooks/useGraphModel.d.ts.map +1 -0
- package/dist/src/hooks/useGraphSearchState.d.ts +29 -0
- package/dist/src/hooks/useGraphSearchState.d.ts.map +1 -0
- package/dist/src/hooks/useStableConfig.d.ts +25 -0
- package/dist/src/hooks/useStableConfig.d.ts.map +1 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/utils/columns.d.ts +7 -0
- package/dist/src/utils/columns.d.ts.map +1 -0
- package/dist/src/utils/pathHighlight.d.ts +29 -0
- package/dist/src/utils/pathHighlight.d.ts.map +1 -0
- package/dist/src/utils/viewport.d.ts +14 -0
- package/dist/src/utils/viewport.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +52 -0
- package/project.json +60 -0
- package/src/components/EdgePath.tsx +103 -0
- package/src/components/Graph.tsx +1545 -0
- package/src/components/GraphLabels.tsx +141 -0
- package/src/components/GraphNode.tsx +214 -0
- package/src/constants/defaults.ts +62 -0
- package/src/hooks/useGraphCollapse.ts +53 -0
- package/src/hooks/useGraphHover.ts +206 -0
- package/src/hooks/useGraphModel.ts +445 -0
- package/src/hooks/useGraphSearchState.ts +215 -0
- package/src/hooks/useStableConfig.ts +108 -0
- package/src/index.ts +57 -0
- package/src/utils/columns.ts +51 -0
- package/src/utils/pathHighlight.ts +160 -0
- package/src/utils/viewport.ts +100 -0
- package/tsconfig.json +12 -0
- package/tsconfig.node.json +11 -0
- package/vite.config.ts +17 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { buildEdgePath, PositionedEdge } from '@graph-render/core';
|
|
3
|
+
|
|
4
|
+
export interface EdgePathProps {
|
|
5
|
+
edge: PositionedEdge;
|
|
6
|
+
color: string;
|
|
7
|
+
width: number;
|
|
8
|
+
curveEdges: boolean;
|
|
9
|
+
curveStrength: number;
|
|
10
|
+
markerEnd?: string;
|
|
11
|
+
isHovered?: boolean;
|
|
12
|
+
isSelected?: boolean;
|
|
13
|
+
hoverColor: string;
|
|
14
|
+
selectionColor?: string;
|
|
15
|
+
labelColor?: string;
|
|
16
|
+
selectionMarker?: string;
|
|
17
|
+
hoverMarker?: string;
|
|
18
|
+
hoverEnabled: boolean;
|
|
19
|
+
hoverStrokeWidth?: number;
|
|
20
|
+
selectedStrokeWidth?: number;
|
|
21
|
+
hitStrokeWidth?: number;
|
|
22
|
+
onHoverChange?: (hovered: boolean) => void;
|
|
23
|
+
onClick?: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Memoised so that unchanged edges are skipped during re-renders of the parent
|
|
27
|
+
// Graph component (e.g. when hover/selection state changes for a different edge).
|
|
28
|
+
// The caller is responsible for keeping callback props (onHoverChange, onClick)
|
|
29
|
+
// referentially stable via useCallback to benefit fully from the bailout.
|
|
30
|
+
export const EdgePath = React.memo(function EdgePath({
|
|
31
|
+
edge,
|
|
32
|
+
color,
|
|
33
|
+
width,
|
|
34
|
+
curveEdges,
|
|
35
|
+
curveStrength,
|
|
36
|
+
markerEnd,
|
|
37
|
+
isHovered,
|
|
38
|
+
isSelected,
|
|
39
|
+
hoverColor,
|
|
40
|
+
selectionColor,
|
|
41
|
+
labelColor,
|
|
42
|
+
selectionMarker,
|
|
43
|
+
hoverMarker,
|
|
44
|
+
hoverEnabled,
|
|
45
|
+
hoverStrokeWidth,
|
|
46
|
+
selectedStrokeWidth,
|
|
47
|
+
hitStrokeWidth,
|
|
48
|
+
onHoverChange,
|
|
49
|
+
onClick,
|
|
50
|
+
}: EdgePathProps) {
|
|
51
|
+
const d = buildEdgePath(edge, curveEdges, curveStrength);
|
|
52
|
+
if (!d) return null;
|
|
53
|
+
|
|
54
|
+
const strokeColor = isHovered ? hoverColor : isSelected ? (selectionColor ?? hoverColor) : color;
|
|
55
|
+
const strokeWidth = isHovered
|
|
56
|
+
? (hoverStrokeWidth ?? width)
|
|
57
|
+
: isSelected
|
|
58
|
+
? (selectedStrokeWidth ?? width + 1)
|
|
59
|
+
: width;
|
|
60
|
+
const resolvedMarker = isHovered
|
|
61
|
+
? (hoverMarker ?? selectionMarker ?? markerEnd)
|
|
62
|
+
: isSelected
|
|
63
|
+
? (selectionMarker ?? markerEnd)
|
|
64
|
+
: markerEnd;
|
|
65
|
+
const label = edge.label != null && edge.labelPosition ? String(edge.label) : null;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<>
|
|
69
|
+
<path
|
|
70
|
+
d={d}
|
|
71
|
+
stroke="transparent"
|
|
72
|
+
strokeWidth={hitStrokeWidth ?? width + 8}
|
|
73
|
+
fill="none"
|
|
74
|
+
pointerEvents="stroke"
|
|
75
|
+
data-graph-edge-interactive="true"
|
|
76
|
+
onMouseEnter={() => hoverEnabled && onHoverChange?.(true)}
|
|
77
|
+
onMouseLeave={() => hoverEnabled && onHoverChange?.(false)}
|
|
78
|
+
onClick={onClick}
|
|
79
|
+
/>
|
|
80
|
+
<path
|
|
81
|
+
d={d}
|
|
82
|
+
stroke={strokeColor}
|
|
83
|
+
strokeWidth={strokeWidth}
|
|
84
|
+
fill="none"
|
|
85
|
+
markerEnd={edge.type === 'directed' ? resolvedMarker : undefined}
|
|
86
|
+
pointerEvents="none"
|
|
87
|
+
/>
|
|
88
|
+
{label && edge.labelPosition ? (
|
|
89
|
+
<text
|
|
90
|
+
x={edge.labelPosition.x}
|
|
91
|
+
y={edge.labelPosition.y - 6}
|
|
92
|
+
textAnchor="middle"
|
|
93
|
+
fontSize={12}
|
|
94
|
+
fontWeight={600}
|
|
95
|
+
fill={labelColor ?? '#334155'}
|
|
96
|
+
pointerEvents="none"
|
|
97
|
+
>
|
|
98
|
+
{label}
|
|
99
|
+
</text>
|
|
100
|
+
) : null}
|
|
101
|
+
</>
|
|
102
|
+
);
|
|
103
|
+
});
|