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