Skip to content

Commit 7427fde

Browse files
committed
Close #206 | replace layoutRandom() with silent layoutRandomInMemory() in Eades
layoutRandom() emits setNodePos per vertex and owns a progress dialog — inappropriate for internal initialisation inside another layout algorithm. Add layoutRandomInMemory() which sets vertex positions silently (no signals, no progress dialog) for use as an initial condition before the Eades iteration loop begins.
1 parent 8ea536c commit 7427fde

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/graph.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,8 @@ public slots:
10791079

10801080
void layoutRandom();
10811081

1082+
void layoutRandomInMemory();
1083+
10821084
void layoutRadialRandom(const bool &guides = true);
10831085

10841086
void layoutCircular(const double &x0,

src/graph/layouts/graph_layouts_basic.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,30 @@ void Graph::layoutRadialRandom(const bool &guides)
121121
setModStatus(ModStatus::VertexPositions);
122122
}
123123

124+
125+
/**
126+
* @brief Repositions all vertices at random coordinates without emitting any signals.
127+
*
128+
* Used internally by force-directed layout algorithms (Eades, FR) to set up
129+
* initial particle positions before the iteration loop begins. Since the iteration
130+
* loop will immediately overwrite these positions and emits a bulk setNodePos pass
131+
* at the end, there is no need to signal the graphics scene here.
132+
*
133+
* For the standalone random layout action (with progress dialog and scene update),
134+
* use layoutRandom() instead.
135+
*/
136+
void Graph::layoutRandomInMemory()
137+
{
138+
qDebug() << "Graph::layoutRandomInMemory()";
139+
VList::const_iterator it;
140+
for (it = m_graph.cbegin(); it != m_graph.cend(); ++it)
141+
{
142+
(*it)->setX(canvasRandomX());
143+
(*it)->setY(canvasRandomY());
144+
}
145+
}
146+
147+
124148
/**
125149
* @brief Repositions all nodes on the periphery of a circle with given radius
126150
* @param x0

src/graph/layouts/graph_layouts_force.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ void Graph::layoutForceDirectedSpringEmbedder(const int maxIterations)
5757
<< " naturalLength " << naturalLength;
5858

5959
/* apply an initial random layout */
60-
// layoutCircular(canvasWidth/2.0, canvasHeight/2.0, naturalLength/2.0 ,false);
61-
layoutRandom();
60+
layoutRandomInMemory();
6261

6362
QString pMsg = tr("Embedding Eades Spring-Gravitational model. \n"
6463
"Please wait ....");

0 commit comments

Comments
 (0)