@painekillers/tree-builder-core 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/graph.js +32 -15
- package/package.json +1 -1
package/graph.js
CHANGED
|
@@ -90,7 +90,7 @@ True: Connects back to existing instance of a node when recursing
|
|
|
90
90
|
/*
|
|
91
91
|
Strategies
|
|
92
92
|
- [X] Current BFS (First) — Layer by shortest distance from root; first discovery determines placement.
|
|
93
|
-
- [X] Undirected BFS (Undirected) — Shortest distance to root; layering is
|
|
93
|
+
- [X] Undirected BFS (Undirected) — Shortest distance to root; layering is one directional.
|
|
94
94
|
- [X] Directed BFS, outward only (Outwards) — Follow prerequisite-to-dependent edges only.
|
|
95
95
|
- [X] Furthest-parent layering (Furthest) — Place each node one layer below its deepest prerequisite.
|
|
96
96
|
*/
|
|
@@ -116,13 +116,13 @@ export class LayoutGraph {
|
|
|
116
116
|
const visited = new Map()
|
|
117
117
|
const connections = new Set()
|
|
118
118
|
|
|
119
|
-
const addConnection = (ln, from) => {
|
|
119
|
+
const addConnection = (ln, from, lnPos) => {
|
|
120
120
|
const fromNode =
|
|
121
121
|
this.layers.get(from.layer)?.[from.ind]
|
|
122
122
|
|
|
123
123
|
if(!fromNode) return
|
|
124
124
|
|
|
125
|
-
const a = `${
|
|
125
|
+
const a = `${lnPos.layer}:${lnPos.ind}`
|
|
126
126
|
const b = `${from.layer}:${from.ind}`
|
|
127
127
|
|
|
128
128
|
const key = [a, b].sort().join("|")
|
|
@@ -166,7 +166,7 @@ export class LayoutGraph {
|
|
|
166
166
|
//holy crap i cannot think bruh
|
|
167
167
|
if(((recurse === false) || (recurse === null)) && pos.layer !== layer) {
|
|
168
168
|
if (
|
|
169
|
-
recurse
|
|
169
|
+
recurse === null ||
|
|
170
170
|
strategy == "Outwards" &&
|
|
171
171
|
from !== null &&
|
|
172
172
|
Math.abs(layer) < Math.abs(from.layer)
|
|
@@ -181,12 +181,13 @@ export class LayoutGraph {
|
|
|
181
181
|
)
|
|
182
182
|
) { continue }
|
|
183
183
|
|
|
184
|
+
//this part makes the fake node btw
|
|
184
185
|
const fn = new LayoutNode(node, layer, this.layers.get(pos.layer)[pos.ind])
|
|
185
186
|
this.layers.get(layer).push(fn)
|
|
186
187
|
|
|
187
|
-
addConnection(fn, from)
|
|
188
|
+
addConnection(fn, from, pos)
|
|
188
189
|
} else {
|
|
189
|
-
addConnection(ln, from)
|
|
190
|
+
addConnection(ln, from, pos)
|
|
190
191
|
|
|
191
192
|
}
|
|
192
193
|
}
|
|
@@ -200,14 +201,30 @@ export class LayoutGraph {
|
|
|
200
201
|
Math.abs(layer) < Math.abs(from.layer)
|
|
201
202
|
) { continue }
|
|
202
203
|
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
204
|
+
if (strategy == "Furthest") {
|
|
205
|
+
if (layer > 0 && !node.parents.every(val => visited.has(val.id))) {
|
|
206
|
+
for (const parent of node.parents) {
|
|
207
|
+
queue.push({
|
|
208
|
+
node: parent,
|
|
209
|
+
layer: layer - 1,
|
|
210
|
+
from: null
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
continue
|
|
215
|
+
} else
|
|
216
|
+
if (layer < 0 && !node.children.every(val => visited.has(val.id))) {
|
|
217
|
+
for (const child of node.children) {
|
|
218
|
+
queue.push({
|
|
219
|
+
node: child,
|
|
220
|
+
layer: layer + 1,
|
|
221
|
+
from: null
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
}
|
|
211
228
|
|
|
212
229
|
const ln = new LayoutNode(node, layer)
|
|
213
230
|
|
|
@@ -221,7 +238,7 @@ export class LayoutGraph {
|
|
|
221
238
|
visited.set(key, pos)
|
|
222
239
|
|
|
223
240
|
if(from) {
|
|
224
|
-
addConnection(ln, from)
|
|
241
|
+
addConnection(ln, from, pos)
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
for (const child of node.children) {
|