Finding all connected elements between 2 elements #1750
-
I have some elements distributed across a paper. Some of them aren't embedded, some of them are. Some of the elements might be even deep-embedded (embedded inside elements that are embedded inside other elements). Is there a way I can find all the elements that are connected between 2 elements? (both including and excluding nested embedded elements) I made a small demo in order to make it easier to understand: https://codesandbox.io/s/jointjs-subgraph-u03xm8 Let's say that I want to get all elements between the 2 violet elements. Option A (all elements, searching deeply embedded elements) would return the cyan, the blue, and the white elements. Note that both options will exclude the red element, because it's not connected (either directly or indirectly) to the second violet element. If the operation was repeated for the 2 green elements: Option A (all elements, including deeply embedded elements) would return all elements, except the red one. I thought that maybe |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi, I would use Dijkstra's shortest path algorithm to receive the Option A (docs, demo). And Option B could be derived from A as discussed here (the descendants of the local hierarchical roots could be filtered out). const optionBResult = optionAResult.filter((e1, _, elements) => {
const isEmbeddedInElements = [el, ...elements].find(e2 => e1 !== e2 && e1.isEmbeddedIn(e2));
return !isEmbeddedInElements;
}); |
Beta Was this translation helpful? Give feedback.
Hi, I would use Dijkstra's shortest path algorithm to receive the Option A (docs, demo). And Option B could be derived from A as discussed here (the descendants of the local hierarchical roots could be filtered out).