feat: add dag into frontend (work in progress)

This commit is contained in:
Lin, Hung-Shin committed 2023-11-15 14:58:00 +08:00
1 parent 14d6ab961b
commit ca8215486c
3 files changed
+56 -121

No files matched your search

+15
View File
@@ -2,6 +2,7 @@ export default class DAG {
constructor(nodes) {
this.nodes = new Map(nodes.map((node) => [node._id, node]))
this.edges = new Set()
this.layers = []
this.nodes.forEach((_, id) => {
this.setLayer(id)
this.addEdges(id)
@@ -12,6 +13,14 @@ export default class DAG {
return this.nodes.get(id)
}
getNodes() {
return Array.from(this.nodes.values())
}
getEdges() {
return Array.from(this.edges.values())
}
setLayer(id) {
console.log(`setLayer(${id})`)
const node = this.nodes.get(id)
@@ -23,6 +32,12 @@ export default class DAG {
}
const previousLayer = node.requirements.map((rId) => this.setLayer(rId))
node.layer = Math.max(...previousLayer, 0) + 1
if (this.layers.length < node.layer) {
this.layer.push(1)
} else {
this.layers[node.layer - 1] += 1
}
node.count = this.layers[node.layer - 1]
return node.layer
}
+1
View File
@@ -1,2 +1,3 @@
export { isValidEmail, isValidUsername } from './auth.js'
export { buildFileCheckCmd } from './commands.js'
export { default as DAG } from './dag.js'