|
@ -8,21 +8,37 @@ export type TaskId = { |
|
|
task: TaskDescriptor; |
|
|
task: TaskDescriptor; |
|
|
} & SimulationNodeDatum; |
|
|
} & 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[] { |
|
|
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 }; |
|
|
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); |
|
|
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) { |
|
|