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