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