@@ -6,6 +6,7 @@ import { Coordinates, MouseCoords } from "sigma/types";
66
77import {
88 useGraphDatasetActions ,
9+ useLayoutState ,
910 useSelection ,
1011 useSelectionActions ,
1112 useSigmaActions ,
@@ -26,6 +27,7 @@ export const EventsController: FC = () => {
2627 const { setNodePositions } = useGraphDatasetActions ( ) ;
2728 const { select, toggle, emptySelection } = useSelectionActions ( ) ;
2829 const { setHoveredNode, resetHoveredNode, setHoveredEdge, resetHoveredEdge } = useSigmaActions ( ) ;
30+ const { type : layoutStatus } = useLayoutState ( ) ;
2931
3032 const dragStateRef = useRef <
3133 | { type : "idle" }
@@ -94,7 +96,7 @@ export const EventsController: FC = () => {
9496
9597 const initialNodesPosition : LayoutMapping = { } ;
9698 nodes . forEach ( ( node ) => {
97- // I think the fixed attribute is a failed tryout to solve the drag during layout issue https://github.com/gephi/gephi-lite/issues/138
99+ // Fixing the node position, it's needed while a layout is running
98100 graph . setNodeAttribute ( node , "fixed" , true ) ;
99101 const { x, y } = graph . getNodeAttributes ( node ) ;
100102 initialNodesPosition [ node ] = { x, y } ;
@@ -147,16 +149,19 @@ export const EventsController: FC = () => {
147149 if ( dragState . type === "downing" || dragState . type === "dragging" ) {
148150 const graph = sigma . getGraph ( ) ;
149151 if ( dragState . type === "dragging" ) {
150- // Save new positions in graph dataset:
151- const positions = mapValues ( dragState . initialNodesPosition , ( _initialPosition , id ) =>
152- pick ( graph . getNodeAttributes ( id ) , [ "x" , "y" ] ) ,
153- ) ;
154- setNodePositions ( positions ) ;
152+ // Save new positions in graph dataset if layout is not running
153+ // Positions will be saved when the algo will be stopped and saving positions here
154+ // will retrigger the layout with the initial positions (#138)
155+ if ( layoutStatus !== "running" ) {
156+ const positions = mapValues ( dragState . initialNodesPosition , ( _initialPosition , id ) =>
157+ pick ( graph . getNodeAttributes ( id ) , [ "x" , "y" ] ) ,
158+ ) ;
159+ setNodePositions ( positions ) ;
160+ }
155161
156162 resetHoveredNode ( ) ;
157163 resetHoveredEdge ( ) ;
158164 }
159- // I think the fixed attribute is a failed tryout to solve the drag during layout issue https://github.com/gephi/gephi-lite/issues/138
160165 graph . forEachNode ( ( node ) => graph . setNodeAttribute ( node , "fixed" , false ) ) ;
161166 dragStateRef . current = { type : "idle" } ;
162167 }
@@ -179,6 +184,7 @@ export const EventsController: FC = () => {
179184 toggle ,
180185 setNodePositions ,
181186 globalEmitter ,
187+ layoutStatus ,
182188 ] ) ;
183189
184190 // DOM events not handled by sigma:
0 commit comments