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