Permalink
Browse files

Take a better approach to scaling using normalized (log(x)) formula. (#…

…46)

* Resolves #45 
* Resolves #25 
* Add conditional on the case that max degree & min degree are equal.
* Switch to regular degree instead of log when the maximum and minimum
node sizes are equal (i.e. a complete graph).
* Add one to degree for the case where all node degrees are equal to zero.
  • Loading branch information...
greebie authored and ruebot committed Sep 2, 2018
1 parent 03652ec commit ceda07c0d413f774243e77e8f59e86522bbd3d54
Showing with 11 additions and 9 deletions.
  1. +10 −8 src/viz.c
  2. +1 −1 tests/quickrun_test.c
View
@@ -155,16 +155,18 @@ extern int layout_graph(igraph_t *graph, char layout) {
extern int set_size(igraph_t *graph, igraph_vector_t *v, int max) {
long int gsize = (long int)igraph_vcount(graph);
igraph_vector_t v2;
igraph_vector_t min;
igraph_vector_t logOf;
igraph_vector_init(&logOf, gsize);
double scale;
igraph_vector_copy(&v2, v);
igraph_vector_init(&min, gsize);
igraph_vector_fill(&min, igraph_vector_min(&v2));
igraph_vector_sub(&v2, &min);
scale = log10(gsize / (igraph_vector_max(&v2) - igraph_vector_min(&v2)));
igraph_vector_scale(&v2, scale);
SETVANV(graph, "size", &v2);
for (long int i=0; i<gsize; i++){
double val = log(VECTOR(v2)[i] + 1);
double minimum = log(igraph_vector_min(&v2) + 1);
double maximum = log(igraph_vector_max(&v2) + 1);
VECTOR(logOf)[i] = maximum == minimum ? (VECTOR(v2)[i] + 1) : (max * (val - minimum) / (maximum - minimum));
}
SETVANV(graph, "size", &logOf);
igraph_vector_destroy(&logOf);
igraph_vector_destroy(&v2);
igraph_vector_destroy(&min);
return 0;
}
View
@@ -64,7 +64,7 @@ void TEST_QUICKRUN_COLOR() {
void TEST_QUICKRUN_SIZE() {
quickrunGraph();
igraph_vector_t size;
igraph_vector_init(&size, 0);
igraph_vector_init(&size, 0.0);
VANV(&g, "size", &size);
TEST_ASSERT_EQUAL_FLOAT(VECTOR(size)[0], 0.0);
TEST_ASSERT_EQUAL_FLOAT(VECTOR(size)[10], 0.0);

0 comments on commit ceda07c

Please sign in to comment.