gui/graph_displayer_canvas-node.cc
changeset 1536 308150155bb5
parent 1512 e54392395480
child 1579 ed7da82bbecf
equal deleted inserted replaced
0:215fe8796d19 1:ccb06be01f23
     3 #include <math.h>
     3 #include <math.h>
     4 
     4 
     5 
     5 
     6 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
     6 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
     7 {
     7 {
       
     8   Graph::NodeMap<double> * actual_map;
       
     9   if(mapname=="Default")
       
    10     {
       
    11       actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
       
    12     }
       
    13   else
       
    14     {
       
    15       actual_map=(mapstorage.nodemap_storage)[mapname];
       
    16     }
       
    17 
     8   if(node==INVALID)
    18   if(node==INVALID)
     9     {
    19     {
    10       for (NodeIt i(g); i!=INVALID; ++i)
    20       for (NodeIt i(g); i!=INVALID; ++i)
    11 	{
    21 	{
    12 	  int w=(int)(*(mapstorage.nodemap_storage)[mapname])[i];
    22 	  int w=(int)(*actual_map)[i];
    13 	  if(w>=0)
    23 	  if(w>=0)
    14 	    {
    24 	    {
    15 	      double x1, y1, x2, y2;
    25 	      double x1, y1, x2, y2;
    16 	      nodesmap[i]->get_bounds(x1, y1, x2, y2);
    26 	      x1=nodesmap[i]->property_x1().get_value();
       
    27 	      x2=nodesmap[i]->property_x2().get_value();
       
    28 	      y1=nodesmap[i]->property_y1().get_value();
       
    29 	      y2=nodesmap[i]->property_y2().get_value();
    17 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    30 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    18 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    31 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    19 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    32 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    20 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    33 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    21 	    }
    34 	    }
    22 	}
    35 	}
    23     }
    36     }
    24   else
    37   else
    25     {
    38     {
    26       int w=(int)(*(mapstorage.nodemap_storage)[mapname])[node];
    39       //I think only new nodes use this case
       
    40 //       int w=(int)(*actual_map)[node];
       
    41       int w=(int)(node_property_defaults[N_RADIUS]);
    27       if(w>=0)
    42       if(w>=0)
    28 	{
    43 	{
    29 	  double x1, y1, x2, y2;
    44 	  double x1, y1, x2, y2;
    30 	  nodesmap[node]->get_bounds(x1, y1, x2, y2);
    45 	  x1=nodesmap[node]->property_x1().get_value();
       
    46 	  x2=nodesmap[node]->property_x2().get_value();
       
    47 	  y1=nodesmap[node]->property_y1().get_value();
       
    48 	  y2=nodesmap[node]->property_y2().get_value();
    31 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    49 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    32 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    50 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    33 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    51 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    34 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    52 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    35 	}
    53 	}
    42 
    60 
    43   //function maps the range of the maximum and
    61   //function maps the range of the maximum and
    44   //the minimum of the nodemap to the range of
    62   //the minimum of the nodemap to the range of
    45   //green in RGB
    63   //green in RGB
    46 
    64 
       
    65   Graph::NodeMap<double> * actual_map;
       
    66   if(mapname=="Default")
       
    67     {
       
    68       actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
       
    69     }
       
    70   else
       
    71     {
       
    72       actual_map=(mapstorage.nodemap_storage)[mapname];
       
    73     }
       
    74 
       
    75   double max, min;
       
    76 
       
    77   if(mapname!="Default")
       
    78     {
       
    79       max=mapstorage.maxOfNodeMap(mapname);
       
    80       min=mapstorage.minOfNodeMap(mapname);
       
    81     }
       
    82   else
       
    83     {
       
    84       max=node_property_defaults[N_COLOR];
       
    85       min=node_property_defaults[N_COLOR];
       
    86     }
       
    87 
       
    88 
    47   if(node==INVALID)
    89   if(node==INVALID)
    48     {
    90     {
    49 
    91 
    50       for (NodeIt i(g); i!=INVALID; ++i)
    92       for (NodeIt i(g); i!=INVALID; ++i)
    51 	{
    93 	{
    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;
    94 	  Gdk::Color color;
       
    95 
       
    96 	  double w=(*actual_map)[i];
       
    97 
    58 	  if(max!=min)
    98 	  if(max!=min)
    59 	    {
    99 	    {
    60 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   100 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    61 	    }
   101 	    }
    62 	  else
   102 	  else
    67 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   107 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
    68 	}
   108 	}
    69     }
   109     }
    70   else
   110   else
    71     {
   111     {
    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;
   112       Gdk::Color color;
       
   113 
       
   114       double w=(*actual_map)[node];
       
   115 
    78       if(max!=min)
   116       if(max!=min)
    79 	{
   117 	{
    80 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   118 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
    81 	}
   119 	}
    82       else
   120       else
    94 
   132 
    95   //the number in the map will be written on the node
   133   //the number in the map will be written on the node
    96   //EXCEPT when the name of the map is Text, because
   134   //EXCEPT when the name of the map is Text, because
    97   //in that case empty string will be written, because
   135   //in that case empty string will be written, because
    98   //that is the deleter map
   136   //that is the deleter map
    99   //\todo isn't it a bit woodcutter?
   137 
       
   138   Graph::NodeMap<double> * actual_map;
       
   139   if(mapname=="Default")
       
   140     {
       
   141       actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
       
   142     }
       
   143   else
       
   144     {
       
   145       actual_map=(mapstorage.nodemap_storage)[mapname];
       
   146     }
   100 
   147 
   101   if(node==INVALID)
   148   if(node==INVALID)
   102     {
   149     {
   103       for (NodeIt i(g); i!=INVALID; ++i)
   150       for (NodeIt i(g); i!=INVALID; ++i)
   104 	{
   151 	{
   105 	  if(mapname!=node_property_strings[N_TEXT])
   152 	  if(mapname!="Default")
   106 	    {
   153 	    {
   107 	      double number=(*(mapstorage.nodemap_storage)[mapname])[i];
   154 	      double number=(*actual_map)[i];
   108 	      int length=1;
   155 	      int length=1;
   109 	      //if number is smaller than one, length would be negative, or invalid
   156 	      //if number is smaller than one, length would be negative, or invalid
   110 	      if(number>=1)
   157 	      if(number>=1)
   111 		{
   158 		{
   112 		  length=(int)(floor(log(number)/log(10)))+1;
   159 		  length=(int)(floor(log(number)/log(10)))+1;
   136 	    }
   183 	    }
   137 	}
   184 	}
   138     }
   185     }
   139   else
   186   else
   140     {
   187     {
   141       if(mapname!=node_property_strings[N_TEXT])
   188       if(mapname!="Default")
   142 	{
   189 	{
   143 	  double number=(*(mapstorage.nodemap_storage)[mapname])[node];
   190 	  double number=(*actual_map)[node];
   144 	  int length=1;
   191 	  int length=1;
   145 	  //if number is smaller than one, length would be negative, or invalid
   192 	  //if number is smaller than one, length would be negative, or invalid
   146 	  if(number>=1)
   193 	  if(number>=1)
   147 	    {
   194 	    {
   148 	      length=(int)(floor(log(number)/log(10)))+1;
   195 	      length=(int)(floor(log(number)/log(10)))+1;