38#define ND_id(n) (((Agnodeinfo_t *)((n)->base.data))->id)
42 fprintf(stderr,
"can only 1, 2 or 3 dimensional color space. with color "
43 "value between 0 to 1\n");
48 MIN((
unsigned int)(
color[1] * 255), 255),
49 MIN((
unsigned int)(
color[2] * 255), 255));
50 }
else if (
dim == 1) {
52 MIN((
unsigned int)(
color[0] * 255), 255),
53 MIN((
unsigned int)(
color[0] * 255), 255));
54 }
else if (
dim == 2) {
56 MIN((
unsigned int)(
color[1] * 255), 255));
135 if (sscanf(
agxget(e, sym),
"%lf", &v) != 1)
147 bool has_positions =
true;
149 *x =
gv_calloc(DIM * nnodes,
sizeof(
double));
153 if ((pval =
agxget(n, psym)) && *pval) {
154 const int nitems = sscanf(pval,
"%lf,%lf", &xx, &yy);
156 has_positions =
false;
160 (*x)[i * DIM + 1] = yy;
162 has_positions =
false;
166 if (!has_positions) {
173 size_t sz =
sizeof(double);
175 assert(nnodes <= INT_MAX);
223 char *pos =
agxget(e, sym);
224 (*xsplines)[i] = strdup(pos);
232 if (h >=
'0' && h <=
'9')
234 if (h >=
'a' && h <=
'f')
236 if (h >=
'A' && h <=
'F')
255 const int i =
ND_id(n);
256 if (rgb_r && rgb_g && rgb_b) {
257 rgb2hex(rgb_r[clusters[i]], rgb_g[clusters[i]], rgb_b[clusters[i]],
266 Agraph_t *g,
int maxcluster,
int dim,
int *nn,
double **label_sizes,
267 double **x,
int **clusters,
float **rgb_r,
float **rgb_g,
float **rgb_b,
268 float **fsz,
char ***labels,
int default_color_scheme,
278 int i,
row, ic, nc, j;
283 int MAX_GRPS, MIN_GRPS;
284 bool noclusterinfo =
false;
289 switch (default_color_scheme) {
355 if (sscanf(
agxget(e, sym),
"%lf", &v) != 1)
364 (
size_t)
nedges, (
size_t)nnodes, nnodes,
I, J, val,
type,
sizeof(
double));
367 *clusters =
gv_calloc(nnodes,
sizeof(
int));
377 memset(*clusters, 0,
sizeof(
int) * nnodes);
385 fprintf(stderr,
"Warning: node %s appears in multiple clusters.\n",
388 (*clusters)[i] = gid;
393 if ((*clusters)[i] == 0)
398 }
else if (clust_sym) {
401 if (sscanf(
agxget(n, clust_sym),
"%d", &ic) > 0) {
408 MIN_GRPS =
MIN(MIN_GRPS, ic);
411 noclusterinfo =
true;
416 noclusterinfo =
true;
431 for (i = 0; i < nnodes; i++)
441 " no complement clustering info in dot file, using modularity "
442 "clustering. Modularity = %f, ncluster=%d\n",
448 if (pal || (!noclusterinfo && clust_clr_sym)) {
449 *rgb_r =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
450 *rgb_g =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
451 *rgb_b =
gv_calloc(1 + MAX_GRPS,
sizeof(
float));
458 *labels =
gv_calloc(nnodes,
sizeof(
char *));
464 if (
agget(n,
"width") &&
agget(n,
"height")) {
465 sscanf(
agget(n,
"width"),
"%lf", &sz);
466 (*label_sizes)[i * 2] =
POINTS(sz * 0.5);
467 sscanf(
agget(n,
"height"),
"%lf", &sz);
468 (*label_sizes)[i * 2 + 1] =
POINTS(sz * 0.5);
470 (*label_sizes)[i * 2] =
POINTS(0.75 / 2);
471 (*label_sizes)[i * 2 + 1] =
POINTS(0.5 * 2);
474 if (
agget(n,
"fontsize")) {
475 sscanf(
agget(n,
"fontsize"),
"%f", &ff);
481 if (
agget(n,
"label") && strcmp(
agget(n,
"label"),
"") != 0 &&
482 strcmp(
agget(n,
"label"),
"\\N") != 0) {
483 char *lbs =
agget(n,
"label");
484 (*labels)[i] = strdup(lbs);
490 if (MAX_GRPS - MIN_GRPS < max_color) {
492 ((
int)((max_color - 1) /
MAX((MAX_GRPS - MIN_GRPS), 1)));
494 j = (j - MIN_GRPS) % max_color;
498 (*rgb_r)[(*clusters)[i]] = pal[3 * j + 0];
499 (*rgb_g)[(*clusters)[i]] = pal[3 * j + 1];
500 (*rgb_b)[(*clusters)[i]] = pal[3 * j + 2];
503 if (!noclusterinfo && clust_clr_sym &&
506 (*rgb_r)[(*clusters)[i]] = (float)
color.u.RGBA[0];
507 (*rgb_g)[(*clusters)[i]] = (float)
color.u.RGBA[1];
508 (*rgb_b)[(*clusters)[i]] = (float)
color.u.RGBA[2];
511 const char *cc =
agget(n,
"clustercolor");
512 if (!noclusterinfo &&
agget(n,
"cluster") && cc && strlen(cc) >= 7 && pal) {
513 (*rgb_r)[(*clusters)[i]] =
hexcol2rgb(cc + 1);
514 (*rgb_g)[(*clusters)[i]] =
hexcol2rgb(cc + 3);
515 (*rgb_b)[(*clusters)[i]] =
hexcol2rgb(cc + 5);
520 bool has_position =
false;
525 if (
agget(n,
"pos")) {
527 sscanf(
agget(n,
"pos"),
"%lf,%lf", &xx, &yy);
529 (*x)[i *
dim + 1] = yy;
531 fprintf(stderr,
"WARNING: pos field missing for node %d, set to origin\n",
534 (*x)[i *
dim + 1] = 0;
559 size_t sz =
sizeof(double);
586 if (sscanf(
agxget(e, sym),
"%lf", &v) != 1)
595 nnodes,
I, J, val,
type, sz);
597 int *clusters =
gv_calloc(nnodes,
sizeof(
int));
611 for (i = 0; i < nnodes; i++)
619 " no complement clustering info in dot file, using modularity "
620 "clustering. Modularity = %f, ncluster=%d\n",
static void color_string(agxbuf *buf, size_t dim, double *color)
void Dot_SetClusterColor(Agraph_t *g, float *rgb_r, float *rgb_g, float *rgb_b, int *clusters)
int getDotNodeID(Agnode_t *n)
SparseMatrix SparseMatrix_import_dot(Agraph_t *g, double **x, int format)
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, size_t dim, double *colors)
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_new(size_t m, int n, size_t nz, int type, int format)
SparseMatrix SparseMatrix_from_coordinate_arrays(size_t nz, size_t m, int n, int *irn, int *jcn, const void *val, int type, size_t sz)
void SparseMatrix_delete(SparseMatrix A)
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)
size_t agnnodes_z(const Agraph_t *g)
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)
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