Skip to content

Commit 1f48b47

Browse files
committed
feat: auto-align all organic layouts except DrL
and bounded FR and KK
1 parent 81e789d commit 1f48b47

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

src/_igraph/graphobject.c

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8188,14 +8188,15 @@ PyObject *igraphmodule_Graph_layout_kamada_kawai(igraphmodule_GraphObject *
81888188
return NULL;
81898189
}
81908190

8191-
if (dim == 2)
8191+
if (dim == 2) {
81928192
ret = igraph_layout_kamada_kawai
81938193
(&self->g, &m, use_seed, maxiter, epsilon, kkconst,
81948194
weights, /*bounds*/ minx, maxx, miny, maxy);
8195-
else
8195+
} else {
81968196
ret = igraph_layout_kamada_kawai_3d
81978197
(&self->g, &m, use_seed, maxiter, epsilon, kkconst,
81988198
weights, /*bounds*/ minx, maxx, miny, maxy, minz, maxz);
8199+
}
81998200

82008201
DESTROY_VECTORS;
82018202

@@ -8207,6 +8208,19 @@ PyObject *igraphmodule_Graph_layout_kamada_kawai(igraphmodule_GraphObject *
82078208
return NULL;
82088209
}
82098210

8211+
/* Align layout, but only if no bounding box was specified. */
8212+
if (minx == NULL && maxx == NULL &&
8213+
miny == NULL && maxy == NULL &&
8214+
minz == NULL && maxz == NULL &&
8215+
igraph_vcount(&self->g) <= 1000) {
8216+
ret = igraph_layout_align(&self->g, &m);
8217+
if (ret) {
8218+
igraph_matrix_destroy(&m);
8219+
igraphmodule_handle_igraph_error();
8220+
return NULL;
8221+
}
8222+
}
8223+
82108224
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
82118225
igraph_matrix_destroy(&m);
82128226
return (PyObject *) result_o;
@@ -8298,6 +8312,16 @@ PyObject* igraphmodule_Graph_layout_davidson_harel(igraphmodule_GraphObject *sel
82988312
return NULL;
82998313
}
83008314

8315+
/* Align layout */
8316+
if (igraph_vcount(&self->g)) {
8317+
retval = igraph_layout_align(&self->g, &m);
8318+
if (retval) {
8319+
igraph_matrix_destroy(&m);
8320+
igraphmodule_handle_igraph_error();
8321+
return NULL;
8322+
}
8323+
}
8324+
83018325
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
83028326
igraph_matrix_destroy(&m);
83038327
return (PyObject *) result_o;
@@ -8520,6 +8544,19 @@ PyObject
85208544
return NULL;
85218545
}
85228546

8547+
/* Align layout, but only if no bounding box was specified. */
8548+
if (minx == NULL && maxx == NULL &&
8549+
miny == NULL && maxy == NULL &&
8550+
minz == NULL && maxz == NULL &&
8551+
igraph_vcount(&self->g) <= 1000) {
8552+
ret = igraph_layout_align(&self->g, &m);
8553+
if (ret) {
8554+
igraph_matrix_destroy(&m);
8555+
igraphmodule_handle_igraph_error();
8556+
return NULL;
8557+
}
8558+
}
8559+
85238560
#undef DESTROY_VECTORS
85248561

85258562
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
@@ -8574,6 +8611,15 @@ PyObject *igraphmodule_Graph_layout_graphopt(igraphmodule_GraphObject *self,
85748611
return NULL;
85758612
}
85768613

8614+
/* Align layout */
8615+
if (igraph_vcount(&self->g) <= 1000) {
8616+
if (igraph_layout_align(&self->g, &m)) {
8617+
igraph_matrix_destroy(&m);
8618+
igraphmodule_handle_igraph_error();
8619+
return NULL;
8620+
}
8621+
}
8622+
85778623
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
85788624
igraph_matrix_destroy(&m);
85798625
return (PyObject *) result_o;
@@ -8632,6 +8678,15 @@ PyObject *igraphmodule_Graph_layout_lgl(igraphmodule_GraphObject * self,
86328678
return NULL;
86338679
}
86348680

8681+
/* Align layout */
8682+
if (igraph_vcount(&self->g) <= 1000) {
8683+
if (igraph_layout_align(&self->g, &m)) {
8684+
igraph_matrix_destroy(&m);
8685+
igraphmodule_handle_igraph_error();
8686+
return NULL;
8687+
}
8688+
}
8689+
86358690
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
86368691
igraph_matrix_destroy(&m);
86378692
return (PyObject *) result_o;
@@ -8697,6 +8752,15 @@ PyObject *igraphmodule_Graph_layout_mds(igraphmodule_GraphObject * self,
86978752
igraph_matrix_destroy(dist); free(dist);
86988753
}
86998754

8755+
/* Align layout */
8756+
if (igraph_vcount(&self->g) <= 1000) {
8757+
if (igraph_layout_align(&self->g, &m)) {
8758+
igraph_matrix_destroy(&m);
8759+
igraphmodule_handle_igraph_error();
8760+
return NULL;
8761+
}
8762+
}
8763+
87008764
result_o = igraphmodule_matrix_t_to_PyList(&m, IGRAPHMODULE_TYPE_FLOAT);
87018765
igraph_matrix_destroy(&m);
87028766
return (PyObject *) result_o;

0 commit comments

Comments
 (0)