@@ -10,7 +10,7 @@ import { dataGraphToFullGraph } from "../graph/utils";
1010import { sessionAtom } from "../session" ;
1111import { resetCamera } from "../sigma" ;
1212import { LAYOUTS } from "./collection" ;
13- import { LayoutMapping , LayoutQuality , LayoutState } from "./types" ;
13+ import { type Layout , LayoutMapping , LayoutQuality , LayoutState } from "./types" ;
1414
1515function getEmptyLayoutState ( ) : LayoutState {
1616 return { quality : { enabled : false , showGrid : true } , type : "idle" } ;
@@ -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,6 +91,18 @@ export const startLayout = asyncAction(async (id: string, params: unknown, isFor
9191
9292 // Async layout
9393 if ( layout . type === "worker" ) {
94+ const graph = sigmaGraphAtom . get ( ) ;
95+
96+ // If layout parameter has a `getNodeFixedAttribut`, then we have to set the 'fixed'
97+ // attribut in sigma's graph
98+ if ( "getNodeFixedAttribut" in params && params . getNodeFixedAttribut ) {
99+ const fixedAttribut = `${ params . getNodeFixedAttribut } ` ;
100+ graph . updateEachNodeAttributes ( ( id , attrs ) => ( {
101+ ...attrs ,
102+ fixed : dataset . nodeData [ id ] [ fixedAttribut ] === true ,
103+ } ) ) ;
104+ }
105+
94106 const worker = new layout . supervisor ( sigmaGraphAtom . get ( ) , { settings : params } ) ;
95107 worker . start ( ) ;
96108 layoutStateAtom . set ( ( prev ) => ( { ...prev , type : "running" , layoutId : id , supervisor : worker } ) ) ;
0 commit comments