33#define ND_id(n) (((Agnodeinfo_t*)((n)->base.data))->id)
37 fprintf(stderr,
"can only 1, 2 or 3 dimensional color space. with color value between 0 to 1\n");
42 MIN((
unsigned int) (
color[1]*255), 255),
MIN((
unsigned int)(
color[2]*255), 255));
45 MIN((
unsigned int) (
color[0]*255), 255),
MIN((
unsigned int)(
color[0]*255), 255));
48 0,
MIN((
unsigned int)(
color[1]*255), 255));
69 if (
row == col)
continue;
102 fprintf (stderr,
"Format %d not supported\n",
format);
133 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1) v = 1;
144 bool has_positions =
true;
153 if ((pval =
agxget(n, psym)) && *pval) {
155 nitems = sscanf(pval,
"%lf,%lf", &xx, &yy);
157 has_positions =
false;
162 }
else if (
dim == 3){
163 nitems = sscanf(pval,
"%lf,%lf,%lf", &xx, &yy, &zz);
165 has_positions =
false;
171 }
else if (
dim == 4){
172 nitems = sscanf(pval,
"%lf,%lf,%lf,%lf", &xx, &yy, &zz,&ww);
174 has_positions =
false;
181 }
else if (
dim == 1){
182 nitems = sscanf(pval,
"%lf", &xx);
193 has_positions =
false;
197 if (!has_positions) {
205 size_t sz =
sizeof(double);
254 char *pos =
agxget (e, sym);
255 (*xsplines)[i] = strdup(pos);
263 if (h >=
'0' && h <=
'9')
return h -
'0';
264 if (h >=
'a' && h <=
'f')
return 10 + h -
'a';
265 if (h >=
'A' && h <=
'F')
return 10 + h -
'A';
280 if (!clust_clr_sym) clust_clr_sym =
agattr_text(g,
AGNODE,
"clustercolor",
"-1");
283 if (rgb_r && rgb_g && rgb_b) {
284 rgb2hex(rgb_r[clusters[i]], rgb_g[clusters[i]], rgb_b[clusters[i]],
292SparseMatrix 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){
301 int i,
row, ic,nc, j;
306 int MAX_GRPS, MIN_GRPS;
307 bool noclusterinfo =
false;
312 switch (default_color_scheme){
377 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1)
387 val,
type,
sizeof(
double));
390 *clusters =
gv_calloc(nnodes,
sizeof(
int));
399 memset (*clusters, 0,
sizeof(
int)*nnodes);
406 fprintf (stderr,
"Warning: node %s appears in multiple clusters.\n",
agnameof(n));
408 (*clusters)[i] = gid;
413 if ((*clusters)[i] == 0)
419 else if (clust_sym) {
422 if ((sscanf(
agxget(n,clust_sym),
"%d", &ic)>0)) {
429 MIN_GRPS =
MIN(MIN_GRPS, ic);
432 noclusterinfo =
true;
438 noclusterinfo =
true;
447 &nc, clusters, &modularity);
450 &nc, clusters, &modularity);
454 for (i = 0; i < nnodes; i++) (*clusters)[i]++;
462 fprintf(stderr,
" no complement clustering info in dot file, using modularity clustering. Modularity = %f, ncluster=%d\n",modularity, nc);
467 if (pal || (!noclusterinfo && clust_clr_sym)){
468 *rgb_r =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
469 *rgb_g =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
470 *rgb_b =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
477 *labels =
gv_calloc(nnodes,
sizeof(
char*));
484 sscanf(
agget(n,
"width"),
"%lf", &sz);
485 (*label_sizes)[i*2] =
POINTS(sz*0.5);
486 sscanf(
agget(n,
"height"),
"%lf", &sz);
487 (*label_sizes)[i*2+1] =
POINTS(sz*0.5);
489 (*label_sizes)[i*2] =
POINTS(0.75/2);
490 (*label_sizes)[i*2+1] =
POINTS(0.5*2);
493 if (
agget(n,
"fontsize")){
494 sscanf(
agget(n,
"fontsize"),
"%f", &ff);
500 if (
agget(n,
"label") && strcmp(
agget(n,
"label"),
"") != 0 && strcmp(
agget(n,
"label"),
"\\N") != 0){
501 char *lbs =
agget(n,
"label");
502 (*labels)[i] = strdup(lbs);
510 if (MAX_GRPS-MIN_GRPS < max_color) {
511 j = (j-MIN_GRPS)*((
int)((max_color-1)/
MAX((MAX_GRPS-MIN_GRPS),1)));
513 j = (j-MIN_GRPS)%max_color;
517 (*rgb_r)[(*clusters)[i]] = pal[3*j+0];
518 (*rgb_g)[(*clusters)[i]] = pal[3*j+1];
519 (*rgb_b)[(*clusters)[i]] = pal[3*j+2];
523 (*rgb_r)[(*clusters)[i]] =
color.u.RGBA[0];
524 (*rgb_g)[(*clusters)[i]] =
color.u.RGBA[1];
525 (*rgb_b)[(*clusters)[i]] =
color.u.RGBA[2];
528 const char *cc =
agget(n,
"clustercolor");
529 if (!noclusterinfo &&
agget(n,
"cluster") && cc && strlen(cc) >= 7 && pal) {
539 bool has_position =
false;
544 if (
agget(n,
"pos")){
546 sscanf(
agget(n,
"pos"),
"%lf,%lf", &xx, &yy);
550 fprintf(stderr,
"WARNING: pos field missing for node %d, set to origin\n",i);
579 size_t sz =
sizeof(double);
605 if (sscanf (
agxget(e,sym),
"%lf", &v) != 1)
617 int *clusters =
gv_calloc(nnodes,
sizeof(
int));
625 &nc, &clusters, &modularity);
628 &nc, &clusters, &modularity);
632 for (i = 0; i < nnodes; i++) (clusters)[i]++;
638 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(size_t nz, int m, int n, int *irn, int *jcn, const void *val, int type, size_t sz)
void SparseMatrix_delete(SparseMatrix A)
SparseMatrix SparseMatrix_new(int m, int n, size_t nz, int type, int format)
Dynamically expanding string buffers.
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