poc: improve galaxy rendering

This commit is contained in:
2025-09-10 23:52:33 +02:00
parent 3f14343b99
commit d1d9d5b44e

View File

@@ -73,10 +73,17 @@ exportToHtml("loadGalaxy", async (config: GalaxyConfig) => {
width: 0.1, width: 0.1,
}, },
}, },
{
selector: ".direct",
style: {
width: "5px",
"line-color": "red",
},
},
], ],
layout: { layout: {
name: "d3-force", name: "d3-force",
animate: false, animate: true,
fit: false, fit: false,
ungrabifyWhileSimulating: true, ungrabifyWhileSimulating: true,
fixedAfterDragging: true, fixedAfterDragging: true,
@@ -93,24 +100,37 @@ exportToHtml("loadGalaxy", async (config: GalaxyConfig) => {
return 1 / Math.max(1, link?.value); return 1 / Math.max(1, link?.value);
}, },
linkIterations: 10,
manyBodyStrength: (node) => { manyBodyStrength: (node) => {
return node?.mass; return node?.mass;
}, },
stop: () => { // manyBodyDistanceMin: 500,
collideRadius: () => {
return 50;
},
ready: (e) => {
// Center on current user node at the start of the simulation
// Color all direct paths from that citizen to it's neighbor
const citizen = e.cy.nodes(`#${config.nodeId}`)[0];
citizen.addClass("focused");
citizen.connectedEdges().addClass("direct");
e.cy.center(citizen);
},
tick: () => {
// Center on current user node during simulation
const citizen = cy.nodes(`#${config.nodeId}`)[0];
cy.center(citizen);
},
stop: (e) => {
// Disable user grabbing of nodes // Disable user grabbing of nodes
// This has to be disabled after the simulation is done // This has to be disabled after the simulation is done
// Otherwise the simulation can't move nodes // Otherwise the simulation can't move nodes
cy.autolock(true); e.cy.autolock(true);
// Center on current user node
for (const node of cy.nodes()) {
if (node.id() === `${config.nodeId}`) {
node.addClass("focused");
cy.center(node);
break;
}
}
}, },
} as D3ForceLayoutOptions, } as D3ForceLayoutOptions,
}); });