gui/graph_displayer_canvas-node.cc
author klao
Mon, 27 Jun 2005 19:47:09 +0000
changeset 1519 17e367a93cbb
child 1525 6d94de269ab1
permissions -rwxr-xr-x
getstart improvements
hegyi@1512
     1
#include <graph_displayer_canvas.h>
hegyi@1512
     2
#include <broken_edge.h>
hegyi@1512
     3
#include <math.h>
hegyi@1512
     4
hegyi@1512
     5
hegyi@1512
     6
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
hegyi@1512
     7
{
hegyi@1512
     8
  if(node==INVALID)
hegyi@1512
     9
    {
hegyi@1512
    10
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
    11
	{
hegyi@1512
    12
	  int w=(int)(*(mapstorage.nodemap_storage)[mapname])[i];
hegyi@1512
    13
	  if(w>=0)
hegyi@1512
    14
	    {
hegyi@1512
    15
	      double x1, y1, x2, y2;
hegyi@1512
    16
	      nodesmap[i]->get_bounds(x1, y1, x2, y2);
hegyi@1512
    17
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@1512
    18
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@1512
    19
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@1512
    20
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@1512
    21
	    }
hegyi@1512
    22
	}
hegyi@1512
    23
    }
hegyi@1512
    24
  else
hegyi@1512
    25
    {
hegyi@1512
    26
      int w=(int)(*(mapstorage.nodemap_storage)[mapname])[node];
hegyi@1512
    27
      if(w>=0)
hegyi@1512
    28
	{
hegyi@1512
    29
	  double x1, y1, x2, y2;
hegyi@1512
    30
	  nodesmap[node]->get_bounds(x1, y1, x2, y2);
hegyi@1512
    31
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@1512
    32
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@1512
    33
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@1512
    34
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@1512
    35
	}
hegyi@1512
    36
    }
hegyi@1512
    37
  return 0;
hegyi@1512
    38
};
hegyi@1512
    39
hegyi@1512
    40
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
hegyi@1512
    41
{  
hegyi@1512
    42
hegyi@1512
    43
  //function maps the range of the maximum and
hegyi@1512
    44
  //the minimum of the nodemap to the range of
hegyi@1512
    45
  //green in RGB
hegyi@1512
    46
hegyi@1512
    47
  if(node==INVALID)
hegyi@1512
    48
    {
hegyi@1512
    49
hegyi@1512
    50
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
    51
	{
hegyi@1512
    52
	  double w=(*(mapstorage.nodemap_storage)[mapname])[i];
hegyi@1512
    53
	  double max=mapstorage.maxOfNodeMap(mapname);
hegyi@1512
    54
	  double min=mapstorage.minOfNodeMap(mapname);
hegyi@1512
    55
      
hegyi@1512
    56
	  //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
hegyi@1512
    57
	  Gdk::Color color;
hegyi@1512
    58
	  if(max!=min)
hegyi@1512
    59
	    {
hegyi@1512
    60
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@1512
    61
	    }
hegyi@1512
    62
	  else
hegyi@1512
    63
	    {
hegyi@1512
    64
	      color.set_rgb_p (0, 0, 100);
hegyi@1512
    65
	    }
hegyi@1512
    66
hegyi@1512
    67
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1512
    68
	}
hegyi@1512
    69
    }
hegyi@1512
    70
  else
hegyi@1512
    71
    {
hegyi@1512
    72
      double w=(*(mapstorage.nodemap_storage)[mapname])[node];
hegyi@1512
    73
      double max=mapstorage.maxOfNodeMap(mapname);
hegyi@1512
    74
      double min=mapstorage.minOfNodeMap(mapname);
hegyi@1512
    75
      
hegyi@1512
    76
      //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
hegyi@1512
    77
      Gdk::Color color;
hegyi@1512
    78
      if(max!=min)
hegyi@1512
    79
	{
hegyi@1512
    80
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@1512
    81
	}
hegyi@1512
    82
      else
hegyi@1512
    83
	{
hegyi@1512
    84
	  color.set_rgb_p (0, 0, 100);
hegyi@1512
    85
	}
hegyi@1512
    86
hegyi@1512
    87
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@1512
    88
    }
hegyi@1512
    89
  return 0;
hegyi@1512
    90
};
hegyi@1512
    91
