31#define ND_id(n) (((Agnodeinfo_t*)((n)->base.data))->id)
35 fprintf(stderr,
"can only 1, 2 or 3 dimensional color space. with color value between 0 to 1\n");
40 MIN((
unsigned int) (
color[1]*255), 255),
MIN((
unsigned int)(
color[2]*255), 255));
43 MIN((
unsigned int) (
color[0]*255), 255),
MIN((
unsigned int)(
color[0]*255), 255));
46 0,
MIN((
unsigned int)(
color[1]*255), 255));
67 if (
row == col)
continue;
100 fprintf (stderr,
"Format %d not supported\n",
format);
131 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1) v = 1;
142 bool has_positions =
true;
151 if ((pval =
agxget(n, psym)) && *pval) {
153 nitems = sscanf(pval,
"%lf,%lf", &xx, &yy);
155 has_positions =
false;
160 }
else if (
dim == 3){
161 nitems = sscanf(pval,
"%lf,%lf,%lf", &xx, &yy, &zz);
163 has_positions =
false;
169 }
else if (
dim == 4){
170 nitems = sscanf(pval,
"%lf,%lf,%lf,%lf", &xx, &yy, &zz,&ww);
172 has_positions =
false;
179 }
else if (
dim == 1){
180 nitems = sscanf(pval,
"%lf", &xx);
191 has_positions =
false;
195 if (!has_positions) {
203 size_t sz =
sizeof(double);
249 char *pos =
agxget (e, sym);
250 (*xsplines)[i] = strdup(pos);
258 if (h >=
'0' && h <=
'9')
return h -
'0';
259 if (h >=
'a' && h <=
'f')
return 10 + h -
'a';
260 if (h >=
'A' && h <=
'F')
return 10 + h -
'A';
275 if (!clust_clr_sym) clust_clr_sym =
agattr(g,
AGNODE,
"clustercolor",
"-1");
278 if (rgb_r && rgb_g && rgb_b) {
279 rgb2hex(rgb_r[clusters[i]], rgb_g[clusters[i]], rgb_b[clusters[i]],
287SparseMatrix Import_coord_clusters_from_dot(
Agraph_t* g,
int maxcluster,
int dim,
int *nn,
double **label_sizes,
double **x,
int **clusters,
float **rgb_r,
float **rgb_g,
float **rgb_b,
float **fsz,
char ***labels,
int default_color_scheme,
int clustering_scheme,
int useClusters){
296 int i,
row, ic,nc, j;
302 int MAX_GRPS, MIN_GRPS;
303 bool noclusterinfo =
false;
308 switch (default_color_scheme){
373 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1)
383 type,
sizeof(
double));
386 *clusters =
gv_calloc(nnodes,
sizeof(
int));
395 memset (*clusters, 0,
sizeof(
int)*nnodes);
402 fprintf (stderr,
"Warning: node %s appears in multiple clusters.\n",
agnameof(n));
404 (*clusters)[i] = gid;
409 if ((*clusters)[i] == 0)
415 else if (clust_sym) {
418 if ((sscanf(
agxget(n,clust_sym),
"%d", &ic)>0)) {
425 MIN_GRPS =
MIN(MIN_GRPS, ic);
428 noclusterinfo =
true;
434 noclusterinfo =
true;
439 if (!clust_sym) clust_sym =
agattr(g,
AGNODE,
"cluster",
"-1");
443 &nc, clusters, &modularity);
446 &nc, clusters, &modularity);
450 for (i = 0; i < nnodes; i++) (*clusters)[i]++;
453 snprintf(scluster,
sizeof(scluster),
"%d", (*clusters)[i]);
454 agxset(n,clust_sym,scluster);
459 fprintf(stderr,
" no complement clustering info in dot file, using modularity clustering. Modularity = %f, ncluster=%d\n",modularity, nc);
464 if (pal || (!noclusterinfo && clust_clr_sym)){
465 *rgb_r =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
466 *rgb_g =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
467 *rgb_b =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
474 *labels =
gv_calloc(nnodes,
sizeof(
char*));
481 sscanf(
agget(n,
"width"),
"%lf", &sz);
482 (*label_sizes)[i*2] =
POINTS(sz*0.5);
483 sscanf(
agget(n,
"height"),
"%lf", &sz);
484 (*label_sizes)[i*2+1] =
POINTS(sz*0.5);
486 (*label_sizes)[i*2] =
POINTS(0.75/2);
487 (*label_sizes)[i*2+1] =
POINTS(0.5*2);
490 if (
agget(n,
"fontsize")){
491 sscanf(
agget(n,
"fontsize"),
"%f", &ff);
497 if (
agget(n,
"label") && strcmp(
agget(n,
"label"),
"") != 0 && strcmp(
agget(n,
"label"),
"\\N") != 0){
498 char *lbs =
agget(n,
"label");
499 (*labels)[i] = strdup(lbs);
507 if (MAX_GRPS-MIN_GRPS < max_color) {
508 j = (j-MIN_GRPS)*((
int)((max_color-1)/
MAX((MAX_GRPS-MIN_GRPS),1)));
510 j = (j-MIN_GRPS)%max_color;
514 (*rgb_r)[(*clusters)[i]] = pal[3*j+0];
515 (*rgb_g)[(*clusters)[i]] = pal[3*j+1];
516 (*rgb_b)[(*clusters)[i]] = pal[3*j+2];
520 (*rgb_r)[(*clusters)[i]] =
color.u.RGBA[0];
521 (*rgb_g)[(*clusters)[i]] =
color.u.RGBA[1];
522 (*rgb_b)[(*clusters)[i]] =
color.u.RGBA[2];
525 const char *cc =
agget(n,
"clustercolor");
526 if (!noclusterinfo &&
agget(n,
"cluster") && cc && strlen(cc) >= 7 && pal) {
536 bool has_position =
false;
541 if (
agget(n,
"pos")){
543 sscanf(
agget(n,
"pos"),
"%lf,%lf", &xx, &yy);
547 fprintf(stderr,
"WARNING: pos field missing for node %d, set to origin\n",i);
576 size_t sz =
sizeof(double);
602 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1)
613 int *clusters =
gv_calloc(nnodes,
sizeof(
int));
617 if (!clust_sym) clust_sym =
agattr(g,
AGNODE,
"cluster",
"-1");
621 &nc, &clusters, &modularity);
624 &nc, &clusters, &modularity);
628 for (i = 0; i < nnodes; i++) (clusters)[i]++;
631 agxbuf value_buffer = {0};
632 agxbprint(&value_buffer,
"%d", clusters[i]);
637 fprintf(stderr,
" no complement clustering info in dot file, using modularity clustering. Modularity = %f, ncluster=%d\n",modularity, nc);
void Dot_SetClusterColor(Agraph_t *g, float *rgb_r, float *rgb_g, float *rgb_b, int *clusters)
SparseMatrix SparseMatrix_import_dot(Agraph_t *g, int dim, double **x, int format)
int getDotNodeID(Agnode_t *n)
void initDotIO(Agraph_t *g)
SparseMatrix Import_coord_clusters_from_dot(Agraph_t *g, int maxcluster, int dim, int *nn, double **label_sizes, double **x, int **clusters, float **rgb_r, float **rgb_g, float **rgb_b, float **fsz, char ***labels, int default_color_scheme, int clustering_scheme, int useClusters)
static float hexcol2rgb(const char *h)
void attach_edge_colors(Agraph_t *g, int dim, double *colors)
static void color_string(agxbuf *buf, int dim, double *color)
void setDotNodeID(Agnode_t *n, int v)
static int hex2int(char h)
void attached_clustering(Agraph_t *g, int maxcluster, int clustering_scheme)
int Import_dot_splines(Agraph_t *g, int *ne, char ***xsplines)
@ COLOR_SCHEME_ADAM_BLEND
@ COLOR_SCHEME_SEQUENTIAL_SINGLEHUE_RED
@ COLOR_SCHEME_SEQUENTIAL_SINGLEHUE_RED_LIGHTER
@ COLOR_SCHEME_BLUE_YELLOW
SparseMatrix SparseMatrix_from_coordinate_arrays(int nz, int m, int n, int *irn, int *jcn, void *val0, int type, size_t sz)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, int nz, int type, int format)
static void agxbfree(agxbuf *xb)
free any malloced resources
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static WUR char * agxbuse(agxbuf *xb)
Memory allocation wrappers that exit on failure.
static void * gv_calloc(size_t nmemb, size_t size)
void modularity_clustering(SparseMatrix A, bool inplace, int ncluster_target, int *nclusters, int **assignment, double *modularity)
const float palette_sequential_singlehue_red[1001][3]
const float palette_grey[1001][3]
const float palette_sequential_singlehue_red_lighter[1001][3]
const float palette_blue_to_yellow[1001][3]
const float palette_grey_to_red[1001][3]
const float palette_adam[11][3]
const float palette_white_to_red[1001][3]
const float palette_adam_blend[1001][3]
const float palette_pastel[1001][3]
const float palette_primary[1001][3]
void rgb2hex(float r, float g, float b, agxbuf *cstring, const char *opacity)
void colorxlate(char *str, agxbuf *buf)
static NORETURN void graphviz_exit(int status)
int agnedges(Agraph_t *g)
int agnnodes(Agraph_t *g)
Agsym_t * agattr(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up attributes of a graph
int agxset(void *obj, Agsym_t *sym, const char *value)
char * agget(void *obj, char *name)
char * agxget(void *obj, Agsym_t *sym)
Agedge_t * agfstout(Agraph_t *g, Agnode_t *n)
Agedge_t * agnxtout(Agraph_t *g, Agedge_t *e)
void agerrorf(const char *fmt,...)
Agnode_t * agnxtnode(Agraph_t *g, Agnode_t *n)
Agnode_t * agfstnode(Agraph_t *g)
char * agnameof(void *)
returns a string descriptor for the object.
void aginit(Agraph_t *g, int kind, const char *rec_name, int rec_size, int move_to_front)
attach new records to objects of specified kind
Agraph_t * agfstsubg(Agraph_t *g)
Agraph_t * agnxtsubg(Agraph_t *subg)
static void color(Agraph_t *g)
GVIO_API const char * format
void mq_clustering(SparseMatrix A, int maxcluster, int *nclusters, int **assignment, double *mq)
static int nedges
total no. of edges used in routing
static bool startswith(const char *s, const char *prefix)
does the string s begin with the string prefix?
implementation of Agrec_t