feat: add ctrl+l to select linked nodes

This commit is contained in:
max_richter 2024-03-21 01:38:12 +01:00
parent 767c798ae6
commit 8dfd05fc63
3 changed files with 29 additions and 7 deletions

View File

@ -444,8 +444,16 @@
document?.activeElement?.id === "graph";
if (event.key === "l") {
const activeNode = graph.getNode($activeNodeId);
console.log(activeNode);
if (event.ctrlKey) {
const activeNode = graph.getNode($activeNodeId);
if (activeNode) {
const nodes = graph.getLinkedNodes(activeNode);
$selectedNodes = new Set(nodes.map((n) => n.id));
}
} else {
const activeNode = graph.getNode($activeNodeId);
console.log(activeNode);
}
}
if (event.key === "Escape") {

View File

@ -40,7 +40,7 @@ void main(){
vec2 size = vec2(uWidth, uHeight);
vec2 uv = (vUv - 0.5) * 2.0;
float u_border_radius = 1.5;
float u_border_radius = 0.4;
vec4 distance = roundedBoxSDF(uv * size, size, u_border_radius*2.0, 0.0);
if (distance.w > 0.0 ) {

View File

@ -62,6 +62,21 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> {
return this.nodeRegistry.getAllNodes();
}
getLinkedNodes(node: Node) {
const nodes = new Set<Node>();
const stack = [node];
while (stack.length) {
const n = stack.pop();
if (!n) continue;
nodes.add(n);
const children = this.getChildrenOfNode(n);
const parents = this.getParentsOfNode(n);
const newNodes = [...children, ...parents].filter(n => !nodes.has(n));
stack.push(...newNodes);
}
return [...nodes.values()];
}
private _init(graph: Graph) {
const nodes = new Map(graph.nodes.map(node => {
@ -92,6 +107,8 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> {
this.edges.set(edges);
this.nodes.set(nodes);
this.execute();
}
async load(graph: Graph) {
@ -126,10 +143,7 @@ export class GraphManager extends EventEmitter<{ "save": Graph }> {
this.loaded = true;
const f = performance.now();
requestAnimationFrame(() => {
console.log(`Loading took ${f - a}ms; a-b: ${b - a}ms; b-c: ${c - b}ms; c-d: ${d - c}ms; d-e: ${e - d}ms; e-f: ${f - e}ms`);
this.execute();
});
console.log(`Loading took ${f - a}ms; a-b: ${b - a}ms; b-c: ${c - b}ms; c-d: ${d - c}ms; d-e: ${e - d}ms; e-f: ${f - e}ms`);
}