@@ -105,6 +105,26 @@ export const DirectedGraph = {
105
105
}
106
106
} ,
107
107
108
+ // Validate that the graph does not have an arrangement of cells that Dagre considers invalid:
109
+ // - child connected to a container
110
+ // - container connected to a child
111
+ // - container connected to a container
112
+ // Throw an understandable error if one of the above situations is the case.
113
+ validateGraph : function ( graph ) {
114
+
115
+ graph . getLinks ( ) . forEach ( ( link ) => {
116
+ const source = link . getSourceElement ( ) ;
117
+ const target = link . getTargetElement ( ) ;
118
+ // is container = is element && has at least one embedded element
119
+ const isSourceContainer = source && source . getEmbeddedCells ( ) . some ( ( cell ) => cell . isElement ( ) ) ;
120
+ const isTargetContainer = target && target . getEmbeddedCells ( ) . some ( ( cell ) => cell . isElement ( ) ) ;
121
+ if ( ( isSourceContainer && target ) || ( source && isTargetContainer ) ) {
122
+ // see https://github.com/clientIO/joint/issues/455
123
+ throw new Error ( 'DirectedGraph: It is not possible to connect a child to a container.' ) ;
124
+ }
125
+ } ) ;
126
+ } ,
127
+
108
128
layout : function ( graphOrCells , opt ) {
109
129
110
130
var graph ;
@@ -129,23 +149,8 @@ export const DirectedGraph = {
129
149
disableOptimalOrderHeuristic : false
130
150
} ) ;
131
151
132
- // Check that we are not trying to connect a child to a container:
133
- // - child to a container
134
- // - container to a child
135
- // - container to a container
136
- if ( opt . validateGraph ) {
137
- graph . getLinks ( ) . forEach ( ( link ) => {
138
- const source = link . getSourceElement ( ) ;
139
- const target = link . getTargetElement ( ) ;
140
- // is container = is element && has at least one embedded element
141
- const isSourceContainer = source && source . getEmbeddedCells ( ) . some ( ( cell ) => cell . isElement ( ) ) ;
142
- const isTargetContainer = target && target . getEmbeddedCells ( ) . some ( ( cell ) => cell . isElement ( ) ) ;
143
- if ( ( isSourceContainer && target ) || ( source && isTargetContainer ) ) {
144
- // see https://github.com/clientIO/joint/issues/455
145
- throw new Error ( 'DirectedGraph: It is not possible to connect a child to a container.' ) ;
146
- }
147
- } ) ;
148
- }
152
+ // Check that we are not trying to connect a child to a container.
153
+ if ( opt . validateGraph ) this . validateGraph ( graph ) ;
149
154
150
155
// Create a graphlib.Graph that represents the joint.dia.Graph
151
156
var glGraph = DirectedGraph . toGraphLib ( graph , {
0 commit comments