Spaces:
Running
Running
bigwolfe
commited on
Commit
·
a9c257b
1
Parent(s):
7f96410
color gradients on graph nodes
Browse files
frontend/src/components/GraphView.tsx
CHANGED
|
@@ -100,18 +100,33 @@ export function GraphView({ onSelectNote }: GraphViewProps) {
|
|
| 100 |
}
|
| 101 |
}, [data, isLoading]);
|
| 102 |
|
| 103 |
-
//
|
| 104 |
-
const
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
}
|
| 109 |
-
const c = (hash & 0x00ffffff).toString(16).toUpperCase();
|
| 110 |
-
return '#' + '00000'.substring(0, 6 - c.length) + c;
|
| 111 |
};
|
| 112 |
|
| 113 |
-
// Node styling based on theme and group
|
| 114 |
-
const defaultNodeColor = isDark ? '#94a3b8' : '#64748b';
|
| 115 |
const linkColor = isDark ? '#334155' : '#e2e8f0';
|
| 116 |
const backgroundColor = isDark ? '#020817' : '#ffffff';
|
| 117 |
|
|
@@ -150,9 +165,9 @@ export function GraphView({ onSelectNote }: GraphViewProps) {
|
|
| 150 |
ref={graphRef}
|
| 151 |
graphData={data}
|
| 152 |
nodeLabel="label"
|
| 153 |
-
nodeColor={
|
| 154 |
linkColor={() => linkColor}
|
| 155 |
-
linkWidth={
|
| 156 |
backgroundColor={backgroundColor}
|
| 157 |
onNodeClick={handleNodeClick}
|
| 158 |
nodeRelSize={6}
|
|
|
|
| 100 |
}
|
| 101 |
}, [data, isLoading]);
|
| 102 |
|
| 103 |
+
// Calculate max connectivity for gradient normalization
|
| 104 |
+
const maxVal = useMemo(() => {
|
| 105 |
+
return Math.max(1, ...data.nodes.map(node => node.val || 1));
|
| 106 |
+
}, [data.nodes]);
|
| 107 |
+
|
| 108 |
+
// Node styling based on theme and connectivity
|
| 109 |
+
const getNodeColor = (node: any) => {
|
| 110 |
+
const val = node.val || 1;
|
| 111 |
+
// Normalize value 0..1 (logarithmic scale often looks better for power-law graphs)
|
| 112 |
+
const normalized = Math.min(1, (val - 1) / (Math.max(maxVal, 2) - 1));
|
| 113 |
+
|
| 114 |
+
if (isDark) {
|
| 115 |
+
// Dark mode: Slate-400 (#94a3b8) to Lime-300 (#bef264)
|
| 116 |
+
// Simple linear interpolation for RGB
|
| 117 |
+
const r = 148 + (190 - 148) * normalized;
|
| 118 |
+
const g = 163 + (242 - 163) * normalized;
|
| 119 |
+
const b = 184 + (100 - 184) * normalized;
|
| 120 |
+
return `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;
|
| 121 |
+
} else {
|
| 122 |
+
// Light mode: Slate-500 (#64748b) to Lime-500 (#84cc16)
|
| 123 |
+
const r = 100 + (132 - 100) * normalized;
|
| 124 |
+
const g = 116 + (204 - 116) * normalized;
|
| 125 |
+
const b = 139 + (22 - 139) * normalized;
|
| 126 |
+
return `rgb(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)})`;
|
| 127 |
}
|
|
|
|
|
|
|
| 128 |
};
|
| 129 |
|
|
|
|
|
|
|
| 130 |
const linkColor = isDark ? '#334155' : '#e2e8f0';
|
| 131 |
const backgroundColor = isDark ? '#020817' : '#ffffff';
|
| 132 |
|
|
|
|
| 165 |
ref={graphRef}
|
| 166 |
graphData={data}
|
| 167 |
nodeLabel="label"
|
| 168 |
+
nodeColor={getNodeColor}
|
| 169 |
linkColor={() => linkColor}
|
| 170 |
+
linkWidth={2} //width of links between nodes
|
| 171 |
backgroundColor={backgroundColor}
|
| 172 |
onNodeClick={handleNodeClick}
|
| 173 |
nodeRelSize={6}
|