Skip to content

Commit 948e99f

Browse files
committed
Update node links: refactored link logic to prioritize connections between similar-colored nodes, ensuring links reflect shared datatypes and form tighter clusters.
1 parent 0caca39 commit 948e99f

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

src/design/Layouts/FullScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const FullScreen = () => {
134134
height: "calc(100vh - 6rem)",
135135
boxSizing: "border-box",
136136
marginTop: "6rem",
137-
backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2000 1500'%3E%3Cdefs%3E%3CradialGradient id='a' gradientUnits='objectBoundingBox'%3E%3Cstop offset='0' stop-color='%23000000'/%3E%3Cstop offset='1' stop-color='%235865F2'/%3E%3C/radialGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='0' y1='750' x2='1550' y2='750'%3E%3Cstop offset='0' stop-color='%232c3379'/%3E%3Cstop offset='1' stop-color='%235865F2'/%3E%3C/linearGradient%3E%3Cpath id='s' fill='url(%23b)' d='M1549.2 51.6c-5.4 99.1-20.2 197.6-44.2 293.6c-24.1 96-57.4 189.4-99.3 278.6c-41.9 89.2-92.4 174.1-150.3 253.3c-58 79.2-123.4 152.6-195.1 219c-71.7 66.4-149.6 125.8-232.2 177.2c-82.7 51.4-170.1 94.7-260.7 129.1c-90.6 34.4-184.4 60-279.5 76.3C192.6 1495 96.1 1502 0 1500c96.1-2.1 191.8-13.3 285.4-33.6c93.6-20.2 185-49.5 272.5-87.2c87.6-37.7 171.3-83.8 249.6-137.3c78.4-53.5 151.5-114.5 217.9-181.7c66.5-67.2 126.4-140.7 178.6-218.9c52.3-78.3 96.9-161.4 133-247.9c36.1-86.5 63.8-176.2 82.6-267.6c18.8-91.4 28.6-184.4 29.6-277.4c0.3-27.6 23.2-48.7 50.8-48.4s49.5 21.8 49.2 49.5c0 0.7 0 1.3-0.1 2L1549.2 51.6z'/%3E%3Cg id='g'%3E%3Cuse href='%23s' transform='scale(0.12) rotate(60)'/%3E%3Cuse href='%23s' transform='scale(0.2) rotate(10)'/%3E%3Cuse href='%23s' transform='scale(0.25) rotate(40)'/%3E%3Cuse href='%23s' transform='scale(0.3) rotate(-20)'/%3E%3Cuse href='%23s' transform='scale(0.4) rotate(-30)'/%3E%3Cuse href='%23s' transform='scale(0.5) rotate(20)'/%3E%3Cuse href='%23s' transform='scale(0.6) rotate(60)'/%3E%3Cuse href='%23s' transform='scale(0.7) rotate(10)'/%3E%3Cuse href='%23s' transform='scale(0.835) rotate(-40)'/%3E%3Cuse href='%23s' transform='scale(0.9) rotate(40)'/%3E%3Cuse href='%23s' transform='scale(1.05) rotate(25)'/%3E%3Cuse href='%23s' transform='scale(1.2) rotate(8)'/%3E%3Cuse href='%23s' transform='scale(1.333) rotate(-60)'/%3E%3Cuse href='%23s' transform='scale(1.45) rotate(-30)'/%3E%3Cuse href='%23s' transform='scale(1.6) rotate(10)'/%3E%3C/g%3E%3C/defs%3E%3Cg transform='translate(400 0)'%3E%3Cg transform='translate(0 375)'%3E%3Ccircle fill='url(%23a)' r='3000'/%3E%3Cg opacity='0.5'%3E%3Ccircle fill='url(%23a)' r='2000'/%3E%3Ccircle fill='url(%23a)' r='1800'/%3E%3Ccircle fill='url(%23a)' r='1700'/%3E%3Ccircle fill='url(%23a)' r='1651'/%3E%3Ccircle fill='url(%23a)' r='1450'/%3E%3Ccircle fill='url(%23a)' r='1250'/%3E%3Ccircle fill='url(%23a)' r='1175'/%3E%3Ccircle fill='url(%23a)' r='900'/%3E%3Ccircle fill='url(%23a)' r='750'/%3E%3Ccircle fill='url(%23a)' r='500'/%3E%3Ccircle fill='url(%23a)' r='380'/%3E%3Ccircle fill='url(%23a)' r='250'/%3E%3C/g%3E%3Cg transform='rotate(-273.6 0 0)'%3E%3Cuse href='%23g' transform='rotate(10)'/%3E%3Cuse href='%23g' transform='rotate(120)'/%3E%3Cuse href='%23g' transform='rotate(240)'/%3E%3C/g%3E%3Ccircle fill-opacity='0.99' fill='url(%23a)' r='3000'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")`,
137+
backgroundImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2000 1500'%3E%3Cdefs%3E%3CradialGradient id='a' gradientUnits='objectBoundingBox'%3E%3Cstop offset='0' stop-color='%23000000'/%3E%3Cstop offset='1' stop-color='%235865F2'/%3E%3C/radialGradient%3E%3ClinearGradient id='b' gradientUnits='userSpaceOnUse' x1='0' y1='750' x2='1550' y2='750'%3E%3Cstop offset='0' stop-color='%232c3379'/%3E%3Cstop offset='1' stop-color='%235865F2'/%3E%3C/linearGradient%3E%3Cpath id='s' fill='url(%23b)' d='M1549.2 51.6c-5.4 99.1-20.2 197.6-44.2 293.6c-24.1 96-57.4 189.4-99.3 278.6c-41.9 89.2-92.4 174.1-150.3 253.3c-58 79.2-123.4 152.6-195.1 219c-71.7 66.4-149.6 125.8-232.2 177.2c-82.7 51.4-170.1 94.7-260.7 129.1c-90.6 34.4-184.4 60-279.5 76.3C192.6 1495 96.1 1502 0 1500c96.1-2.1 191.8-13.3 285.4-33.6c93.6-20.2 185-49.5 272.5-87.2c87.6-37.7 171.3-83.8 249.6-137.3c78.4-53.5 151.5-114.5 217.9-181.7c66.5-67.2 126.4-140.7 178.6-218.9c52.3-78.3 96.9-161.4 133-247.9c36.1-86.5 63.8-176.2 82.6-267.6c18.8-91.4 28.6-184.4 29.6-277.4c0.3-27.6 23.2-48.7 50.8-48.4s49.5 21.8 49.2 49.5c0 0.7 0 1.3-0.1 2L1549.2 51.6z'/%3E%3Cg id='g'%3E%3Cuse href='%23s' transform='scale(0.12) rotate(60)'/%3E%3Cuse href='%23s' transform='scale(0.2) rotate(10)'/%3E%3Cuse href='%23s' transform='scale(0.25) rotate(40)'/%3E%3Cuse href='%23s' transform='scale(0.3) rotate(-20)'/%3E%3Cuse href='%23s' transform='scale(0.4) rotate(-30)'/%3E%3Cuse href='%23s' transform='scale(0.5) rotate(20)'/%3E%3Cuse href='%23s' transform='scale(0.6) rotate(60)'/%3E%3Cuse href='%23s' transform='scale(0.7) rotate(10)'/%3E%3Cuse href='%23s' transform='scale(0.835) rotate(-40)'/%3E%3Cuse href='%23s' transform='scale(0.9) rotate(40)'/%3E%3Cuse href='%23s' transform='scale(1.05) rotate(25)'/%3E%3Cuse href='%23s' transform='scale(1.2) rotate(8)'/%3E%3Cuse href='%23s' transform='scale(1.333) rotate(-60)'/%3E%3Cuse href='%23s' transform='scale(1.45) rotate(-30)'/%3E%3Cuse href='%23s' transform='scale(1.6) rotate(10)'/%3E%3C/g%3E%3C/defs%3E%3Cg transform='rotate(0 0 0)'%3E%3Cg transform='rotate(0 0 0)'%3E%3Ccircle fill='url(%23a)' r='3000'/%3E%3Cg opacity='0.5'%3E%3Ccircle fill='url(%23a)' r='2000'/%3E%3Ccircle fill='url(%23a)' r='1800'/%3E%3Ccircle fill='url(%23a)' r='1700'/%3E%3Ccircle fill='url(%23a)' r='1651'/%3E%3Ccircle fill='url(%23a)' r='1450'/%3E%3Ccircle fill='url(%23a)' r='1250'/%3E%3Ccircle fill='url(%23a)' r='1175'/%3E%3Ccircle fill='url(%23a)' r='900'/%3E%3Ccircle fill='url(%23a)' r='750'/%3E%3Ccircle fill='url(%23a)' r='500'/%3E%3Ccircle fill='url(%23a)' r='380'/%3E%3Ccircle fill='url(%23a)' r='250'/%3E%3C/g%3E%3Cg transform='rotate(0 0 0)'%3E%3Cuse href='%23g' transform='rotate(10)'/%3E%3Cuse href='%23g' transform='rotate(120)'/%3E%3Cuse href='%23g' transform='rotate(240)'/%3E%3C/g%3E%3Ccircle fill-opacity='0.83' fill='url(%23a)' r='3000'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E")`,
138138
backgroundAttachment: "fixed",
139139
backgroundSize: "cover",
140140
overflow: "auto",

src/modules/universe/NeuroJsonGraph.tsx

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface NodeObject {
1818
support: string;
1919
url: string;
2020
datasets: number;
21-
standard: string[]; // define type of standard property
21+
standard: string[];
2222
}
2323

2424
const NeuroJsonGraph: React.FC<{
@@ -71,14 +71,7 @@ const NeuroJsonGraph: React.FC<{
7171
return `rgb(${avgR}, ${avgG}, ${avgB})`;
7272
};
7373

74-
// Function to determine color and size based on node size
75-
// const size2colorAndSize = (size: number) => {
76-
// if (size > 32) return { color: Colors.primary.dark, size: 10 };
77-
// if (size > 3) return { color: Colors.primary.main, size: 7 };
78-
// return { color: Colors.primary.light, size: 5 };
79-
// };
80-
81-
// Custom random number generator
74+
// Custom random number generator for link connection usage
8275
const mulberry32 = (a: number) => {
8376
return function () {
8477
let t = (a += 0x6d2b79f5);
@@ -102,33 +95,30 @@ const NeuroJsonGraph: React.FC<{
10295
return;
10396
}
10497

105-
let colorlist: { brightness: number; index: number }[] = registry.map(
106-
(db, index) => {
98+
// create a colorlist after blend colors for nodes
99+
let colorlist: { brightness: number; index: number; color: string }[] =
100+
registry.map((db, index) => {
107101
const colorStr = blendColors(db.datatype); // Get color in "rgb(R,G,B)" format
108-
109-
// Extract RGB values from the string
110102
const match = colorStr.match(/\d+/g); // Get numbers from "rgb(R,G,B)"
111-
if (!match) return { brightness: 255, index }; // Default to white if extraction fails
103+
if (!match)
104+
return { brightness: 255, index, color: "rgb(255, 255, 255)" }; // Default to white if extraction fails
112105

113106
const [r, g, b] = match.map(Number); // Convert to numbers
114107
const brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b; // Compute brightness
115108

116-
return { brightness, index };
117-
}
118-
);
109+
return { brightness, index, color: colorStr };
110+
});
119111

120112
// Sort nodes by brightness
121113
colorlist.sort((a, b) => a.brightness - b.brightness);
122114

123115
// Prepare graph data
124116
const graphData = {
125117
nodes: registry.map((db) => {
126-
// const { color, size } = size2colorAndSize(db.datasets);
127118
const color = blendColors(db.datatype);
128-
// const size = db.datasets > 32 ? 10 : db.datasets > 3 ? 7 : 5;
129-
130-
let size = db.datasets > 100 ? Math.log(db.datasets) : db.datasets / 5;
131-
size = Math.max(size, 2);
119+
let size =
120+
db.datasets > 100 ? Math.log(db.datasets) * 2.5 : db.datasets / 6;
121+
size = Math.max(size, 4);
132122

133123
return {
134124
id: db.id,
@@ -144,13 +134,13 @@ const NeuroJsonGraph: React.FC<{
144134
};
145135
}),
146136

147-
links: registry.flatMap((db, index) => {
148-
const coloridx = index;
149-
const i = colorlist[coloridx].index; // Get shuffled node index
150-
const node = registry[i]; // Get actual node
151-
152-
// Determine number of connections (proportional to dataset size)
153-
const conn = 1 + Math.round(rngfun() * Math.max(1, node.datasets / 20));
137+
links: colorlist.flatMap(({ index, color }, colorIdx) => {
138+
const node = registry[index];
139+
// Determine number of connections
140+
const scaledDatasets =
141+
node.datasets > 100 ? Math.log(node.datasets) : node.datasets;
142+
const conn =
143+
1 + Math.round(rngfun() * Math.max(1, scaledDatasets / 20));
154144

155145
const connections: {
156146
source: string;
@@ -159,17 +149,19 @@ const NeuroJsonGraph: React.FC<{
159149
visible: boolean;
160150
}[] = [];
161151

162-
for (let j = 1; j <= conn; j++) {
163-
if (index + j >= registry.length) break; // Prevent out-of-bounds errors
164-
165-
const targetIdx = colorlist[index + j].index; // Get next closest in brightness
166-
const targetNode = registry[targetIdx];
152+
for (let j = -conn; j <= conn; j++) {
153+
if (j === 0) continue;
154+
const targetColorIdx = colorIdx + j;
155+
if (targetColorIdx < 0 || targetColorIdx >= colorlist.length)
156+
continue; // Prevent out-of-bounds errors
157+
const targetIdx = colorlist[targetColorIdx].index; // Get registry node index in colorlist order
158+
const targetNode = registry[targetIdx]; // Get target node info in registry
167159

168160
connections.push({
169161
source: node.id,
170162
target: targetNode.id,
171-
color: blendColors(node.datatype), // Keep consistent coloring
172-
visible: true, // Make links visible
163+
color: blendColors(node.datatype),
164+
visible: true,
173165
});
174166
}
175167

@@ -180,7 +172,7 @@ const NeuroJsonGraph: React.FC<{
180172
// Initialize 3D Force Graph
181173
const Graph = new ForceGraph3D(graphRef.current)
182174
.graphData(graphData)
183-
.nodeRelSize(2)
175+
.nodeRelSize(1)
184176
.nodeColor((node) => (node as NodeObject).color)
185177
.linkWidth(1)
186178
.backgroundColor("rgba(0,0,0,0)")
@@ -239,8 +231,8 @@ const NeuroJsonGraph: React.FC<{
239231
// Add label as CSS2DObject
240232
const label = new CSS2DObject(document.createElement("div"));
241233
label.element.textContent = castNode.dbname || "Unnamed";
242-
label.element.style.color = Colors.white;
243-
label.element.style.fontSize = "12px";
234+
label.element.style.color = Colors.lightYellow;
235+
label.element.style.fontSize = "16px";
244236
label.element.style.pointerEvents = "none";
245237
label.position.set(0, 10, 0);
246238
group.add(label);

src/pages/Home.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,14 @@ const Home: React.FC = () => {
7272
<Box
7373
sx={{
7474
overflow: "hidden",
75-
maxWidth: "42%",
75+
maxWidth: "35%",
7676
zIndex: "3",
7777
position: "absolute",
7878
top: "6%",
79-
left: "5%",
79+
left: "1%",
8080
backgroundColor: "none",
8181
padding: "1.5rem",
8282
borderRadius: "8px",
83-
boxShadow: "0 4px 8px rgba(0, 0, 0, 0.1)",
8483
}}
8584
>
8685
{/* Header Section */}

0 commit comments

Comments
 (0)