graf: pri updatu to uz tolik neskace
This commit is contained in:
parent
2494eab6e7
commit
0336e59c05
2 changed files with 27 additions and 13 deletions
|
@ -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>
|
||||
|
|
|
@ -8,21 +8,37 @@ export type TaskId = {
|
|||
task: TaskDescriptor;
|
||||
} & SimulationNodeDatum;
|
||||
|
||||
function createNodes(tasks: TasksFile, old?: TaskId[]): TaskId[] {
|
||||
return tasks.tasks.map((t) => {
|
||||
return { id: t.id, task: t };
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
export function createNodesAndEdges(tasks: TasksFile, oldNodes?, oldEdges?): [TaskId[], SimulationLinkDatum<TaskId>[]] {
|
||||
function createNodes(tasks: TasksFile, old?: TaskId[]): TaskId[] {
|
||||
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?: 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) {
|
||||
|
|
Reference in a new issue