gui/graph_displayer_canvas-node.cc
author hegyi
Fri, 24 Jun 2005 18:16:12 +0000
changeset 1512 e54392395480
child 1525 6d94de269ab1
permissions -rwxr-xr-x
NodeMap values are now visualizable. Todo: default map-values
     1 #include <graph_displayer_canvas.h>
     2 #include <broken_edge.h>
     3 #include <math.h>
     4 
     5 
     6 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
     7 {
     8   if(node==INVALID)
     9     {
    10       for (NodeIt i(g); i!=INVALID; ++i)
    11 	{
    12 	  int w=(int)(*(mapstorage.nodemap_storage)[mapname])[i];
    13 	  if(w>=0)
    14 	    {
    15 	      double x1, y1, x2, y2;
    16 	      nodesmap[i]->get_bounds(x1, y1, x2, y2);
    17 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    18 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    19 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    20 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    21 	    }
    22 	}
    23     }
    24   else
    25     {
    26       int w=(int)(*(mapstorage.nodemap_storage)[mapname])[node];
    27       if(w>=0)
    28 	{
    29 	  double x1, y1, x2, y2;
    30 	  nodesmap[node]->get_bounds(x1, y1, x2, y2);
    31 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    32 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    33 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    34 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    35 	}
    36     }
    37   return 0;
    38 };
    39 
    40 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
    41 {  
    42 
    43   //function maps the range of the maximum and
    44   //the minimum of the nodemap to the range of
    45   //green in RGB
    46 
    47   if(node==INVALID)
    48     {
    49 
    50       for (NodeIt i(g); i!=INVALID; ++i)
    51 	{
    52 	  double w=(*(mapstorage.nodemap_storage)[mapname])[i];
    53 	  double max=mapstorage.maxOfNodeMap(mapname);
    54 	  double min=mapstorage.minOfNodeMap(mapname);
    55       
    56 	  //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    57 	  Gdk::Color color;
    58 	  if(max!=min)
    59 	    {
    60 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    61 	    }
    62 	  else
    63 	    {
    64 	      color.set_rgb_p (0, 0, 100);
    65 	    }
    66 
    67 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
    68 	}
    69     }
    70   else
    71     {
    72       double w=(*(mapstorage.nodemap_storage)[mapname])[node];
    73       double max=mapstorage.maxOfNodeMap(mapname);
    74       double min=mapstorage.minOfNodeMap(mapname);
    75       
    76       //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    77       Gdk::Color color;
    78       if(max!=min)
    79 	{
    80 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    81 	}
    82       else
    83 	{
    84 	  color.set_rgb_p (0, 0, 100);
    85 	}
    86 
    87       nodesmap[node]->property_fill_color_gdk().set_value(color);
    88     }
    89   return 0;
    90 };
    91 
    92 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
    93 {
    94 
    95   //the number in the map will be written on the node
    96   //EXCEPT when the name of the map is Text, because
    97   //in that case empty string will be written, because
    98   //that is the deleter map
    99   //\todo isn't it a bit woodcutter?
   100 
   101   if(node==INVALID)
   102     {
   103       for (NodeIt i(g); i!=INVALID; ++i)
   104 	{
   105 	  if(mapname!=node_property_strings[N_TEXT])
   106 	    {
   107 	      double number=(*(mapstorage.nodemap_storage)[mapname])[i];
   108 	      int length=1;
   109 	      //if number is smaller than one, length would be negative, or invalid
   110 	      if(number>=1)
   111 		{
   112 		  length=(int)(floor(log(number)/log(10)))+1;
   113 		}
   114 	      int maxpos=(int)(pow(10,length-1));
   115 	      int strl=length+1+RANGE;
   116 	      char * str=new char[strl];
   117 	      str[length]='.';
   118 	      str[strl]='\0';
   119       
   120 	      for(int j=0;j<strl;j++)
   121 		{
   122 		  if(j!=length)
   123 		    {
   124 		      int digit=(int)(number/maxpos);
   125 		      str[j]=(digit+'0');
   126 		      number-=digit*maxpos;
   127 		      number*=10;
   128 		    }
   129 		}
   130       
   131 	      nodetextmap[i]->property_text().set_value(str);
   132 	    }
   133 	  else
   134 	    {
   135 	      nodetextmap[i]->property_text().set_value("");
   136 	    }
   137 	}
   138     }
   139   else
   140     {
   141       if(mapname!=node_property_strings[N_TEXT])
   142 	{
   143 	  double number=(*(mapstorage.nodemap_storage)[mapname])[node];
   144 	  int length=1;
   145 	  //if number is smaller than one, length would be negative, or invalid
   146 	  if(number>=1)
   147 	    {
   148 	      length=(int)(floor(log(number)/log(10)))+1;
   149 	    }
   150 	  int maxpos=(int)(pow(10,length-1));
   151 	  int strl=length+1+RANGE;
   152 	  char * str=new char[strl];
   153 	  str[length]='.';
   154 	  str[strl]='\0';
   155       
   156 	  for(int j=0;j<strl;j++)
   157 	    {
   158 	      if(j!=length)
   159 		{
   160 		  int digit=(int)(number/maxpos);
   161 		  str[j]=(digit+'0');
   162 		  number-=digit*maxpos;
   163 		  number*=10;
   164 		}
   165 	    }
   166       
   167 	  nodetextmap[node]->property_text().set_value(str);
   168 	}
   169       else
   170 	{
   171 	  nodetextmap[node]->property_text().set_value("");
   172 	}
   173     }
   174   return 0;
   175 };