|
| 1 | +import {prepareBlocks, prepareConnections} from './utils'; |
| 2 | + |
1 | 3 | class TreeLayoutEngine { |
2 | 4 | constructor(blocks, connections, options = {}) { |
3 | 5 | this.blocks = new Map(blocks.map((block) => [block.id, {...block}])); |
@@ -221,12 +223,12 @@ class TreeLayoutEngine { |
221 | 223 | } |
222 | 224 |
|
223 | 225 | // Функция для использования алгоритма |
224 | | -export function calculateTreeLayout(blocks, connections, options = {}) { |
| 226 | +function calculateTreeLayout(blocks, connections, options = {}) { |
225 | 227 | const engine = new TreeLayoutEngine(blocks, connections, options); |
226 | 228 | return engine.layout(); |
227 | 229 | } |
228 | 230 |
|
229 | | -export function calculateConnectionPaths(layoutResult, connections) { |
| 231 | +function calculateTreeEdges(layoutResult, connections) { |
230 | 232 | // Создаем карту позиций для удобства поиска |
231 | 233 | const positionMap = new Map(layoutResult.map((item) => [item.id, item])); |
232 | 234 |
|
@@ -314,3 +316,16 @@ export function calculateConnectionPaths(layoutResult, connections) { |
314 | 316 |
|
315 | 317 | return connectionPaths; |
316 | 318 | } |
| 319 | + |
| 320 | +onmessage = function (e) { |
| 321 | + const {nodes, links} = e.data; |
| 322 | + const blocks = prepareBlocks(nodes); |
| 323 | + const connections = prepareConnections(links); |
| 324 | + const layout = calculateTreeLayout(blocks, connections); |
| 325 | + const edges = calculateTreeEdges(layout, connections); |
| 326 | + |
| 327 | + postMessage({ |
| 328 | + layout, |
| 329 | + edges, |
| 330 | + }); |
| 331 | +}; |
0 commit comments