gui/graph_displayer_canvas-edge.cc
author hegyi
Wed, 04 Jan 2006 11:41:58 +0000
changeset 1872 3b7694cf0a08
parent 1837 8dd6160ff699
permissions -rwxr-xr-x
Best feature ever\! Name of tabs are different from now on\!
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     3 
     4 
     5 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
     6 {
     7   double min, max;
     8 
     9   min=edge_property_defaults[E_WIDTH];
    10   max=edge_property_defaults[E_WIDTH];
    11   Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
    12   
    13   if(edge==INVALID)
    14     {
    15       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    16 	{
    17 	  double v=fabs(actual_map[i]);
    18 	  int w;
    19 	  if(min==max)
    20 	    {
    21 	      w=(int)(edge_property_defaults[E_WIDTH]);
    22 	    }
    23 	  else
    24 	    {
    25 	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
    26 	    }
    27 	  edgesmap[i]->property_width_units().set_value(w);
    28 	}
    29     }
    30   else
    31     {
    32       int w=(int)actual_map[edge];
    33       if(w>=0)
    34 	{
    35 	  edgesmap[edge]->property_width_units().set_value(w);
    36 	}
    37     }
    38   return 0;
    39 }
    40 
    41 
    42 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
    43 {
    44   Graph::EdgeMap<double> * actual_map;
    45   double min, max;
    46 
    47   min=(mytab.mapstorage).minOfEdgeMap(mapname);
    48   max=(mytab.mapstorage).maxOfEdgeMap(mapname);
    49   actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
    50 
    51   if(edge==INVALID)
    52     {
    53       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    54 	{
    55 	  double v=fabs((*actual_map)[i]);
    56 	  int w;
    57 	  if(min==max)
    58 	    {
    59 	      w=(int)(edge_property_defaults[E_WIDTH]);
    60 	    }
    61 	  else
    62 	    {
    63 	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
    64 	    }
    65 	  edgesmap[i]->property_width_units().set_value(w);
    66 	}
    67     }
    68   else
    69     {
    70       int w=(int)(*actual_map)[edge];
    71       if(w>=0)
    72 	{
    73 	  edgesmap[edge]->property_width_units().set_value(w);
    74 	}
    75     }
    76   return 0;
    77 };
    78 
    79 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
    80 {  
    81 
    82   //function maps the range of the maximum and
    83   //the minimum of the nodemap to the range of
    84   //green in RGB
    85   Graph::EdgeMap<double> * actual_map;
    86   actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
    87 
    88   double max, min;
    89 
    90   max=(mytab.mapstorage).maxOfEdgeMap(mapname);
    91   min=(mytab.mapstorage).minOfEdgeMap(mapname);
    92 
    93   if(edge==INVALID)
    94     {
    95       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    96 	{
    97 	  double w=(*actual_map)[i];
    98 
    99 	  Gdk::Color color;
   100 	  if(max!=min)
   101 	    {
   102 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   103 	    }
   104 	  else
   105 	    {
   106 	      color.set_rgb_p (0, 100, 0);
   107 	    }
   108 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
   109 	}
   110     }
   111   else
   112     {
   113       Gdk::Color color;
   114 
   115       double w=(*actual_map)[edge];
   116 
   117       if(max!=min)
   118 	{
   119 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   120 	}
   121       else
   122 	{
   123 	  color.set_rgb_p (0, 100, 0);
   124 	}
   125 
   126       edgesmap[edge]->property_fill_color_gdk().set_value(color);
   127     }
   128   return 0;
   129 };
   130 
   131 int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
   132 {  
   133 
   134   //function maps the range of the maximum and
   135   //the minimum of the nodemap to the range of
   136   //green in RGB
   137   Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
   138 
   139   double max, min;
   140 
   141   max=edge_property_defaults[E_COLOR];
   142   min=edge_property_defaults[E_COLOR];
   143 
   144   if(edge==INVALID)
   145     {
   146       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   147 	{
   148 	  double w=actual_map[i];
   149 
   150 	  Gdk::Color color;
   151 	  if(max!=min)
   152 	    {
   153 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   154 	    }
   155 	  else
   156 	    {
   157 	      color.set_rgb_p (0, 100, 0);
   158 	    }
   159 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
   160 	}
   161     }
   162   else
   163     {
   164       Gdk::Color color;
   165 
   166       double w=actual_map[edge];
   167 
   168       if(max!=min)
   169 	{
   170 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   171 	}
   172       else
   173 	{
   174 	  color.set_rgb_p (0, 100, 0);
   175 	}
   176 
   177       edgesmap[edge]->property_fill_color_gdk().set_value(color);
   178     }
   179   return 0;
   180 };
   181 
   182 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
   183 {
   184   //the number in the map will be written on the edge
   185   //EXCEPT when the name of the map is Default, because
   186   //in that case empty string will be written, because
   187   //that is the deleter map
   188   
   189   if(edge==INVALID)
   190     {
   191       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   192 	{
   193 	  edgemap_to_edit=mapname;
   194 	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
   195 	  
   196 	  std::ostringstream ostr;
   197 	  ostr << number;
   198 	  
   199 	  edgetextmap[i]->property_text().set_value(ostr.str());
   200 	}
   201 
   202     }
   203   else
   204     {
   205 	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
   206 
   207 	  std::ostringstream ostr;
   208 	  ostr << number;
   209 	  
   210 	  edgetextmap[edge]->property_text().set_value(ostr.str());
   211     }
   212 
   213   return 0;
   214 
   215 };
   216 
   217 int GraphDisplayerCanvas::resetEdgeText (Edge edge)
   218 {
   219   //the number in the map will be written on the edge
   220   //EXCEPT when the name of the map is Default, because
   221   //in that case empty string will be written, because
   222   //that is the deleter map
   223   
   224   if(edge==INVALID)
   225     {
   226       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   227 	{
   228 	  edgemap_to_edit="";
   229 	  edgetextmap[i]->property_text().set_value("");
   230 	}
   231 
   232     }
   233   else
   234     {
   235       edgetextmap[edge]->property_text().set_value("");
   236     }
   237 
   238   return 0;
   239 
   240 };