graph_displayer_canvas-node.cc
author hegyi
Wed, 25 Oct 2006 13:21:24 +0000
changeset 172 fc1e478697d3
parent 156 c5cdf6690cdf
child 174 95872af46fc4
permissions -rwxr-xr-x
Currently visualized map can be saved and loaded from file.
ladanyi@53
     1
#include "graph_displayer_canvas.h"
alpar@59
     2
#include <cmath>
hegyi@28
     3
hegyi@157
     4
const int minimum_node_radius=5;
hegyi@28
     5
alpar@62
     6
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
hegyi@28
     7
{
hegyi@31
     8
  Graph::NodeMap<double> * actual_map;
hegyi@48
     9
  double min, max;
hegyi@96
    10
  min=(mytab.mapstorage).minOfNodeMap(mapname);
hegyi@96
    11
  max=(mytab.mapstorage).maxOfNodeMap(mapname);
hegyi@96
    12
  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
hegyi@81
    13
hegyi@81
    14
  if(node==INVALID)
hegyi@31
    15
    {
hegyi@96
    16
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
    17
	{
hegyi@81
    18
	  double v=fabs((*actual_map)[i]);
hegyi@81
    19
	  int w;
hegyi@154
    20
	  if(autoscale)
hegyi@81
    21
	    {
hegyi@154
    22
	      if(min==max)
hegyi@154
    23
		{
hegyi@154
    24
		  w=(int)(node_property_defaults[N_RADIUS]);
hegyi@154
    25
		}
hegyi@154
    26
	      else
hegyi@154
    27
		{
hegyi@157
    28
		  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
hegyi@154
    29
		}
hegyi@81
    30
	    }
hegyi@81
    31
	  else
hegyi@81
    32
	    {
hegyi@157
    33
	      w=(int)(v*radius_size);
hegyi@81
    34
	    }
hegyi@155
    35
hegyi@157
    36
	  if(w<minimum_node_radius)
hegyi@155
    37
	    {
hegyi@157
    38
	      w=minimum_node_radius;
hegyi@155
    39
	    }
hegyi@155
    40
hegyi@156
    41
	  if(zoomtrack)
hegyi@156
    42
	    {
hegyi@156
    43
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
    44
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
    45
	    }
hegyi@156
    46
hegyi@81
    47
	  if(w>=0)
hegyi@81
    48
	    {
hegyi@81
    49
	      double x1, y1, x2, y2;
hegyi@81
    50
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@81
    51
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@81
    52
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@81
    53
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@81
    54
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    55
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    56
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    57
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    58
	    }
hegyi@81
    59
	}
hegyi@31
    60
    }
hegyi@31
    61
  else
hegyi@31
    62
    {
hegyi@81
    63
      //I think only new nodes use this case
hegyi@154
    64
      //that has no own value, only the default one
hegyi@154
    65
      //int w=(int)(*actual_map)[node];
hegyi@81
    66
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@81
    67
      if(w>=0)
hegyi@81
    68
	{
hegyi@81
    69
	  double x1, y1, x2, y2;
hegyi@81
    70
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@81
    71
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@81
    72
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@81
    73
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@81
    74
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@81
    75
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@81
    76
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@81
    77
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@81
    78
	}
hegyi@31
    79
    }
hegyi@81
    80
  return 0;
hegyi@81
    81
};
hegyi@31
    82
hegyi@81
    83
