@@ -59,10 +59,11 @@ export const stopLayout = asyncAction(async (isForRestart = false) => {
5959 if ( ! isForRestart ) layoutStateAtom . set ( ( prev ) => ( { ...prev , type : "idle" } ) ) ;
6060} ) ;
6161
62- export const startLayout = asyncAction ( async ( id : string , params : unknown , isForRestart = false ) => {
62+ export const startLayout = asyncAction ( async ( id : string , params : Record < string , unknown > , isForRestart = false ) => {
6363 // Stop the previous algo (the "if needed" is done in the function itself)
6464 await stopLayout ( isForRestart ) ;
6565
66+ const dataset = graphDatasetAtom . get ( ) ;
6667 const { setNodePositions } = graphDatasetActions ;
6768
6869 // search the layout
@@ -74,7 +75,6 @@ export const startLayout = asyncAction(async (id: string, params: unknown, isFor
7475 layoutStateAtom . set ( ( prev ) => ( { ...prev , type : "running" , layoutId : id , supervisor : undefined } ) ) ;
7576
7677 // generate positions
77- const dataset = graphDatasetAtom . get ( ) ;
7878 const fullGraph = dataGraphToFullGraph ( dataset ) ;
7979 const positions = layout . run ( fullGraph , { settings : params } ) ;
8080
@@ -91,7 +91,28 @@ export const startLayout = asyncAction(async (id: string, params: unknown, isFor
9191
9292 // Async layout
9393 if ( layout . type === "worker" ) {
94- const worker = new layout . supervisor ( sigmaGraphAtom . get ( ) , { settings : params } ) ;
94+ const graph = sigmaGraphAtom . get ( ) ;
95+
96+ // Fixed node management
97+ // ---------------------
98+ // If layout parameter has a `getNodeFixedAttribut`, then we have to set the 'fixed' attribut in sigma's graph
99+ // On a layout restart, if parameter has been removed, we need to set to false
100+ // We also use the 'fixed' attribut for drag'n'drop
101+ graph . updateEachNodeAttributes ( ( id , attrs ) => {
102+ let fixed = attrs . dragging === true ;
103+ if ( "getNodeFixedAttribut" in params && params . getNodeFixedAttribut ) {
104+ const fixedAttribut = `${ params . getNodeFixedAttribut } ` ;
105+ if ( dataset . nodeData [ id ] [ fixedAttribut ] === true ) {
106+ fixed = true ;
107+ }
108+ }
109+ return {
110+ ...attrs ,
111+ fixed,
112+ } ;
113+ } ) ;
114+
115+ const worker = new layout . supervisor ( graph , { settings : params } ) ;
95116 worker . start ( ) ;
96117 layoutStateAtom . set ( ( prev ) => ( { ...prev , type : "running" , layoutId : id , supervisor : worker } ) ) ;
97118 }
0 commit comments