32#define ND_id(n) (((Agnodeinfo_t*)((n)->base.data))->id)
36 fprintf(stderr,
"can only 1, 2 or 3 dimensional color space. with color value between 0 to 1\n");
41 MIN((
unsigned int) (
color[1]*255), 255),
MIN((
unsigned int)(
color[2]*255), 255));
44 MIN((
unsigned int) (
color[0]*255), 255),
MIN((
unsigned int)(
color[0]*255), 255));
47 0,
MIN((
unsigned int)(
color[1]*255), 255));
68 if (
row == col)
continue;
101 fprintf (stderr,
"Format %d not supported\n",
format);
132 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1) v = 1;
143 bool has_positions =
true;
152 if ((pval =
agxget(n, psym)) && *pval) {
154 nitems = sscanf(pval,
"%lf,%lf", &xx, &yy);
156 has_positions =
false;
161 }
else if (
dim == 3){
162 nitems = sscanf(pval,
"%lf,%lf,%lf", &xx, &yy, &zz);
164 has_positions =
false;
170 }
else if (
dim == 4){
171 nitems = sscanf(pval,
"%lf,%lf,%lf,%lf", &xx, &yy, &zz,&ww);
173 has_positions =
false;
180 }
else if (
dim == 1){
181 nitems = sscanf(pval,
"%lf", &xx);
192 has_positions =
false;
196 if (!has_positions) {
204 size_t sz =
sizeof(double);
250 char *pos =
agxget (e, sym);
251 (*xsplines)[i] = strdup(pos);
259 if (h >=
'0' && h <=
'9')
return h -
'0';
260 if (h >=
'a' && h <=
'f')
return 10 + h -
'a';
261 if (h >=
'A' && h <=
'F')
return 10 + h -
'A';
276 if (!clust_clr_sym) clust_clr_sym =
agattr_text(g,
AGNODE,
"clustercolor",
"-1");
279 if (rgb_r && rgb_g && rgb_b) {
280 rgb2hex(rgb_r[clusters[i]], rgb_g[clusters[i]], rgb_b[clusters[i]],
288SparseMatrix 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){
297 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;
443 &nc, clusters, &modularity);
446 &nc, clusters, &modularity);
450 for (i = 0; i < nnodes; i++) (*clusters)[i]++;
458 fprintf(stderr,
" no complement clustering info in dot file, using modularity clustering. Modularity = %f, ncluster=%d\n",modularity, nc);
463 if (pal || (!noclusterinfo && clust_clr_sym)){
464 *rgb_r =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
465 *rgb_g =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
466 *rgb_b =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
473 *labels =
gv_calloc(nnodes,
sizeof(
char*));
480 sscanf(
agget(n,
"width"),
"%lf", &sz);
481 (*label_sizes)[i*2] =
POINTS(sz*0.5);
482 sscanf(
agget(n,
"height"),
"%lf", &sz);
483 (*label_sizes)[i*2+1] =
POINTS(sz*0.5);
485 (*label_sizes)[i*2] =
POINTS(0.75/2);
486 (*label_sizes)[i*2+1] =
POINTS(0.5*2);
489 if (
agget(n,
"fontsize")){
490 sscanf(
agget(n,
"fontsize"),
"%f", &ff);
496 if (
agget(n,
"label") && strcmp(
agget(n,
"label"),
"") != 0 && strcmp(
agget(n,
"label"),
"\\N") != 0){
497 char *lbs =
agget(n,
"label");
498 (*labels)[i] = strdup(lbs);
506 if (MAX_GRPS-MIN_GRPS < max_color) {
507 j = (j-MIN_GRPS)*((
int)((max_color-1)/
MAX((MAX_GRPS-MIN_GRPS),1)));
509 j = (j-MIN_GRPS)%max_color;
513 (*rgb_r)[(*clusters)[i]] = pal[3*j+0];
514 (*rgb_g)[(*clusters)[i]] = pal[3*j+1];
515 (*rgb_b)[(*clusters)[i]] = pal[3*j+2];
519 (*rgb_r)[(*clusters)[i]] =
color.u.RGBA[0];
520 (*rgb_g)[(*clusters)[i]] =
color.u.RGBA[1];
521 (*rgb_b)[(*clusters)[i]] =
color.u.RGBA[2];
524 const char *cc =
agget(n,
"clustercolor");
525 if (!noclusterinfo &&
agget(n,
"cluster") && cc && strlen(cc) >= 7 && pal) {
535 bool has_position =
false;
540 if (
agget(n,
"pos")){
542 sscanf(
agget(n,
"pos"),
"%lf,%lf", &xx, &yy);
546 fprintf(stderr,
"WARNING: pos field missing for node %d, set to origin\n",i);
575 size_t sz =
sizeof(double);
601 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1)
612 int *clusters =
gv_calloc(nnodes,
sizeof(
int));
620 &nc, &clusters, &modularity);
623 &nc, &clusters, &modularity);
627 for (i = 0; i < nnodes; i++) (clusters)[i]++;
633 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_text(Agraph_t *g, int kind, char *name, const char *value)
creates or looks up text 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