-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfgs.c
5235 lines (4546 loc) · 112 KB
/
sfgs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* simpified version not using splay() */
/*
* Copyright t lefering
* parts are (C) Universitaet Passau 1986-1991
* parts are Copyright (C) 1998-2021 Free Software Foundation, Inc.
* parts are Copyright (C) Felix von Leitner from dietlibc
*
* https://notabug.org/mooigraph/sfgraph
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* These are the four essential freedoms with GNU GPL software:
* 1: freedom to run the program, for any purpose
* 2: freedom to study how the program works, and change it to make it do what you wish
* 3: freedom to redistribute copies to help your Free Software friends
* 4: freedom to distribute copies of your modified versions to your Free Software friends
* , ,
* / \
* ((__-^^-,-^^-__))
* `-_---' `---_-'
* `--|o` 'o|--'
* \ ` /
* ): :(
* :o_o:
* "-"
*
* SPDX-License-Identifier: GPL-3.0+
* License-Filename: LICENSE
*/
/* Single File Graph layout for directed graphs.
* the api to use this file is in sfg.h
* the demo program how to use is sfgdemo.c
*/
#include <stdio.h>
#include <stdlib.h> /* for calloc() free() */
/* from <limits.h> for CHAR_BIT is 8 definition */
#define CHAR_BIT 8
/* min (x,y) spacing between nodes */
#define NXSPACING 5
#define NYSPACING 15
#include "sfg.h"
struct gml_graph;
struct gml_node;
struct gml_edge;
struct gml_nlist;
struct gml_elist;
struct gml_graph {
int layouted; /* set if layout is done */
int nodenum; /* highest node number in use */
int nnodes; /* number of nodes in the graph */
int edgenum; /* highest edge number in use */
int nedges; /* number of edges in the graph */
int maxlevel; /* maximum relative level */
int nedgelabels; /* number of edgelabels */
int do_edgelabels; /* if set add edgelabels in the graph */
int nsinglenodes; /* number of single nodes */
int nhedges; /* number of hor edges */
int startnodeslevel; /* level where graph drawing starts */
int nstartnodes; /* number of start node numbers */
int *startnodes; /* array with start node numbers */
int xspacing; /* min x spacing between nodes */
int yspacing; /* min y spacing between nodes */
struct gml_nlist *nodelist; /* list of nodes */
struct gml_nlist *nodelistend;
struct gml_nlist *singlenodelist; /* list of single nodes */
struct gml_nlist *singlenodelistend;
struct gml_elist *edgelist; /* list of edges */
struct gml_elist *edgelistend;
int *nnodes_of_level; /* number of nodes for each level */
int widestnnodes; /* widest number of nodes on one level */
int widestlevel; /* widest level */
int sugi_icrossings; /* initial crossings */
int sugi_fcrossings; /* final crossings */
int sugi_changes; /* sugiyama changes made */
int *numce; /* number of crossings at every level */
int *nume; /* number of edges */
int maxx; /* max x pos of drawing */
int maxy; /* max y pos of drawing */
int nodemin; /* min. node number in use */
int nodemax; /* max. node number in use */
int edgemin; /* min. edge number in use */
int edgemax; /* max. edge number in use */
};
struct gml_node {
int nr; /* uniq node number */
int tx; /* text xsize */
int ty; /* text ysize */
int bbx; /* text xsize */
int bby; /* text ysize */
int dummy; /* set to 1 if dummy node */
int elabel; /* set if node is a edge label */
int enumber; /* orig. edge number of the edge label */
int nselfedges; /* number of self edges at this node */
int done; /* dfs black/white */
int grey; /* dfs grey */
int indegree; /* incoming edges to node */
int outdegree; /* outgoing edges from node */
int hashedge; /* set if node has hor. edge */
void *data; /* user data */
int relx; /* relative xpos */
int rely; /* relative ypos */
int absx; /* absolute xpos */
int absy; /* absolute ypos */
int lx0; /* absolute xpos */
int ly0; /* absolute xpos */
int lx1; /* absolute ypos */
int ly1; /* absolute ypos */
int finx; /* absolute xpos */
int finy; /* absolute ypos */
struct gml_elist *outgoing_e; /* source list, outgoing edges */
struct gml_elist *outgoing_etail; /* source list, outgoing edges */
struct gml_elist *incoming_e; /* target list, incoming edges */
struct gml_elist *incoming_etail; /* target list, incoming edges */
int startnode; /* node belongs to part of graph with this startnode */
struct gml_node *el_fnode; /* in edge-label the from-node */
struct gml_node *el_tnode; /* in edge-label the to-node */
};
struct gml_edge {
int nr; /* uniq edge number */
struct gml_node *from_node; /* from node */
struct gml_node *to_node; /* to node */
int tx; /* text xsize */
int ty; /* text ysize */
int elabel; /* set if there is a edge label */
int reversed; /* set if edge is reversed */
int hedge; /* set if hor. edge */
};
struct gml_nlist {
struct gml_node *node;
struct gml_nlist *next;
};
struct gml_elist {
struct gml_edge *edge;
struct gml_elist *next;
};
/* local vars */
static struct gml_graph *maingraph = NULL;
static struct gml_node *uniqnode(struct gml_graph *g, int nr);
static void uniqnode_add(struct gml_graph *g, struct gml_node *node);
static void clear_nodelist(struct gml_graph *g);
static void clear_edgelist(struct gml_graph *g);
static void prep(struct gml_graph *g);
static void reorg(struct gml_graph *g);
static void uncycle(struct gml_graph *g);
static void make_stlist(struct gml_graph *g);
static void clear_stlist(struct gml_node *node);
static void clear_stlist_all(struct gml_graph *g);
static void ylevels(struct gml_graph *g);
static void set_level2(struct gml_graph *g, struct gml_node *n, int i, int startnode);
static void shorteredges(struct gml_graph *g);
static void edgesdownwards(struct gml_graph *g);
static void edgelen(struct gml_graph *g);
static void doublespacey(struct gml_graph *g);
static void edgelabels(struct gml_graph *g);
static void splitedges(struct gml_graph *g);
static void nodecounts(struct gml_graph *g);
static void barycenter(struct gml_graph *g, int it1v, int it2v);
static void improve_positions(struct gml_graph *g);
static void finalxy(struct gml_graph *g);
static struct gml_edge *findedge(int num);
static void setminmax(struct gml_graph *g);
/* returns a version number as version 1.0 returns int 10 */
int sfg_version(void)
{
return (20);
}
/* init
* returns 0 if oke
* returns -1 if already inited
* returns -2 if other error
*/
int sfg_init(void)
{
if (maingraph) {
return (-1);
}
maingraph = calloc(1, sizeof(struct gml_graph));
if (maingraph == NULL) {
return (-2);
}
/* min (x,y) spacing between nodes */
maingraph->xspacing = NXSPACING;
maingraph->yspacing = NYSPACING;
maingraph->do_edgelabels = 1;
return (0);
}
/* de-init
* returns 0 if oke
* returns -1 if not inited
*/
int sfg_deinit(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->numce) {
free(maingraph->numce);
maingraph->numce = NULL;
}
if (maingraph->nnodes_of_level) {
free(maingraph->nnodes_of_level);
maingraph->nnodes_of_level = NULL;
}
if (maingraph->startnodes) {
free(maingraph->startnodes);
maingraph->startnodes = NULL;
}
clear_stlist_all(maingraph);
clear_edgelist(maingraph);
clear_nodelist(maingraph);
free(maingraph);
maingraph = NULL;
return (0);
}
/* add a node with uniq number starting at 1
* with (tx,ty) as rectangle size for label text or (0,0)
* before adding edges all node numbers must be defined
* returns 0 if oke
* returns -1 if not inited
* returns -2 if number is lower then 1
* returns -3 if tx number is lower then 0
* returns -4 if ty number is lower then 0
* returns -5 if layout already done
* returns -6 if node already defined
* returns -7 if other error
*/
int sfg_addnode(int number, int tx, int ty)
{
struct gml_node *nn = NULL;
struct gml_nlist *nl = NULL;
if (maingraph == NULL) {
return (-1);
}
if (number < 1) {
return (-2);
}
if (tx < 0) {
return (-3);
}
if (ty < 0) {
return (-4);
}
if (maingraph->layouted) {
return (-5);
}
/* check if node does exist already */
if (uniqnode(maingraph, number)) {
return (-6);
}
/* create the new node */
nn = calloc(1, sizeof(struct gml_node));
if (nn == NULL) {
return (-7);
}
nl = calloc(1, sizeof(struct gml_nlist));
if (nl == NULL) {
free(nn);
return (-7);
}
nn->nr = number;
nn->tx = tx;
nn->ty = ty;
/* data field is inited NULL and is set via other routine */
nl->node = nn;
if (maingraph->nodelist == NULL) {
maingraph->nodelist = nl;
maingraph->nodelistend = nl;
} else {
maingraph->nodelistend->next = nl;
maingraph->nodelistend = nl;
}
if (number > maingraph->nodenum) {
/* highest node number in use */
maingraph->nodenum = number;
}
uniqnode_add(maingraph, nn);
/* number of nodes in the graph */
maingraph->nnodes++;
return (0);
}
/* add a edge with uniq number starting at 1
* the from-node number is in from, the to-node number is in to
* self-edges are allowed but not with a label
* with (tx,ty) as rectangle size for label text or (0,0)
* returns 0 if oke
* returns -1 if not inited
* returns -2 if number is lower then 1
* returns -3 if tx number is lower then 0
* returns -4 if ty number is lower then 0
* returns -5 if from-node number is not defined
* returns -6 if to-node number is not defined
* returns -7 if self-edge with a label
* returns -8 if layout already done
* returns -9 if other error
*/
int sfg_addedge(int number, int from, int to, int tx, int ty)
{
struct gml_node *fn = NULL;
struct gml_node *tn = NULL;
struct gml_edge *e = NULL;
struct gml_elist *el = NULL;
if (maingraph == NULL) {
return (-1);
}
if (number < 1) {
return (-2);
}
if (tx < 0) {
return (-3);
}
if (ty < 0) {
return (-4);
}
if (from < 1) {
return (-5);
}
if (to < 1) {
return (-6);
}
if (from == to) {
if (tx || ty) { /* do not allow self-edge with a label */
return (-7);
}
}
if (maingraph->layouted) {
return (-8);
}
fn = uniqnode(maingraph, from);
if (fn == NULL) {
return (-5);
}
tn = uniqnode(maingraph, to);
if (tn == NULL) {
return (-6);
}
if (number > maingraph->edgenum) {
maingraph->edgenum = number;
}
maingraph->nedges++;
if (fn == tn) {
/* at self-edge increase counter at node */
fn->nselfedges++;
} else {
/* fresh new edge */
e = calloc(1, sizeof(struct gml_edge));
if (e == NULL) {
return (-9);
}
el = calloc(1, sizeof(struct gml_elist));
if (el == NULL) {
free(e);
return (-9);
}
e->nr = number;
e->from_node = fn;
e->to_node = tn;
e->tx = tx;
e->ty = ty;
if (tx || ty) {
/* mark there is a edgelabel */
e->elabel = 1;
/* number of edge labels in the graph */
maingraph->nedgelabels++;
}
el->edge = e;
if (maingraph->edgelist == NULL) {
maingraph->edgelist = el;
maingraph->edgelistend = el;
} else {
maingraph->edgelistend->next = el;
maingraph->edgelistend = el;
}
}
return (0);
}
/* run sugiyama barycenter layout
* returns 0 if oke
* returns -1 if not inited
* returns -2 if layout already done
* returns -3 if no nodes in the graph
*/
int sfg_layout(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted) {
return (-2);
}
if (maingraph->nodelist == NULL) {
return (-3);
}
/* prepare */
prep(maingraph);
/* re-organize nodelist */
reorg(maingraph);
/* change cycles in the graph */
uncycle(maingraph);
/* re-organize nodelist */
reorg(maingraph);
/* set y level of all nodes */
ylevels(maingraph);
/* find shorter edges */
shorteredges(maingraph);
/* change edge directions downwards */
edgesdownwards(maingraph);
/* check length of edges */
edgelen(maingraph);
/* doublespace the vertical levels */
doublespacey(maingraph);
/* split edges with label into node->label->node */
edgelabels(maingraph);
/* split longer edges */
splitedges(maingraph);
/* create level node count data */
nodecounts(maingraph);
/* run barycenter using defaults (0,0) or a value */
barycenter(maingraph, 100, 100);
/* re-calc positions */
improve_positions(maingraph);
/* final (x,y) positioning of nodes/edges */
finalxy(maingraph);
/* update node min/max and edge min/max */
setminmax(maingraph);
/* set layout is calculated */
maingraph->layouted = 1;
return (0);
}
/* return edge crossings in the graph
* returns crossings >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_crossings(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-22);
}
return (maingraph->sugi_fcrossings);
}
/* return initial edge crossings in the graph
* returns crossings >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_initialcrossings(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->sugi_icrossings);
}
/* set 1 to add edgelabels, or 0 to remove edgelabels
* returns 0 if oke
* returns -1 if not inited
* returns -2 if already layouted
*/
int sfg_edgelabels(int status)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted) {
return (-2);
}
if (status) {
maingraph->do_edgelabels = 1;
} else {
maingraph->do_edgelabels = 1;
}
return (0);
}
/* return x pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodexpos(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->finx);
}
/* return y pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodeypos(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->finy);
}
/* return relative x pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_noderelxpos(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->relx);
}
/* return relative y pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_noderelypos(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->rely);
}
/* return level y start pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodely0(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->ly0);
}
/* return level y end pos of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodely1(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->ly1);
}
/* return x size of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodexsize(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->tx);
}
/* return y size of node with uniq number
* returns >= 0 if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if number < 1
* returns -4 if node not found
*/
int sfg_nodeysize(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->ty);
}
/* set min. x spacing between nodes
* returns 0 if oke
* returns -1 if not inited
* returns -2 if number is lower then 0
* returns -3 if layout already done
*/
int sfg_xspacing(int num)
{
if (maingraph == NULL) {
return (-1);
}
if (num < 1) {
return (-2);
}
if (maingraph->layouted) {
return (-3);
}
maingraph->xspacing = num;
return (0);
}
/* set min. y spacing between nodes
* returns 0 if oke
* returns -1 if not inited
* returns -2 if number is lower then 0
* returns -3 if layout already done
*/
int sfg_yspacing(int num)
{
if (maingraph == NULL) {
return (-1);
}
if (num < 1) {
return (-2);
}
if (maingraph->layouted) {
return (-3);
}
maingraph->yspacing = num;
return (0);
}
/* get max x pos in drawing
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_maxx(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->maxx);
}
/* get max y pos in drawing
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_maxy(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->maxy);
}
/* get min node number in use after layout
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if there are no nodes
*/
int sfg_nodemin(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (maingraph->nodelist == NULL) {
return (-3);
}
return (maingraph->nodemin);
}
/* get maxc node number in use after layout
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if there are no nodes
*/
int sfg_nodemax(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (maingraph->nodelist == NULL) {
return (-3);
}
return (maingraph->nodemax);
}
/* get min edge number in use after layout
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if there are no edges
*/
int sfg_edgemin(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (maingraph->edgelist == NULL) {
return (-3);
}
return (maingraph->edgemin);
}
/* get max edge number in use after layout
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
* returns -3 if there are no edges
*/
int sfg_edgemax(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (maingraph->edgelist == NULL) {
return (-3);
}
return (maingraph->edgemax);
}
/* get number of levels
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_nlevels(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->maxlevel + 1);
}
/* get number of nodes
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_nnodes(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->nnodes);
}
/* get number of edges
* returns value if oke
* returns -1 if not inited
* returns -2 if layout not done
*/
int sfg_nedges(void)
{
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
return (maingraph->nedges);
}
/* return type of node with uniq number
* returns type of node, 1=regular, 2=dummy, 3=edgelabel node
* returns -1 not inited
* returns -2 if layout not done
* returns -3 if nodenumber is < 1
* returns -4 if node not found
*/
int sfg_nodetype(int num)
{
struct gml_node *n = NULL;
int type = 0;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
if (n->dummy) {
type = 2;
} else if (n->elabel) {
type = 3;
} else {
type = 1;
}
return (type);
}
/* return number of selfedges at node
* returns number of selfedges if oke
* returns -1 not inited
* returns -2 if layout not done
* returns -3 if nodenumber is < 1
* returns -4 if node not found
*/
int sfg_nodeselfedges(int num)
{
struct gml_node *n = NULL;
if (maingraph == NULL) {
return (-1);
}
if (maingraph->layouted == 0) {
return (-2);
}
if (num < 1) {
return (-3);
}
n = uniqnode(maingraph, num);
if (n == NULL) {
return (-4);
}
return (n->nselfedges);
}