|
1 | 1 | import { app } from "../app";
|
| 2 | +import * as joint from "jointjs"; |
2 | 3 |
|
3 | 4 | /**
|
4 | 5 | * order graph elements from source to target
|
@@ -50,32 +51,25 @@ export const orderGraph = graph => {
|
50 | 51 | export const getOrderedElements = () => {
|
51 | 52 | const order = [];
|
52 | 53 | const { graph } = app;
|
53 |
| - const sources = graph.getSources(); |
54 | 54 |
|
55 | 55 | const addedBoxId = [];
|
56 | 56 |
|
57 |
| - for (const source of sources) { |
58 |
| - order.push(source); |
59 |
| - addedBoxId.push(source.attributes.boxId); |
60 |
| - |
61 |
| - let children = graph.getNeighbors(source, { outbound: true }); |
62 |
| - do { |
63 |
| - let allChildren = []; |
64 |
| - const noDuplicates = children.filter( |
65 |
| - ({ attributes: { boxId } }) => !addedBoxId.includes(boxId) |
66 |
| - ); |
67 |
| - //.sort((a,b) => graph.getNeighbors(b).length - graph.getNeighbors(a).length) |
| 57 | + let subgraph = new joint.dia.Graph(); |
| 58 | + subgraph.addCells(graph.getCells()); |
68 | 59 |
|
69 |
| - for (const child of noDuplicates) { |
70 |
| - order.push(child); |
71 |
| - addedBoxId.push(child.attributes.boxId); |
72 |
| - allChildren = allChildren.concat( |
73 |
| - graph.getNeighbors(child, { outbound: true }) |
74 |
| - ); |
75 |
| - } |
| 60 | + do { |
| 61 | + const sources = subgraph.getSources(); |
| 62 | + for (const source of sources) { |
| 63 | + order.push(source); |
| 64 | + addedBoxId.push(source.attributes.boxId); |
| 65 | + } |
| 66 | + let remainingEls = subgraph |
| 67 | + .getElements() |
| 68 | + .filter(el => !sources.includes(el)); |
| 69 | + let remainingCells = subgraph.getSubgraph(remainingEls); |
| 70 | + subgraph = new joint.dia.Graph(); |
| 71 | + subgraph.addCells(remainingCells); |
| 72 | + } while (subgraph.getElements().length); |
76 | 73 |
|
77 |
| - children = allChildren; |
78 |
| - } while (children.length); |
79 |
| - } |
80 | 74 | return order;
|
81 | 75 | };
|
0 commit comments