hegyi@1512
    92
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
hegyi@1512
    93
{
hegyi@1512
    94
hegyi@1512
    95
  //the number in the map will be written on the node
hegyi@1512
    96
  //EXCEPT when the name of the map is Text, because
hegyi@1512
    97
  //in that case empty string will be written, because
hegyi@1512
    98
  //that is the deleter map
hegyi@1512
    99
  //\todo isn't it a bit woodcutter?
hegyi@1512
   100
hegyi@1512
   101
  if(node==INVALID)
hegyi@1512
   102
    {
hegyi@1512
   103
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@1512
   104
	{
hegyi@1512
   105
	  if(mapname!=node_property_strings[N_TEXT])
hegyi@1512
   106
	    {
hegyi@1512
   107
	      double number=(*(mapstorage.nodemap_storage)[mapname])[i];
hegyi@1512
   108
	      int length=1;
hegyi@1512
   109
	      //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   110
	      if(number>=1)
hegyi@1512
   111
		{
hegyi@1512
   112
		  length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   113
		}
hegyi@1512
   114
	      int maxpos=(int)(pow(10,length-1));
hegyi@1512
   115
	      int strl=length+1+RANGE;
hegyi@1512
   116
	      char * str=new char[strl];
hegyi@1512
   117
	      str[length]='.';
hegyi@1512
   118
	      str[strl]='\0';
hegyi@1512
   119
      
hegyi@1512
   120
	      for(int j=0;j<strl;j++)
hegyi@1512
   121
		{
hegyi@1512
   122
		  if(j!=length)
hegyi@1512
   123
		    {
hegyi@1512
   124
		      int digit=(int)(number/maxpos);
hegyi@1512
   125
		      str[j]=(digit+'0');
hegyi@1512
   126
		      number-=digit*maxpos;
hegyi@1512
   127
		      number*=10;
hegyi@1512
   128
		    }
hegyi@1512
   129
		}
hegyi@1512
   130
      
hegyi@1512
   131
	      nodetextmap[i]->property_text().set_value(str);
hegyi@1512
   132
	    }
hegyi@1512
   133
	  else
hegyi@1512
   134
	    {
hegyi@1512
   135
	      nodetextmap[i]->property_text().set_value("");
hegyi@1512
   136
	    }
hegyi@1512
   137
	}
hegyi@1512
   138
    }
hegyi@1512
   139
  else
hegyi@1512
   140
    {
hegyi@1512
   141
      if(mapname!=node_property_strings[N_TEXT])
hegyi@1512
   142
	{
hegyi@1512
   143
	  double number=(*(mapstorage.nodemap_storage)[mapname])[node];
hegyi@1512
   144
	  int length=1;
hegyi@1512
   145
	  //if number is smaller than one, length would be negative, or invalid
hegyi@1512
   146
	  if(number>=1)
hegyi@1512
   147
	    {
hegyi@1512
   148
	      length=(int)(floor(log(number)/log(10)))+1;
hegyi@1512
   149
	    }
hegyi@1512
   150
	  int maxpos=(int)(pow(10,length-1));
hegyi@1512
   151
	  int strl=length+1+RANGE;
hegyi@1512
   152
	  char * str=new char[strl];
hegyi@1512
   153
	  str[length]='.';
hegyi@1512
   154
	  str[strl]='\0';
hegyi@1512
   155
      
hegyi@1512
   156
	  for(int j=0;j<strl;j++)
hegyi@1512
   157
	    {
hegyi@1512
   158
	      if(j!=length)
hegyi@1512
   159
		{
hegyi@1512
   160
		  int digit=(int)(number/maxpos);
hegyi@1512
   161
		  str[j]=(digit+'0');
hegyi@1512
   162
		  number-=digit*maxpos;
hegyi@1512
   163
		  number*=10;
hegyi@1512
   164
		}
hegyi@1512
   165
	    }
hegyi@1512
   166
      
hegyi@1512
   167
	  nodetextmap[node]->property_text().set_value(str);
hegyi@1512
   168
	}
hegyi@1512
   169
      else
hegyi@1512
   170
	{
hegyi@1512
   171
	  nodetextmap[node]->property_text().set_value("");
hegyi@1512
   172
	}
hegyi@1512
   173
    }
hegyi@1512
   174
  return 0;
hegyi@1512
   175
};