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