-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphlib.c
4307 lines (3727 loc) · 129 KB
/
graphlib.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
/*
Copyright (c) 2007-2013
Lawrence Livermore National Security, LLC.
Produced at the Lawrence Livermore National Laboratory.
Written by Martin Schulz, Dorian Arnold, and Gregory L. Lee
Contact email: schulzm@llnl.gov
LLNL-CODE-624053
All rights reserved.
This file is part of GraphLib. For details see https://github.com/lee218llnl/graphlib.
Please also read the file "LICENSE" included in this package for
Our Notice and GNU Lesser General Public License.
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) version 2.1
dated February 1999.
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
terms and conditions of the GNU General Public License for more
details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the
Free Software Foundation, Inc.,
59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
/*-----------------------------------------------------------------*/
/* Library to create, manipulate, and export graphs */
/* Martin Schulz, LLNL, 2005-2006 */
/* Additions by Dorian Arnold, LLNL, 2006 */
/* Modifications by Gregory L. Lee, LLNL, 2006-2011 */
/*-----------------------------------------------------------------*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include "graphlib.h"
/*-----------------------------------------------------------------*/
/* Constants */
#define MAXEDGE_GML 5
/*.......................................................*/
/* Attributes */
#define DEFAULT_NODE_COLOR GRC_YELLOW
#define DEFAULT_NODE_WIDTH 20
#define DEFAULT_EDGE_COLOR GRC_BLUE
#define DEFAULT_EDGE_WIDTH 1
#define DEFAULT_FONT_SIZE -1
#define DEFAULT_BLOCK GRB_NONE
#define DEFAULT_EDGE_STYLE GRA_LINE
#define DEFAULT_NODE_COOR -1
#define GRAPHLIB_DEFAULT_ANNOTATION 0.0
/*.......................................................*/
/* Fragment sizes */
#define NODEFRAGSIZE 2000
#define EDGEFRAGSIZE 2000
/*-----------------------------------------------------------------*/
/* Types */
/*............................................................*/
/* Nodes */
typedef struct graphlib_nodeentry_d *graphlib_nodeentry_p;
typedef struct graphlib_nodedata_d *graphlib_nodedata_p;
typedef struct graphlib_nodedata_d
{
graphlib_node_t id;
graphlib_nodeattr_t attr;
} graphlib_nodedata_t;
typedef union graphlib_innodeentry_d
{
graphlib_nodeentry_p freeptr;
graphlib_nodedata_t data;
} graphlib_innodeentry_t;
typedef struct graphlib_nodeentry_d
{
int full;
graphlib_innodeentry_t entry;
} graphlib_nodeentry_t;
typedef struct graphlib_nodefragment_d *graphlib_nodefragment_p;
typedef struct graphlib_nodefragment_d
{
int count;
graphlib_nodefragment_p next;
graphlib_annotation_t *grannot;
/* must be last */
graphlib_nodeentry_t node[NODEFRAGSIZE];
} graphlib_nodefragment_t;
/*............................................................*/
/* Edges */
typedef struct graphlib_edgeentry_d *graphlib_edgeentry_p;
typedef struct graphlib_edgedata_d *graphlib_edgedata_p;
typedef struct graphlib_edgedata_d
{
graphlib_nodeentry_t *ref_from;
graphlib_nodeentry_t *ref_to;
graphlib_node_t node_from;
graphlib_node_t node_to;
graphlib_edgeattr_t attr;
} graphlib_edgedata_t;
typedef union graphlib_inedgeentry_d
{
graphlib_edgeentry_p freeptr;
graphlib_edgedata_t data;
} graphlib_inedgeentry_t;
typedef struct graphlib_edgeentry_d
{
int full;
graphlib_inedgeentry_t entry;
} graphlib_edgeentry_t;
typedef struct graphlib_edgefragment_d *graphlib_edgefragment_p;
typedef struct graphlib_edgefragment_d
{
int count;
graphlib_edgefragment_p next;
/* must be last */
graphlib_edgeentry_t edge[EDGEFRAGSIZE];
} graphlib_edgefragment_t;
/*............................................................*/
/* Graph and Graphlist */
typedef struct graphlib_graph_d
{
int directed;
int edgeset;
int numannotation;
int num_node_attrs;
int num_edge_attrs;
char **annotations;
char **node_attr_keys;
char **edge_attr_keys;
graphlib_nodefragment_t *nodes;
graphlib_edgefragment_t *edges;
graphlib_nodeentry_p freenodes;
graphlib_edgeentry_p freeedges;
graphlib_functiontable_p functions;
} graphlib_graph_t;
typedef struct graphlib_graphlist_d *graphlib_graphlist_p;
typedef struct graphlib_graphlist_d
{
graphlib_graph_p graph;
graphlib_graphlist_p next;
} graphlib_graphlist_t;
/*-----------------------------------------------------------------*/
/* Variables */
graphlib_graphlist_t *allgraphs=NULL;
static unsigned int grlibint_num_colors=0;
static long node_clusters[GRC_RAINBOWCOLORS];
/* Default function table */
static graphlib_functiontable_p default_functions=NULL;
/*-----------------------------------------------------------------*/
/* Simple support routines */
/*............................................................*/
/* find a node in the node table with indices */
graphlib_error_t grlibint_findNodeIndex(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_nodeentry_p *entry,
graphlib_nodefragment_p *nodefrag,
int *index)
{
*nodefrag=graph->nodes;
while ((*nodefrag)!=NULL)
{
for ((*index)=0; (*index)<(*nodefrag)->count; (*index)++)
{
if ((*nodefrag)->node[*index].full)
{
if ((*nodefrag)->node[*index].entry.data.id==node)
{
*entry=&((*nodefrag)->node[(*index)]);
return GRL_OK;
}
}
}
(*nodefrag)=(*nodefrag)->next;
}
return GRL_NONODE;
}
/*............................................................*/
/* find a node in the node table */
graphlib_error_t grlibint_findNode(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_nodeentry_p *entry)
{
int i;
graphlib_nodefragment_p nodefrag;
return grlibint_findNodeIndex(graph,node,entry,&nodefrag,&i);
}
/*............................................................*/
/* find an edge in the edge table */
graphlib_error_t grlibint_findEdge(graphlib_graph_p graph,
graphlib_node_t node1,
graphlib_node_t node2,
graphlib_edgeentry_p *entry)
{
int i;
graphlib_edgefragment_p edgefrag;
edgefrag=graph->edges;
while (edgefrag!=NULL)
{
for (i=0; i<edgefrag->count; i++)
{
if (edgefrag->edge[i].full)
{
if ((edgefrag->edge[i].entry.data.node_from==node1) &&
(edgefrag->edge[i].entry.data.node_to==node2))
{
*entry=&(edgefrag->edge[i]);
return GRL_OK;
}
}
}
edgefrag=edgefrag->next;
}
return GRL_NOEDGE;
}
/*............................................................*/
/* find an incoming edge of a given color */
graphlib_error_t grlibint_findIncomingEdgeColor(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_color_t color,
graphlib_edgeentry_p *entry)
{
int i;
graphlib_edgefragment_p edgefrag;
edgefrag=graph->edges;
while (edgefrag!=NULL)
{
for (i=0; i<edgefrag->count; i++)
{
if (edgefrag->edge[i].full)
{
if ((edgefrag->edge[i].entry.data.attr.color==color) &&
(edgefrag->edge[i].entry.data.node_to==node))
{
*entry=&(edgefrag->edge[i]);
return GRL_OK;
}
}
}
edgefrag=edgefrag->next;
}
return GRL_NOEDGE;
}
/*............................................................*/
/* find an incoming edge */
graphlib_error_t grlibint_findIncomingEdge(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_edgeentry_p *entry)
{
int i;
graphlib_edgefragment_p edgefrag;
edgefrag=graph->edges;
while (edgefrag!=NULL)
{
for (i=0; i<edgefrag->count; i++)
{
if (edgefrag->edge[i].full)
{
if (edgefrag->edge[i].entry.data.node_to==node)
{
*entry=&(edgefrag->edge[i]);
return GRL_OK;
}
}
}
edgefrag=edgefrag->next;
}
return GRL_NOEDGE;
}
/*............................................................*/
/* find an outgoing edge */
graphlib_error_t grlibint_findOutgoingEdge(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_edgeentry_p *entry)
{
int i;
graphlib_edgefragment_p edgefrag;
edgefrag=graph->edges;
while (edgefrag!=NULL)
{
for (i=0; i<edgefrag->count; i++)
{
if (edgefrag->edge[i].full)
{
if (edgefrag->edge[i].entry.data.node_from==node)
{
*entry=&(edgefrag->edge[i]);
return GRL_OK;
}
}
}
edgefrag=edgefrag->next;
}
return GRL_NOEDGE;
}
/*............................................................*/
/* find an incoming or outgoing edge */
graphlib_error_t grlibint_findNodeEdge(graphlib_graph_p graph,
graphlib_node_t node,
graphlib_edgeentry_p *entry)
{
int i;
graphlib_edgefragment_p edgefrag;
edgefrag=graph->edges;
while (edgefrag!=NULL)
{
for (i=0; i<edgefrag->count; i++)
{
if (edgefrag->edge[i].full)
{
if ((edgefrag->edge[i].entry.data.node_from==node) ||
(edgefrag->edge[i].entry.data.node_to==node))
{
*entry=&(edgefrag->edge[i]);
return GRL_OK;
}
}
}
edgefrag=edgefrag->next;
}
return GRL_NOEDGE;
}
/*............................................................*/
/* delete a node */
graphlib_error_t grlibint_delNode(graphlib_graph_p graph,
graphlib_nodeentry_p node)
{
int i;
if (node->full==0)
{
return GRL_NONODE;
}
graph->functions->free_node(node->entry.data.attr.label);
for (i=0; i<graph->num_node_attrs; i++)
{
graph->functions->free_node_attr(graph->node_attr_keys[i], node->entry.data.attr.attr_values[i]);
}
free(node->entry.data.attr.attr_values);
node->full=0;
node->entry.freeptr=graph->freenodes;
graph->freenodes=node;
return GRL_OK;
}
/*............................................................*/
/* delete an edge */
graphlib_error_t grlibint_delEdge(graphlib_graph_p graph,
graphlib_edgeentry_p edge)
{
int i;
if (edge->full==0)
{
return GRL_NOEDGE;
}
for (i=0; i<graph->num_edge_attrs; i++)
{
graph->functions->free_edge_attr(graph->edge_attr_keys[i], edge->entry.data.attr.attr_values[i]);
}
free(edge->entry.data.attr.attr_values);
edge->full=0;
edge->entry.freeptr=graph->freeedges;
graph->functions->free_edge(edge->entry.data.attr.label);
graph->freeedges=edge;
return GRL_OK;
}
/*............................................................*/
/* create and register a new graph */
graphlib_error_t grlibint_addGraph(graphlib_graph_p *newgraph)
{
graphlib_graphlist_p newitem;
newitem=(graphlib_graphlist_t*)malloc(sizeof(graphlib_graphlist_t));
if (newitem==NULL)
return GRL_NOMEM;
*newgraph=(graphlib_graph_p)calloc(1, sizeof(graphlib_graph_t));
if (*newgraph==NULL)
{
free(newitem);
return GRL_NOMEM;
}
newitem->next=allgraphs;
newitem->graph=*newgraph;
allgraphs=newitem;
return GRL_OK;
}
/*............................................................*/
/* create and initialize new node segment */
graphlib_error_t grlibint_newNodeFragment(graphlib_nodefragment_p *newnodefrag,
int numannotation)
{
int i;
*newnodefrag=(graphlib_nodefragment_t*)
calloc(1, sizeof(graphlib_nodefragment_t));
if (*newnodefrag==NULL)
return GRL_NOMEM;
(*newnodefrag)->next=NULL;
(*newnodefrag)->count=0;
if (numannotation==0)
(*newnodefrag)->grannot=NULL;
else
{
(*newnodefrag)->grannot=
(graphlib_annotation_t*)malloc(sizeof(graphlib_annotation_t)
*NODEFRAGSIZE*numannotation);
if ((*newnodefrag)->grannot==NULL)
{
free(*newnodefrag);
return GRL_NOMEM;
}
for (i=0; i<NODEFRAGSIZE*numannotation; i++)
{
(*newnodefrag)->grannot[i]=GRAPHLIB_DEFAULT_ANNOTATION;
}
}
return GRL_OK;
}
/*............................................................*/
/* create and initialize new edge segment */
graphlib_error_t grlibint_newEdgeFragment(graphlib_edgefragment_p *newedgefrag)
{
*newedgefrag=(graphlib_edgefragment_t*)
calloc(1, sizeof(graphlib_edgefragment_t));
if (*newedgefrag==NULL)
return GRL_NOMEM;
(*newedgefrag)->next=NULL;
(*newedgefrag)->count=0;
return GRL_OK;
}
/*............................................................*/
/* read a binary segment from disk */
graphlib_error_t grlibint_read(int fh, char *buf, int len)
{
int sum,count;
sum=0;
while (sum!=len)
{
count=read(fh,&(buf[sum]),len-sum);
if (count<=0)
return GRL_FILEERROR;
sum+=count;
}
return GRL_OK;
}
/*............................................................*/
/* write a binary segment from disk */
graphlib_error_t grlibint_write(int fh, char *buf, int len)
{
int sum,count;
sum=0;
while (sum!=len)
{
count=write(fh,&(buf[sum]),len-sum);
if (count<=0)
return GRL_FILEERROR;
sum+=count;
}
return GRL_OK;
}
/*............................................................*/
/* write len bytes of data from src to cur_pos (a marker into dest_array) -- realloc() as necessary
- updates cur_pos after write
- updates dest_array_len after realloc
*/
graphlib_error_t grlibint_copyDataToBuf(int *idx, const char *src, int len,
char **dest_array, int *dest_array_len)
{
unsigned int alloc_size;
char *dst;
if ((((*idx)+len)>(*dest_array_len)))
{
alloc_size = 8192*(1+((*idx)+len)/8192);
*dest_array = (char*)realloc(*dest_array, alloc_size);
*dest_array_len = alloc_size;
}
dst=(*dest_array)+(*idx);
memcpy(dst,src,len);
(*idx)+=len;
#ifdef DEBUG
fprintf(stderr,"[%s:%s():%d]: ", __FILE__,__FUNCTION__,__LINE__);
if (len == sizeof(int))
fprintf(stderr,"\tint: %d (%p) => %d (%p)\n",
*((int*)src),src,*((int*)dst),dst);
else if (len==sizeof(graphlib_width_t))
fprintf(stderr,"\tdouble: %.2lf (%p) => %.2lf (%p)\n",
*((double*)src),src,*((double*)dst),dst);
else
fprintf(stderr, "\tstring: \"%s\" (%p) => \"%s\" (%p)\n",src,src,dst,dst);
#endif
return GRL_OK;
}
/*............................................................*/
/* read graph from a buffer */
graphlib_error_t grlibint_copyDataFromBuf(char *dst, int *idx, int len,
char *src_array, int src_array_len)
{
char *src=src_array+*idx;
/* check for array bounds read error */
if ((((*idx)+len)>(src_array_len)))
{
return GRL_MEMORYERROR;
}
memcpy(dst,src,len);
(*idx)+=len;
#ifdef DEBUG
fprintf(stderr,"[%s:%s():%d]: ",__FILE__,__FUNCTION__,__LINE__);
if (len==sizeof(int))
fprintf(stderr,"int: %d (%p) <= %d (%p)\n",*((int*)dst),dst,*((int*)src),
src);
else if (len == sizeof(graphlib_width_t))
fprintf(stderr, "double: %.2lf (%p) <= %.2lf (%p)\n",
*((double*)dst),dst,*((double*)src),src);
else
fprintf(stderr, "string: \"%s\" (%p) <= \"%s\" (%p)\n",dst,dst,src,src);
#endif
return GRL_OK;
}
/*-----------------------------------------------------------------*/
/* color management */
/*............................................................*/
/* color settings for GML export */
void grlibint_exp_dot_color(graphlib_color_t color, FILE *fh)
{
switch (color)
{
case GRC_FIREBRICK:
fprintf(fh,"\"#B22222\"");
break;
case GRC_YELLOW:
fprintf(fh,"\"#FFFF00\"");
break;
case GRC_ORANGE:
fprintf(fh,"\"#FFA500\"");
break;
case GRC_TAN:
fprintf(fh,"\"#D2B48C\"");
break;
case GRC_GOLDENROD:
fprintf(fh,"\"#DAA520\"");
break;
case GRC_PURPLE:
fprintf(fh,"\"#800080\"");
break;
case GRC_OLIVE:
fprintf(fh,"\"#556B2F\"");
break;
case GRC_GREY:
fprintf(fh,"\"#AAAAAA\"");
break;
case GRC_LIGHTGREY:
fprintf(fh,"\"#DDDDDD\"");
break;
case GRC_BLACK:
fprintf(fh,"\"#000000\"");
break;
case GRC_BLUE:
fprintf(fh,"\"#0000FF\"");
break;
case GRC_GREEN:
fprintf(fh,"\"#00FF00\"");
break;
case GRC_DARKGREEN:
fprintf(fh,"\"#009900\"");
break;
case GRC_RED:
fprintf(fh,"\"#FF0000\"");
break;
case GRC_WHITE:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_RANGE1:
fprintf(fh,"\"#808080\"");
break;
case GRC_RANGE2:
fprintf(fh,"\"#8080A0\"");
break;
case GRC_RANGE3:
fprintf(fh,"\"#8080D0\"");
break;
case GRC_RANGE4:
fprintf(fh,"\"#8080F0\"");
break;
default:
{
if ((color>=GRC_REDSPEC) && (color<GRC_REDSPEC+GRC_SPECTRUMRANGE))
fprintf(fh,"\"#FF%02x%02x\"",256-(color-GRC_REDSPEC),256-(color-GRC_REDSPEC));
else if ((color>=GRC_GREENSPEC) && (color<GRC_GREENSPEC+GRC_SPECTRUMRANGE))
fprintf(fh,"\"#%02xFF%02x\"",256-(color-GRC_GREENSPEC),256-(color-GRC_GREENSPEC));
else if ((color>=GRC_RAINBOW) && (color<GRC_RAINBOW+GRC_RAINBOWCOLORS))
{
unsigned int color_val;
/*GLL comment: added the +.1 b/c when the num_colors was a nice power of 2 (i.e., 2,4,8) the color_vals were all coming out as shades of one color
float normalized_color_val=1.0-(((float)color-GRC_RAINBOW)/((float)grlibint_num_colors+.1));
color_val=(unsigned int)(normalized_color_val*((float)0xFFFFFF)); */
/*GLL comment: if there are a small number of colors, use a larger
normalizing value to get a better color range*/
if (grlibint_num_colors<18)
color_val=16777215-(unsigned int)(((color-GRC_RAINBOW)/18.0)*16777215);
/* Powers of 2 number of colors create red-only colors */
else if (grlibint_num_colors%32==0)
color_val=16777215-(unsigned int)(((color-GRC_RAINBOW)/(float)(grlibint_num_colors+1))*16777215);
else
color_val=16777215-(unsigned int)(((color-GRC_RAINBOW)/(float)grlibint_num_colors)*16777215);
fprintf(fh,"\"#%06x\"",color_val);
}
else
fprintf(fh,"\"#CCCCFF\"");
break;
}
}
}
/*............................................................*/
/* color settings for DOT files with arbitrary colors */
void grlibint_exp_gml_color(graphlib_color_t color, FILE *fh)
{
grlibint_exp_dot_color(color,fh);
fprintf(fh,"\n");
}
/*............................................................*/
/* color settings for DOT files with reduced colors */
void grlibint_exp_plaindot_color(graphlib_color_t color, FILE *fh)
{
if ((color>=GRC_RAINBOW) && (color<GRC_RAINBOW+GRC_RAINBOWCOLORS))
{
color=(color-GRC_RAINBOW) % GRL_NUM_COLORS;
}
switch (color)
{
case GRC_FIREBRICK:
fprintf(fh,"red");
break;
case GRC_YELLOW:
fprintf(fh,"yellow");
break;
case GRC_ORANGE:
fprintf(fh,"orange");
break;
case GRC_TAN:
fprintf(fh,"beige");
break;
case GRC_GOLDENROD:
fprintf(fh,"yellow");
break;
case GRC_PURPLE:
fprintf(fh,"purple");
break;
case GRC_OLIVE:
fprintf(fh,"green");
break;
case GRC_GREY:
fprintf(fh,"grey");
break;
case GRC_LIGHTGREY:
fprintf(fh,"grey");
break;
case GRC_BLACK:
fprintf(fh,"black");
break;
case GRC_BLUE:
fprintf(fh,"blue");
break;
case GRC_GREEN:
fprintf(fh,"green");
break;
case GRC_DARKGREEN:
fprintf(fh,"green");
break;
case GRC_RED:
fprintf(fh,"red");
break;
case GRC_WHITE:
fprintf(fh,"white");
break;
case GRC_RANGE1:
fprintf(fh,"blue");
break;
case GRC_RANGE2:
fprintf(fh,"blue");
break;
case GRC_RANGE3:
fprintf(fh,"blue");
break;
case GRC_RANGE4:
fprintf(fh,"blue");
break;
default:
{
if ((color>=GRC_REDSPEC) && (color<GRC_REDSPEC+GRC_SPECTRUMRANGE))
fprintf(fh,"red");
else if ((color>=GRC_GREENSPEC) &&
(color<GRC_GREENSPEC+GRC_SPECTRUMRANGE))
fprintf(fh,"green");
else
fprintf(fh,"grey");
break;
}
}
}
/*............................................................*/
/* font color settings for GML export */
void grlibint_exp_dot_fontcolor(graphlib_color_t color, FILE *fh)
{
switch (color)
{
case GRC_FIREBRICK:
fprintf(fh,"\"#000000\"");
break;
case GRC_YELLOW:
fprintf(fh,"\"#000000\"");
break;
case GRC_ORANGE:
fprintf(fh,"\"#000000\"");
break;
case GRC_TAN:
fprintf(fh,"\"#000000\"");
break;
case GRC_GOLDENROD:
fprintf(fh,"\"#000000\"");
break;
case GRC_PURPLE:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_OLIVE:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_GREY:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_LIGHTGREY:
fprintf(fh,"\"#000000\"");
break;
case GRC_BLACK:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_BLUE:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_GREEN:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_DARKGREEN:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_RED:
fprintf(fh,"\"#FFFFFF\"");
break;
case GRC_WHITE:
fprintf(fh,"\"#000000\"");
break;
case GRC_RANGE1:
fprintf(fh,"\"#000000\"");
break;
case GRC_RANGE2:
fprintf(fh,"\"#000000\"");
break;
case GRC_RANGE3:
fprintf(fh,"\"#000000\"");
break;
case GRC_RANGE4:
fprintf(fh,"\"#000000\"");
break;
default:
{
if ((color>=GRC_REDSPEC) && (color<GRC_REDSPEC+GRC_SPECTRUMRANGE))
{
if ((color-GRC_REDSPEC)<(GRC_SPECTRUMRANGE/2))
fprintf(fh,"\"#000000\"");
else
fprintf(fh,"\"#FFFFFF\"");
}
else if ((color>=GRC_GREENSPEC) && (color<GRC_GREENSPEC+
GRC_SPECTRUMRANGE))
{
if ((color-GRC_GREENSPEC)<(GRC_SPECTRUMRANGE/2))
fprintf(fh,"\"#000000\"");
else
fprintf(fh,"\"#FFFFFF\"");
}
else if ((color>=GRC_RAINBOW) && (color<GRC_RAINBOW+GRC_RAINBOWCOLORS))
{
unsigned int color_val;
float normalized_color_val=1.0-(((float)color-GRC_RAINBOW)/
((float)grlibint_num_colors));
color_val=(unsigned int)(normalized_color_val*((float)0xFFFFFF));
if (((color_val & 0xFF0000)+(color_val && 0xFF00)+(color_val &&
0xFF))>0xFF)
fprintf(fh,"\"#000000\"");
else
fprintf(fh,"\"#FFFFFF\"");
}
else
fprintf(fh,"\"#FFFFFF\"");
break;
}
}
}
/*............................................................*/
/* color settings for DOT files with arbitrary colors */
void grlibint_exp_gml_fontcolor(graphlib_color_t color, FILE *fh)
{
grlibint_exp_dot_fontcolor(color,fh);
fprintf(fh,"\n");
}
/*............................................................*/
/* color settings for DOT files with reduced colors */
void grlibint_exp_plaindot_fontcolor(graphlib_color_t color, FILE *fh)
{
if ((color>=GRC_RAINBOW) && (color<GRC_RAINBOW+GRC_RAINBOWCOLORS))
{
color=(color-GRC_RAINBOW) % GRL_NUM_COLORS;
}
switch (color)
{
case GRC_FIREBRICK:
fprintf(fh,"white");
break;
case GRC_YELLOW:
fprintf(fh,"black");
break;
case GRC_ORANGE:
fprintf(fh,"black");
break;
case GRC_TAN:
fprintf(fh,"black");
break;
case GRC_GOLDENROD:
fprintf(fh,"red");
break;
case GRC_PURPLE:
fprintf(fh,"white");
break;
case GRC_OLIVE:
fprintf(fh,"white");
break;
case GRC_GREY:
fprintf(fh,"white");
break;
case GRC_LIGHTGREY:
fprintf(fh,"black");
break;
case GRC_BLACK:
fprintf(fh,"white");
break;
case GRC_BLUE:
fprintf(fh,"white");
break;
case GRC_GREEN:
fprintf(fh,"black");