graph_displayer_canvas-node.cc
branchgui
changeset 81 5ad61c33487c
parent 62 80eefca04b1e
child 89 4042761b21e3
     1.1 --- a/graph_displayer_canvas-node.cc	Thu Oct 06 12:32:06 2005 +0000
     1.2 +++ b/graph_displayer_canvas-node.cc	Thu Oct 20 15:50:23 2005 +0000
     1.3 @@ -7,19 +7,67 @@
     1.4  {
     1.5    Graph::NodeMap<double> * actual_map;
     1.6    double min, max;
     1.7 -  if(mapname=="Default")
     1.8 +  min=mapstorage.minOfNodeMap(mapname);
     1.9 +  max=mapstorage.maxOfNodeMap(mapname);
    1.10 +  actual_map=(mapstorage.nodemap_storage)[mapname];
    1.11 +
    1.12 +  if(node==INVALID)
    1.13      {
    1.14 -      min=node_property_defaults[N_RADIUS];
    1.15 -      max=node_property_defaults[N_RADIUS];
    1.16 -      actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
    1.17 +      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    1.18 +	{
    1.19 +	  double v=fabs((*actual_map)[i]);
    1.20 +	  int w;
    1.21 +	  if(min==max)
    1.22 +	    {
    1.23 +	      w=(int)(node_property_defaults[N_RADIUS]);
    1.24 +	    }
    1.25 +	  else
    1.26 +	    {
    1.27 +	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
    1.28 +	    }
    1.29 +	  if(w>=0)
    1.30 +	    {
    1.31 +	      double x1, y1, x2, y2;
    1.32 +	      x1=nodesmap[i]->property_x1().get_value();
    1.33 +	      x2=nodesmap[i]->property_x2().get_value();
    1.34 +	      y1=nodesmap[i]->property_y1().get_value();
    1.35 +	      y2=nodesmap[i]->property_y2().get_value();
    1.36 +	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    1.37 +	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    1.38 +	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    1.39 +	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    1.40 +	    }
    1.41 +	}
    1.42      }
    1.43    else
    1.44      {
    1.45 -      min=mapstorage.minOfNodeMap(mapname);
    1.46 -      max=mapstorage.maxOfNodeMap(mapname);
    1.47 -      actual_map=(mapstorage.nodemap_storage)[mapname];
    1.48 +      //I think only new nodes use this case
    1.49 +//       int w=(int)(*actual_map)[node];
    1.50 +      int w=(int)(node_property_defaults[N_RADIUS]);
    1.51 +      if(w>=0)
    1.52 +	{
    1.53 +	  double x1, y1, x2, y2;
    1.54 +	  x1=nodesmap[node]->property_x1().get_value();
    1.55 +	  x2=nodesmap[node]->property_x2().get_value();
    1.56 +	  y1=nodesmap[node]->property_y1().get_value();
    1.57 +	  y2=nodesmap[node]->property_y2().get_value();
    1.58 +	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    1.59 +	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    1.60 +	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    1.61 +	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    1.62 +	}
    1.63      }
    1.64 +  return 0;
    1.65 +};
    1.66  
    1.67 +int GraphDisplayerCanvas::resetNodeRadius (Node node)
    1.68 +{
    1.69 +  Graph::NodeMap<double> * actual_map;
    1.70 +  double min, max;
    1.71 +  min=node_property_defaults[N_RADIUS];
    1.72 +  max=node_property_defaults[N_RADIUS];
    1.73 +  actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
    1.74 +  
    1.75    if(node==INVALID)
    1.76      {
    1.77        for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    1.78 @@ -77,28 +125,68 @@
    1.79    //green in RGB
    1.80  
    1.81    Graph::NodeMap<double> * actual_map;
    1.82 -  if(mapname=="Default")
    1.83 +  actual_map=(mapstorage.nodemap_storage)[mapname];
    1.84 +
    1.85 +  double max, min;
    1.86 +
    1.87 +  max=mapstorage.maxOfNodeMap(mapname);
    1.88 +  min=mapstorage.minOfNodeMap(mapname);
    1.89 +
    1.90 +  if(node==INVALID)
    1.91      {
    1.92 -      actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
    1.93 +
    1.94 +      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    1.95 +	{
    1.96 +	  Gdk::Color color;
    1.97 +
    1.98 +	  double w=(*actual_map)[i];
    1.99 +
   1.100 +	  if(max!=min)
   1.101 +	    {
   1.102 +	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   1.103 +	    }
   1.104 +	  else
   1.105 +	    {
   1.106 +	      color.set_rgb_p (0, 0, 100);
   1.107 +	    }
   1.108 +
   1.109 +	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   1.110 +	}
   1.111      }
   1.112    else
   1.113      {
   1.114 -      actual_map=(mapstorage.nodemap_storage)[mapname];
   1.115 +      Gdk::Color color;
   1.116 +
   1.117 +      double w=(*actual_map)[node];
   1.118 +
   1.119 +      if(max!=min)
   1.120 +	{
   1.121 +	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   1.122 +	}
   1.123 +      else
   1.124 +	{
   1.125 +	  color.set_rgb_p (0, 0, 100);
   1.126 +	}
   1.127 +
   1.128 +      nodesmap[node]->property_fill_color_gdk().set_value(color);
   1.129      }
   1.130 +  return 0;
   1.131 +};
   1.132 +
   1.133 +int GraphDisplayerCanvas::resetNodeColor (Node node)
   1.134 +{  
   1.135 +
   1.136 +  //function maps the range of the maximum and
   1.137 +  //the minimum of the nodemap to the range of
   1.138 +  //green in RGB
   1.139 +
   1.140 +  Graph::NodeMap<double> * actual_map;
   1.141 +  actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
   1.142  
   1.143    double max, min;
   1.144  
   1.145 -  if(mapname!="Default")
   1.146 -    {
   1.147 -      max=mapstorage.maxOfNodeMap(mapname);
   1.148 -      min=mapstorage.minOfNodeMap(mapname);
   1.149 -    }
   1.150 -  else
   1.151 -    {
   1.152 -      max=node_property_defaults[N_COLOR];
   1.153 -      min=node_property_defaults[N_COLOR];
   1.154 -    }
   1.155 -
   1.156 +  max=node_property_defaults[N_COLOR];
   1.157 +  min=node_property_defaults[N_COLOR];
   1.158  
   1.159    if(node==INVALID)
   1.160      {
   1.161 @@ -150,47 +238,52 @@
   1.162    //that is the deleter map
   1.163  
   1.164    Graph::NodeMap<double> * actual_map=NULL;
   1.165 -  if(mapname!="Default")
   1.166 -    {
   1.167 -      actual_map=(mapstorage.nodemap_storage)[mapname];
   1.168 -    }
   1.169 +  actual_map=(mapstorage.nodemap_storage)[mapname];
   1.170  
   1.171    if(node==INVALID)
   1.172      {
   1.173        for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   1.174  	{
   1.175 -	  if(mapname!="Default")
   1.176 -	    {
   1.177 -	      nodemap_to_edit=mapname;
   1.178 -	      double number=(*actual_map)[i];
   1.179 +	  nodemap_to_edit=mapname;
   1.180 +	  double number=(*actual_map)[i];
   1.181  
   1.182 -	      std::ostringstream ostr;
   1.183 -	      ostr << number;
   1.184 +	  std::ostringstream ostr;
   1.185 +	  ostr << number;
   1.186  	      
   1.187 -      	      nodetextmap[i]->property_text().set_value(ostr.str());
   1.188 -	    }
   1.189 -	  else
   1.190 -	    {
   1.191 -	      nodemap_to_edit="";
   1.192 -	      nodetextmap[i]->property_text().set_value("");
   1.193 -	    }
   1.194 +	  nodetextmap[i]->property_text().set_value(ostr.str());
   1.195  	}
   1.196      }
   1.197    else
   1.198      {
   1.199 -      if(mapname!="Default")
   1.200 -	{
   1.201 -	  double number=(*actual_map)[node];
   1.202 +      double number=(*actual_map)[node];
   1.203  
   1.204 -	  std::ostringstream ostr;
   1.205 -	  ostr << number;
   1.206 +      std::ostringstream ostr;
   1.207 +      ostr << number;
   1.208  	      
   1.209 -	  nodetextmap[node]->property_text().set_value(ostr.str());
   1.210 -	}
   1.211 -      else
   1.212 -	{
   1.213 -	  nodetextmap[node]->property_text().set_value("");
   1.214 -	}
   1.215 +      nodetextmap[node]->property_text().set_value(ostr.str());
   1.216      }
   1.217    return 0;
   1.218  };
   1.219 +
   1.220 +int GraphDisplayerCanvas::resetNodeText (Node node)
   1.221 +{
   1.222 +
   1.223 +  //the number in the map will be written on the node
   1.224 +  //EXCEPT when the name of the map is Text, because
   1.225 +  //in that case empty string will be written, because
   1.226 +  //that is the deleter map
   1.227 +
   1.228 +  if(node==INVALID)
   1.229 +    {
   1.230 +      for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   1.231 +	{
   1.232 +	  nodemap_to_edit="";
   1.233 +	  nodetextmap[i]->property_text().set_value("");
   1.234 +	}
   1.235 +    }
   1.236 +  else
   1.237 +    {
   1.238 +      nodetextmap[node]->property_text().set_value("");
   1.239 +    }
   1.240 +  return 0;
   1.241 +};