Browse Source

graf: pri updatu to uz tolik neskace

mj-deploy
Vašek Šraier 4 years ago
parent
commit
0336e59c05
  1. 4
      frontend/src/Graph.svelte
  2. 30
      frontend/src/graph-types.ts

4
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 @@
}
</style>
{@debug tasks}
<div bind:this={container} bind:clientHeight bind:clientWidth>
<svg bind:this={svgElement}>
<g>

30
frontend/src/graph-types.ts

@ -8,21 +8,37 @@ export type TaskId = {
task: TaskDescriptor;
} & SimulationNodeDatum;
function toMapById(nodes: TaskId[]): Map<string, TaskId> {
let nodeMap = new Map<string, TaskId>();
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<string, TaskId>() : 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<TaskId>[]] {
export function createNodesAndEdges(tasks: TasksFile, oldNodes?: TaskId[], oldEdges?: SimulationLinkDatum<TaskId>[]): [TaskId[], SimulationLinkDatum<TaskId>[]] {
let nodes = createNodes(tasks, oldNodes);
// create mapping from ID to node
let nodeMap = new Map<string, TaskId>();
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<TaskId>[] = [];
for (const task of tasks.tasks) {