@@ -2178,21 +2178,94 @@ function viewportDrawerLayoutVertical() {
2178
2178
console . log ( "nodevGapValue" , nodevGapValue ) ;
2179
2179
console . log ( "groupvGapValue" , groupvGapValue ) ;
2180
2180
2181
- cy . layout (
2182
- {
2183
- fit : true ,
2184
- name : "cola" ,
2185
- animate : true ,
2186
- randomize : false ,
2187
- maxSimulationTime : 400 ,
2188
- edgeLength : function ( e ) {
2189
- return edgeLengthValue / e . data ( "weight" ) ;
2190
- } ,
2191
- nodeGap : function ( e ) {
2192
- return nodeGapValue / e . data ( "weight" ) ;
2193
- } ,
2194
- } )
2195
- . run ( ) ;
2181
+ const xOffset = parseFloat ( nodevGapValue ) ;
2182
+ const yOffset = parseFloat ( groupvGapValue ) ;
2183
+
2184
+ console . log ( "yOffset" , yOffset ) ;
2185
+ console . log ( "xOffset" , xOffset ) ;
2186
+
2187
+ const delay = 100 ;
2188
+
2189
+ setTimeout ( ( ) => {
2190
+ cy . nodes ( ) . forEach ( function ( node ) {
2191
+ if ( node . isParent ( ) ) {
2192
+ // For each parent node
2193
+ // For each parent node
2194
+ const children = node . children ( ) ;
2195
+ const numRows = 1 ;
2196
+
2197
+ const cellWidth = node . width ( ) / children . length ;
2198
+ // const xOffset = 5
2199
+ // const xOffset = 5
2200
+
2201
+ children . forEach ( function ( child , index ) {
2202
+ // Position children in rows
2203
+ // Position children in rows
2204
+ const xPos = index * ( cellWidth + xOffset ) ;
2205
+ const yPos = 0 ;
2206
+
2207
+ // Set the position of each child node
2208
+ // Set the position of each child node
2209
+ child . position ( {
2210
+ x : xPos ,
2211
+ y : yPos
2212
+ } ) ;
2213
+ } ) ;
2214
+ }
2215
+ } ) ;
2216
+
2217
+ var parentCounts = { } ;
2218
+ var maxWidth = 0 ;
2219
+ var centerX = 0 ;
2220
+ var centerY = cy . height ( ) / 2 ;
2221
+
2222
+ // Count children of each parent node
2223
+ // Count children of each parent node
2224
+ cy . nodes ( ) . forEach ( function ( node ) {
2225
+ if ( node . isParent ( ) ) {
2226
+ const childrenCount = node . children ( ) . length ;
2227
+ parentCounts [ node . id ( ) ] = childrenCount ;
2228
+ }
2229
+ } ) ;
2230
+
2231
+ cy . nodes ( ) . forEach ( function ( node ) {
2232
+ if ( node . isParent ( ) ) {
2233
+ const width = node . width ( ) ;
2234
+ if ( width > maxWidth ) {
2235
+ maxWidth = width ;
2236
+ console . log ( "ParentMaxWidth: " , maxWidth ) ;
2237
+ }
2238
+ }
2239
+ } ) ;
2240
+
2241
+ const divisionFactor = maxWidth / 2 ;
2242
+ console . log ( "divisionFactor: " , divisionFactor ) ;
2243
+
2244
+ // Sort parent nodes by child count in ascending order
2245
+ // Sort parent nodes by child count in ascending order
2246
+ const sortedParents = Object . keys ( parentCounts ) . sort (
2247
+ ( a , b ) => parentCounts [ a ] - parentCounts [ b ] ,
2248
+ ) ;
2249
+
2250
+ let yPos = 0 ;
2251
+ // const yOffset = 50;
2252
+ // const yOffset = 50;
2253
+
2254
+ // Position parent nodes vertically and center them horizontally
2255
+ // Position parent nodes vertically and center them horizontally
2256
+ sortedParents . forEach ( function ( parentId ) {
2257
+ const parent = cy . getElementById ( parentId ) ;
2258
+ const xPos = centerX - parent . width ( ) / divisionFactor ;
2259
+ // to the left compared to the center of the widest parent node.
2260
+ // to the left compared to the center of the widest parent node.
2261
+ parent . position ( {
2262
+ x : xPos ,
2263
+ y : yPos
2264
+ } ) ;
2265
+ yPos += yOffset ;
2266
+ } ) ;
2267
+ cy . fit ( ) ;
2268
+ } , delay ) ;
2196
2269
}
2197
2270
2198
2271
0 commit comments