diff --git a/frontend/src/Graph.svelte b/frontend/src/Graph.svelte index 6307128..b8b2da9 100644 --- a/frontend/src/Graph.svelte +++ b/frontend/src/Graph.svelte @@ -20,7 +20,7 @@ // when we update nodes and edges let [nodes, edges] = createNodesAndEdges(tasks); function hack() { - [nodes, edges] = createNodesAndEdges(tasks); + [nodes, edges] = createNodesAndEdges(tasks, nodes, edges); runSimulation(); } $: { @@ -103,8 +103,6 @@ } -{@debug tasks} -
diff --git a/frontend/src/graph-types.ts b/frontend/src/graph-types.ts index 0391c8b..08f2d82 100644 --- a/frontend/src/graph-types.ts +++ b/frontend/src/graph-types.ts @@ -8,21 +8,37 @@ export type TaskId = { task: TaskDescriptor; } & SimulationNodeDatum; +function toMapById(nodes: TaskId[]): Map { + let nodeMap = new Map(); + for (let task of nodes) { + if (task.id in nodeMap) + throw 'duplicate IDs'; + nodeMap.set(task.id, task); + } + return nodeMap; +} + function createNodes(tasks: TasksFile, old?: TaskId[]): TaskId[] { - return tasks.tasks.map((t) => { + let m = (old == undefined) ? new Map() : toMapById(old); + + let res = tasks.tasks.map((t) => { return { id: t.id, task: t }; }); + + for (let t of res) { + if (m.has(t.id)) { + Object.assign(t, m.get(t.id)) + } + } + + return res; } -export function createNodesAndEdges(tasks: TasksFile, oldNodes?, oldEdges?): [TaskId[], SimulationLinkDatum[]] { +export function createNodesAndEdges(tasks: TasksFile, oldNodes?: TaskId[], oldEdges?: SimulationLinkDatum[]): [TaskId[], SimulationLinkDatum[]] { let nodes = createNodes(tasks, oldNodes); // create mapping from ID to node - let nodeMap = new Map(); - for (let task of nodes) { - if (task.id in nodeMap) throw 'duplicate IDs'; - nodeMap.set(task.id, task); - } + let nodeMap = toMapById(nodes); let links: SimulationLinkDatum[] = []; for (const task of tasks.tasks) {