gui/graph_displayer_canvas-node.cc
changeset 1512 e54392395480
child 1525 6d94de269ab1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/graph_displayer_canvas-node.cc	Fri Jun 24 18:16:12 2005 +0000
     1.3 @@ -0,0 +1,175 @@
     1.4 +#include <graph_displayer_canvas.h>
     1.5 +#include <broken_edge.h>
     1.6 +#include <math.h>
     1.7 +
     1.8 +
     1.9 +int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
    1.10 +{
    1.11 +  if(node==INVALID)
    1.12 +    {
    1.13 +      for (NodeIt i(g); i!=INVALID; ++i)
    1.14 +	{
    1.15 +	  int w=(int)(*(mapstorage.nodemap_storage)[mapname])[i];
    1.16 +	  if(w>=0)
    1.17 +	    {
    1.18 +	      double x1, y1, x2, y2;
    1.19 +	      nodesmap[i]->get_bounds(x1, y1, x2, y2);
    1.20 +	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    1.21 +	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    1.22 +	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    1.23 +	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    1.24 +	    }
    1.25 +	}
    1.26 +    }
    1.27 +  else
    1.28 +    {
    1.29 +      int w=(int)(*(mapstorage.nodemap_storage)[mapname])[node];
    1.30 +      if(w>=0)
    1.31 +	{
    1.32 +	  double x1, y1, x2, y2;
    1.33 +	  nodesmap[node]->get_bounds(x1, y1, x2, y2);
    1.34 +	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    1.35 +	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    1.36 +	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    1.37 +	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    1.38 +	}
    1.39 +    }
    1.40 +  return 0;
    1.41 +};
    1.42 +
    1.43 +int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
    1.44 +{  
    1.45 +
    1.46 +  //function maps the range of the maximum and
    1.47 +  //the minimum of the nodemap to the range of
    1.48 +  //green in RGB
    1.49 +
    1.50 +  if(node==INVALID)
    1.51 +    {
    1.52 +
    1.53 +      for (NodeIt i(g); i!=INVALID; ++i)
    1.54 +	{
    1.55 +	  double w=(*(mapstorage.nodemap_storage)[mapname])[i];
    1.56 +	  double max=mapstorage.maxOfNodeMap(mapname);
    1.57 +	  double min=mapstorage.minOfNodeMap(mapname);
    1.58 +      
    1.59 +	  //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    1.60 +	  Gdk::Color color;
    1.61 +	  if(max!=min)
    1.62 +	    {
    1.63 +	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    1.64 +	    }
    1.65 +	  else
    1.66 +	    {
    1.67 +	      color.set_rgb_p (0, 0, 100);
    1.68 +	    }
    1.69 +
    1.70 +	  nodesmap[i]->property_fill_color_gdk().set_value(color);
    1.71 +	}
    1.72 +    }
    1.73 +  else
    1.74 +    {
    1.75 +      double w=(*(mapstorage.nodemap_storage)[mapname])[node];
    1.76 +      double max=mapstorage.maxOfNodeMap(mapname);
    1.77 +      double min=mapstorage.minOfNodeMap(mapname);
    1.78 +      
    1.79 +      //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
    1.80 +      Gdk::Color color;
    1.81 +      if(max!=min)
    1.82 +	{
    1.83 +	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    1.84 +	}
    1.85 +      else
    1.86 +	{
    1.87 +	  color.set_rgb_p (0, 0, 100);
    1.88 +	}
    1.89 +
    1.90 +      nodesmap[node]->property_fill_color_gdk().set_value(color);
    1.91 +    }
    1.92 +  return 0;
    1.93 +};
    1.94 +
    1.95 +int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
    1.96 +{
    1.97 +
    1.98 +  //the number in the map will be written on the node
    1.99 +  //EXCEPT when the name of the map is Text, because
   1.100 +  //in that case empty string will be written, because
   1.101 +  //that is the deleter map
   1.102 +  //\todo isn't it a bit woodcutter?
   1.103 +
   1.104 +  if(node==INVALID)
   1.105 +    {
   1.106 +      for (NodeIt i(g); i!=INVALID; ++i)
   1.107 +	{
   1.108 +	  if(mapname!=node_property_strings[N_TEXT])
   1.109 +	    {
   1.110 +	      double number=(*(mapstorage.nodemap_storage)[mapname])[i];
   1.111 +	      int length=1;
   1.112 +	      //if number is smaller than one, length would be negative, or invalid
   1.113 +	      if(number>=1)
   1.114 +		{
   1.115 +		  length=(int)(floor(log(number)/log(10)))+1;
   1.116 +		}
   1.117 +	      int maxpos=(int)(pow(10,length-1));
   1.118 +	      int strl=length+1+RANGE;
   1.119 +	      char * str=new char[strl];
   1.120 +	      str[length]='.';
   1.121 +	      str[strl]='\0';
   1.122 +      
   1.123 +	      for(int j=0;j<strl;j++)
   1.124 +		{
   1.125 +		  if(j!=length)
   1.126 +		    {
   1.127 +		      int digit=(int)(number/maxpos);
   1.128 +		      str[j]=(digit+'0');
   1.129 +		      number-=digit*maxpos;
   1.130 +		      number*=10;
   1.131 +		    }
   1.132 +		}
   1.133 +      
   1.134 +	      nodetextmap[i]->property_text().set_value(str);
   1.135 +	    }
   1.136 +	  else
   1.137 +	    {
   1.138 +	      nodetextmap[i]->property_text().set_value("");
   1.139 +	    }
   1.140 +	}
   1.141 +    }
   1.142 +  else
   1.143 +    {
   1.144 +      if(mapname!=node_property_strings[N_TEXT])
   1.145 +	{
   1.146 +	  double number=(*(mapstorage.nodemap_storage)[mapname])[node];
   1.147 +	  int length=1;
   1.148 +	  //if number is smaller than one, length would be negative, or invalid
   1.149 +	  if(number>=1)
   1.150 +	    {
   1.151 +	      length=(int)(floor(log(number)/log(10)))+1;
   1.152 +	    }
   1.153 +	  int maxpos=(int)(pow(10,length-1));
   1.154 +	  int strl=length+1+RANGE;
   1.155 +	  char * str=new char[strl];
   1.156 +	  str[length]='.';
   1.157 +	  str[strl]='\0';
   1.158 +      
   1.159 +	  for(int j=0;j<strl;j++)
   1.160 +	    {
   1.161 +	      if(j!=length)
   1.162 +		{
   1.163 +		  int digit=(int)(number/maxpos);
   1.164 +		  str[j]=(digit+'0');
   1.165 +		  number-=digit*maxpos;
   1.166 +		  number*=10;
   1.167 +		}
   1.168 +	    }
   1.169 +      
   1.170 +	  nodetextmap[node]->property_text().set_value(str);
   1.171 +	}
   1.172 +      else
   1.173 +	{
   1.174 +	  nodetextmap[node]->property_text().set_value("");
   1.175 +	}
   1.176 +    }
   1.177 +  return 0;
   1.178 +};