gui/graph_displayer_canvas-edge.cc
author hegyi
Fri, 24 Jun 2005 07:58:18 +0000
changeset 1510 cde847387b5a
child 1512 e54392395480
permissions -rwxr-xr-x
File graph_displayer is split in functional parts.
hegyi@1510
     1
#include <graph_displayer_canvas.h>
hegyi@1510
     2
#include <broken_edge.h>
hegyi@1510
     3
#include <math.h>
hegyi@1510
     4
hegyi@1510
     5
hegyi@1510
     6
int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
hegyi@1510
     7
{
hegyi@1510
     8
  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1510
     9
    {
hegyi@1510
    10
      int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@1510
    11
      if(w>=0)
hegyi@1510
    12
	{
hegyi@1510
    13
	  edgesmap[i]->property_width_pixels().set_value(w);
hegyi@1510
    14
	}
hegyi@1510
    15
    }
hegyi@1510
    16
  return 0;
hegyi@1510
    17
};
hegyi@1510
    18
hegyi@1510
    19
int GraphDisplayerCanvas::changeColor (std::string mapname)
hegyi@1510
    20
{  
hegyi@1510
    21
hegyi@1510
    22
  //function maps the range of the maximum and
hegyi@1510
    23
  //the minimum of the nodemap to the range of
hegyi@1510
    24
  //green in RGB
hegyi@1510
    25
hegyi@1510
    26
  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1510
    27
  {
hegyi@1510
    28
    double w=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@1510
    29
    double max=mapstorage.maxOfEdgeMap(mapname);
hegyi@1510
    30
    double min=mapstorage.minOfEdgeMap(mapname);
hegyi@1510
    31
      
hegyi@1510
    32
    //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
hegyi@1510
    33
    Gdk::Color color;
hegyi@1510
    34
    if(max!=min)
hegyi@1510
    35
    {
hegyi@1510
    36
      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1510
    37
    }
hegyi@1510
    38
    else
hegyi@1510
    39
    {
hegyi@1510
    40
      color.set_rgb_p (0, 100, 0);
hegyi@1510
    41
    }
hegyi@1510
    42
hegyi@1510
    43
    edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1510
    44
  }
hegyi@1510
    45
  return 0;
hegyi@1510
    46
};
hegyi@1510
    47
hegyi@1510
    48
int GraphDisplayerCanvas::changeText (std::string mapname)
hegyi@1510
    49
{
hegyi@1510
    50
hegyi@1510
    51
  //the number in the map will be written on the edge
hegyi@1510
    52
  //EXCEPT when the name of the map is Text, because
hegyi@1510
    53
  //in that case empty string will be written, because
hegyi@1510
    54
  //that is the deleter map
hegyi@1510
    55
  //\todo isn't it a bit woodcutter?
hegyi@1510
    56
hegyi@1510
    57
  for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@1510
    58
    {
hegyi@1510
    59
      if(mapname!="Text")
hegyi@1510
    60
	{
hegyi@1510
    61
	  double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@1510
    62
	  int length=1;
hegyi@1510
    63
	  //if number is smaller than one, length would be negative, or invalid
hegyi@1510
    64
	  if(number>=1)
hegyi@1510
    65
	    {
hegyi@1510
    66
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@1510
    67
	    }
hegyi@1510
    68
	  int maxpos=(int)(pow(10,length-1));
hegyi@1510
    69
	  int strl=length+1+RANGE;
hegyi@1510
    70
	  char * str=new char[strl];
hegyi@1510
    71
	  str[length]='.';
hegyi@1510
    72
	  str[strl]='\0';
hegyi@1510
    73
      
hegyi@1510
    74
	  for(int j=0;j<strl;j++)
hegyi@1510
    75
	    {
hegyi@1510
    76
	      if(j!=length)
hegyi@1510
    77
		{
hegyi@1510
    78
		  int digit=(int)(number/maxpos);
hegyi@1510
    79
		  str[j]=(digit+'0');
hegyi@1510
    80
		  number-=digit*maxpos;
hegyi@1510
    81
		  number*=10;
hegyi@1510
    82
		}
hegyi@1510
    83
	    }
hegyi@1510
    84
      
hegyi@1510
    85
	  edgetextmap[i]->property_text().set_value(str);
hegyi@1510
    86
	}
hegyi@1510
    87
      else
hegyi@1510
    88
	{
hegyi@1510
    89
	  edgetextmap[i]->property_text().set_value("");
hegyi@1510
    90
	}
hegyi@1510
    91
    }
hegyi@1510
    92
  return 0;
hegyi@1510
    93
};