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
|
// when we update nodes and edges
|
||||||
let [nodes, edges] = createNodesAndEdges(tasks);
|
let [nodes, edges] = createNodesAndEdges(tasks);
|
||||||
function hack() {
|
function hack() {
|
||||||
[nodes, edges] = createNodesAndEdges(tasks);
|
[nodes, edges] = createNodesAndEdges(tasks, nodes, edges);
|
||||||
runSimulation();
|
runSimulation();
|
||||||
}
|
}
|
||||||
$: {
|
$: {
|
||||||
|
@ -103,8 +103,6 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
{@debug tasks}
|
|
||||||
|
|
||||||
<div bind:this={container} bind:clientHeight bind:clientWidth>
|
<div bind:this={container} bind:clientHeight bind:clientWidth>
|
||||||
<svg bind:this={svgElement}>
|
<svg bind:this={svgElement}>
|
||||||
<g>
|
<g>
|
||||||
|
|
|
@ -8,21 +8,37 @@ export type TaskId = {
|
||||||
task: TaskDescriptor;
|
task: TaskDescriptor;
|
||||||
} & SimulationNodeDatum;
|
} & SimulationNodeDatum;
|
||||||
|
|
||||||
function createNodes(tasks: TasksFile, old?: TaskId[]): TaskId[] {
|
function toMapById(nodes: TaskId[]): Map<string, TaskId> {
|
||||||
return tasks.tasks.map((t) => {
|
let nodeMap = new Map<string, TaskId>();
|
||||||
return { id: t.id, task: t };
|
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);
|
let nodes = createNodes(tasks, oldNodes);
|
||||||
|
|
||||||
// create mapping from ID to node
|
// create mapping from ID to node
|
||||||
let nodeMap = new Map<string, TaskId>();
|
let nodeMap = toMapById(nodes);
|
||||||
for (let task of nodes) {
|
|
||||||
if (task.id in nodeMap) throw 'duplicate IDs';
|
|
||||||
nodeMap.set(task.id, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
let links: SimulationLinkDatum<TaskId>[] = [];
|
let links: SimulationLinkDatum<TaskId>[] = [];
|
||||||
for (const task of tasks.tasks) {
|
for (const task of tasks.tasks) {
|
||||||
|
|
Reference in a new issue