int GraphDisplayerCanvas::resetNodeRadius (Node node)
hegyi@81
    84
{
hegyi@81
    85
  double min, max;
hegyi@81
    86
  min=node_property_defaults[N_RADIUS];
hegyi@81
    87
  max=node_property_defaults[N_RADIUS];
hegyi@96
    88
  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
hegyi@81
    89
  
hegyi@28
    90
  if(node==INVALID)
hegyi@28
    91
    {
hegyi@96
    92
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@28
    93
	{
ladanyi@91
    94
	  double v=fabs(actual_map[i]);
hegyi@48
    95
	  int w;
hegyi@48
    96
	  if(min==max)
hegyi@48
    97
	    {
hegyi@48
    98
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@48
    99
	    }
hegyi@48
   100
	  else
hegyi@48
   101
	    {
hegyi@48
   102
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@48
   103
	    }
hegyi@156
   104
	  if(zoomtrack)
hegyi@156
   105
	    {
hegyi@156
   106
	      double actual_ppu=get_pixels_per_unit();
hegyi@156
   107
	      w=(int)(w/actual_ppu*fixed_zoom_factor);
hegyi@156
   108
	    }
hegyi@28
   109
	  if(w>=0)
hegyi@28
   110
	    {
hegyi@28
   111
	      double x1, y1, x2, y2;
hegyi@31
   112
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@31
   113
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@31
   114
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@31
   115
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@28
   116
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   117
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   118
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   119
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   120
	    }
hegyi@28
   121
	}
hegyi@28
   122
    }
hegyi@28
   123
  else
hegyi@28
   124
    {
hegyi@31
   125
      //I think only new nodes use this case
ladanyi@91
   126
//       int w=(int)actual_map[node];
hegyi@31
   127
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@28
   128
      if(w>=0)
hegyi@28
   129
	{
hegyi@28
   130
	  double x1, y1, x2, y2;
hegyi@31
   131
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@31
   132
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@31
   133
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@31
   134
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@28
   135
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
   136
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
   137
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
   138
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
   139
	}
hegyi@28
   140
    }
hegyi@28
   141
  return 0;
hegyi@28
   142
};
hegyi@28
   143
alpar@62
   144
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
hegyi@28
   145
{  
hegyi@28
   146
hegyi@28
   147
  //function maps the range of the maximum and
hegyi@28
   148
  //the minimum of the nodemap to the range of
hegyi@28
   149
  //green in RGB
hegyi@28
   150
hegyi@31
   151
  Graph::NodeMap<double> * actual_map;
hegyi@96
   152
  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
hegyi@81
   153
hegyi@81
   154
  double max, min;
hegyi@81
   155
hegyi@96
   156
  max=(mytab.mapstorage).maxOfNodeMap(mapname);
hegyi@96
   157
  min=(mytab.mapstorage).minOfNodeMap(mapname);
hegyi@81
   158
hegyi@81
   159
  if(node==INVALID)
hegyi@31
   160
    {
hegyi@81
   161
hegyi@96
   162
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
   163
	{
hegyi@81
   164
	  Gdk::Color color;
hegyi@81
   165
hegyi@81
   166
	  double w=(*actual_map)[i];
hegyi@81
   167
hegyi@81
   168
	  if(max!=min)
hegyi@81
   169
	    {
hegyi@81
   170
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@81
   171
	    }
hegyi@81
   172
	  else
hegyi@81
   173
	    {
hegyi@81
   174
	      color.set_rgb_p (0, 0, 100);
hegyi@81
   175
	    }
hegyi@81
   176
hegyi@81
   177
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@81
   178
	}
hegyi@31
   179
    }
hegyi@31
   180
  else
hegyi@31
   181
    {
hegyi@81
   182
      Gdk::Color color;
hegyi@81
   183
hegyi@81
   184
      double w=(*actual_map)[node];
hegyi@81
   185
hegyi@81
   186
      if(max!=min)
hegyi@81
   187
	{
hegyi@81
   188
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@81
   189
	}
hegyi@81
   190
      else
hegyi@81
   191
	{
hegyi@81
   192
	  color.set_rgb_p (0, 0, 100);
hegyi@81
   193
	}
hegyi@81
   194
hegyi@81
   195
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@31
   196
    }
hegyi@81
   197
  return 0;
hegyi@81
   198
};
hegyi@81
   199
hegyi@81
   200
