gui/graph_displayer_canvas-edge.cc
changeset 1563 0853ed07a677
parent 1512 e54392395480
child 1579 ed7da82bbecf
equal deleted inserted replaced
1:3317793565bb 2:419a81797d69
     3 #include <math.h>
     3 #include <math.h>
     4 
     4 
     5 
     5 
     6 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
     6 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
     7 {
     7 {
       
     8   Graph::EdgeMap<double> * actual_map;
       
     9   if(mapname=="Default")
       
    10     {
       
    11       actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
       
    12     }
       
    13   else
       
    14     {
       
    15       actual_map=(mapstorage.edgemap_storage)[mapname];
       
    16     }
       
    17 
     8   if(edge==INVALID)
    18   if(edge==INVALID)
     9     {
    19     {
    10       for (EdgeIt i(g); i!=INVALID; ++i)
    20       for (EdgeIt i(g); i!=INVALID; ++i)
    11 	{
    21 	{
    12 	  int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
    22 	  int w=(int)(*actual_map)[i];
    13 	  if(w>=0)
    23 	  if(w>=0)
    14 	    {
    24 	    {
    15 	      edgesmap[i]->property_width_pixels().set_value(w);
    25 	      edgesmap[i]->property_width_pixels().set_value(w);
    16 	    }
    26 	    }
    17 	}
    27 	}
    18     }
    28     }
    19   else
    29   else
    20     {
    30     {
    21       int w=(int)(*(mapstorage.edgemap_storage)[mapname])[edge];
    31       int w=(int)(*actual_map)[edge];
    22       if(w>=0)
    32       if(w>=0)
    23 	{
    33 	{
    24 	  edgesmap[edge]->property_width_pixels().set_value(w);
    34 	  edgesmap[edge]->property_width_pixels().set_value(w);
    25 	}
    35 	}
    26     }
    36     }
    31 {  
    41 {  
    32 
    42 
    33   //function maps the range of the maximum and
    43   //function maps the range of the maximum and
    34   //the minimum of the nodemap to the range of
    44   //the minimum of the nodemap to the range of
    35   //green in RGB
    45   //green in RGB
       
    46   Graph::EdgeMap<double> * actual_map;
       
    47   if(mapname=="Default")
       
    48     {
       
    49       actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
       
    50     }
       
    51   else
       
    52     {
       
    53       actual_map=(mapstorage.edgemap_storage)[mapname];
       
    54     }
       
    55 
       
    56   double max, min;
       
    57 
       
    58   if(mapname!="Default")
       
    59     {
       
    60       max=mapstorage.maxOfEdgeMap(mapname);
       
    61       min=mapstorage.minOfEdgeMap(mapname);
       
    62     }
       
    63   else
       
    64     {
       
    65       max=edge_property_defaults[E_COLOR];
       
    66       min=edge_property_defaults[E_COLOR];
       
    67     }
       
    68 
    36   if(edge==INVALID)
    69   if(edge==INVALID)
    37     {
    70     {
    38 
       
    39       for (EdgeIt i(g); i!=INVALID; ++i)
    71       for (EdgeIt i(g); i!=INVALID; ++i)
    40 	{
    72 	{
    41 	  double w=(*(mapstorage.edgemap_storage)[mapname])[i];
    73 	  double w=(*actual_map)[i];
    42 	  double max=mapstorage.maxOfEdgeMap(mapname);
    74 
    43 	  double min=mapstorage.minOfEdgeMap(mapname);
       
    44       
       
    45 	  //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
       
    46 	  Gdk::Color color;
    75 	  Gdk::Color color;
    47 	  if(max!=min)
    76 	  if(max!=min)
    48 	    {
    77 	    {
    49 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    78 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    50 	    }
    79 	    }
    51 	  else
    80 	  else
    52 	    {
    81 	    {
    53 	      color.set_rgb_p (0, 100, 0);
    82 	      color.set_rgb_p (0, 100, 0);
    54 	    }
    83 	    }
    55 
       
    56 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
    84 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
    57 	}
    85 	}
    58     }
    86     }
    59   else
    87   else
    60     {
    88     {
    61       double w=(*(mapstorage.edgemap_storage)[mapname])[edge];
       
    62       double max=mapstorage.maxOfEdgeMap(mapname);
       
    63       double min=mapstorage.minOfEdgeMap(mapname);
       
    64       
       
    65       //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
       
    66       Gdk::Color color;
    89       Gdk::Color color;
       
    90 
       
    91       double w=(*actual_map)[edge];
       
    92 
    67       if(max!=min)
    93       if(max!=min)
    68 	{
    94 	{
    69 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    95 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    70 	}
    96 	}
    71       else
    97       else
    83 
   109 
    84   //the number in the map will be written on the edge
   110   //the number in the map will be written on the edge
    85   //EXCEPT when the name of the map is Text, because
   111   //EXCEPT when the name of the map is Text, because
    86   //in that case empty string will be written, because
   112   //in that case empty string will be written, because
    87   //that is the deleter map
   113   //that is the deleter map
    88   //\todo isn't it a bit woodcutter?
       
    89 
   114 
    90   if(edge==INVALID)
   115   if(edge==INVALID)
    91     {
   116     {
    92       for (EdgeIt i(g); i!=INVALID; ++i)
   117       for (EdgeIt i(g); i!=INVALID; ++i)
    93 	{
   118 	{
    94 	  if(mapname!=edge_property_strings[E_TEXT])
   119 	  if(mapname!="Default")
    95 	    {
   120 	    {
    96 	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
   121 	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
    97 	      int length=1;
   122 	      int length=1;
    98 	      //if number is smaller than one, length would be negative, or invalid
   123 	      //if number is smaller than one, length would be negative, or invalid
    99 	      if(number>=1)
   124 	      if(number>=1)
   126 	}
   151 	}
   127 
   152 
   128     }
   153     }
   129   else
   154   else
   130     {
   155     {
   131       if(mapname!=edge_property_strings[E_TEXT])
   156       if(mapname!="Default")
   132 	{
   157 	{
   133 	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
   158 	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
   134 	  int length=1;
   159 	  int length=1;
   135 	  //if number is smaller than one, length would be negative, or invalid
   160 	  //if number is smaller than one, length would be negative, or invalid
   136 	  if(number>=1)
   161 	  if(number>=1)