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