int GraphDisplayerCanvas::resetNodeColor (Node node)
hegyi@81
   201
{  
hegyi@81
   202
hegyi@81
   203
  //function maps the range of the maximum and
hegyi@81
   204
  //the minimum of the nodemap to the range of
hegyi@81
   205
  //green in RGB
hegyi@81
   206
hegyi@96
   207
  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
hegyi@31
   208
hegyi@31
   209
  double max, min;
hegyi@31
   210
hegyi@81
   211
  max=node_property_defaults[N_COLOR];
hegyi@81
   212
  min=node_property_defaults[N_COLOR];
hegyi@31
   213
hegyi@28
   214
  if(node==INVALID)
hegyi@28
   215
    {
hegyi@28
   216
hegyi@96
   217
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@28
   218
	{
hegyi@28
   219
	  Gdk::Color color;
hegyi@31
   220
ladanyi@91
   221
	  double w=actual_map[i];
hegyi@31
   222
hegyi@28
   223
	  if(max!=min)
hegyi@28
   224
	    {
hegyi@28
   225
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   226
	    }
hegyi@28
   227
	  else
hegyi@28
   228
	    {
hegyi@28
   229
	      color.set_rgb_p (0, 0, 100);
hegyi@28
   230
	    }
hegyi@28
   231
hegyi@28
   232
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   233
	}
hegyi@28
   234
    }
hegyi@28
   235
  else
hegyi@28
   236
    {
hegyi@28
   237
      Gdk::Color color;
hegyi@31
   238
ladanyi@91
   239
      double w=actual_map[node];
hegyi@31
   240
hegyi@28
   241
      if(max!=min)
hegyi@28
   242
	{
hegyi@28
   243
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   244
	}
hegyi@28
   245
      else
hegyi@28
   246
	{
hegyi@28
   247
	  color.set_rgb_p (0, 0, 100);
hegyi@28
   248
	}
hegyi@28
   249
hegyi@28
   250
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@28
   251
    }
hegyi@28
   252
  return 0;
hegyi@28
   253
};
hegyi@28
   254
alpar@62
   255
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
hegyi@28
   256
{
hegyi@28
   257
hegyi@28
   258
  //the number in the map will be written on the node
hegyi@28
   259
  //EXCEPT when the name of the map is Text, because
hegyi@28
   260
  //in that case empty string will be written, because
hegyi@28
   261
  //that is the deleter map
hegyi@31
   262
hegyi@36
   263
  Graph::NodeMap<double> * actual_map=NULL;
hegyi@96
   264
  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
hegyi@28
   265
hegyi@28
   266
  if(node==INVALID)
hegyi@28
   267
    {
hegyi@96
   268
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@28
   269
	{
hegyi@81
   270
	  nodemap_to_edit=mapname;
hegyi@81
   271
	  double number=(*actual_map)[i];
hegyi@45
   272
hegyi@81
   273
	  std::ostringstream ostr;
hegyi@81
   274
	  ostr << number;
hegyi@45
   275
	      
hegyi@81
   276
	  nodetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   277
	}
hegyi@28
   278
    }
hegyi@28
   279
  else
hegyi@28
   280
    {
hegyi@81
   281
      double number=(*actual_map)[node];
hegyi@45
   282
hegyi@81
   283
      std::ostringstream ostr;
hegyi@81
   284
      ostr << number;
hegyi@45
   285
	      
hegyi@81
   286
      nodetextmap[node]->property_text().set_value(ostr.str());
hegyi@28
   287
    }
hegyi@28
   288
  return 0;
hegyi@28
   289
};
hegyi@81
   290
hegyi@81
   291
int GraphDisplayerCanvas::resetNodeText (Node node)
hegyi@81
   292
{
hegyi@81
   293
hegyi@81
   294
  //the number in the map will be written on the node
hegyi@81
   295
  //EXCEPT when the name of the map is Text, because
hegyi@81
   296
  //in that case empty string will be written, because
hegyi@81
   297
  //that is the deleter map
hegyi@81
   298
hegyi@81
   299
  if(node==INVALID)
hegyi@81
   300
    {
hegyi@96
   301
      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
hegyi@81
   302
	{
hegyi@81
   303
	  nodemap_to_edit="";
hegyi@81
   304
	  nodetextmap[i]->property_text().set_value("");
hegyi@81
   305
	}
hegyi@81
   306
    }
hegyi@81
   307
  else
hegyi@81
   308
    {
hegyi@81
   309
      nodetextmap[node]->property_text().set_value("");
hegyi@81
   310
    }
hegyi@81
   311
  return 0;
hegyi@81
   312
};