graph_displayer_canvas-node.cc
author hegyi
Thu, 28 Jul 2005 15:54:00 +0000
branchgui
changeset 48 b8ec84524fa2
parent 45 199f433eb7cd
child 53 e73d7540bd24
permissions -rwxr-xr-x
cout->cerr, node radius and edge width is now scaled, maps are editable by clicking on texts.
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@31
     8
  Graph::NodeMap<double> * actual_map;
hegyi@48
     9
  double min, max;
hegyi@31
    10
  if(mapname=="Default")
hegyi@31
    11
    {
hegyi@48
    12
      min=node_property_defaults[N_RADIUS];
hegyi@48
    13
      max=node_property_defaults[N_RADIUS];
hegyi@31
    14
      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
hegyi@31
    15
    }
hegyi@31
    16
  else
hegyi@31
    17
    {
hegyi@48
    18
      min=mapstorage.minOfNodeMap(mapname);
hegyi@48
    19
      max=mapstorage.maxOfNodeMap(mapname);
hegyi@31
    20
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@31
    21
    }
hegyi@31
    22
hegyi@28
    23
  if(node==INVALID)
hegyi@28
    24
    {
hegyi@28
    25
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@28
    26
	{
hegyi@48
    27
	  double v=abs((*actual_map)[i]);
hegyi@48
    28
	  int w;
hegyi@48
    29
	  if(min==max)
hegyi@48
    30
	    {
hegyi@48
    31
	      w=(int)(node_property_defaults[N_RADIUS]);
hegyi@48
    32
	    }
hegyi@48
    33
	  else
hegyi@48
    34
	    {
hegyi@48
    35
	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
hegyi@48
    36
	    }
hegyi@28
    37
	  if(w>=0)
hegyi@28
    38
	    {
hegyi@28
    39
	      double x1, y1, x2, y2;
hegyi@31
    40
	      x1=nodesmap[i]->property_x1().get_value();
hegyi@31
    41
	      x2=nodesmap[i]->property_x2().get_value();
hegyi@31
    42
	      y1=nodesmap[i]->property_y1().get_value();
hegyi@31
    43
	      y2=nodesmap[i]->property_y2().get_value();
hegyi@28
    44
	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
    45
	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
    46
	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
    47
	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
    48
	    }
hegyi@28
    49
	}
hegyi@28
    50
    }
hegyi@28
    51
  else
hegyi@28
    52
    {
hegyi@31
    53
      //I think only new nodes use this case
hegyi@31
    54
//       int w=(int)(*actual_map)[node];
hegyi@31
    55
      int w=(int)(node_property_defaults[N_RADIUS]);
hegyi@28
    56
      if(w>=0)
hegyi@28
    57
	{
hegyi@28
    58
	  double x1, y1, x2, y2;
hegyi@31
    59
	  x1=nodesmap[node]->property_x1().get_value();
hegyi@31
    60
	  x2=nodesmap[node]->property_x2().get_value();
hegyi@31
    61
	  y1=nodesmap[node]->property_y1().get_value();
hegyi@31
    62
	  y2=nodesmap[node]->property_y2().get_value();
hegyi@28
    63
	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
hegyi@28
    64
	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
hegyi@28
    65
	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
hegyi@28
    66
	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
hegyi@28
    67
	}
hegyi@28
    68
    }
hegyi@28
    69
  return 0;
hegyi@28
    70
};
hegyi@28
    71
hegyi@28
    72
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
hegyi@28
    73
{  
hegyi@28
    74
hegyi@28
    75
  //function maps the range of the maximum and
hegyi@28
    76
  //the minimum of the nodemap to the range of
hegyi@28
    77
  //green in RGB
hegyi@28
    78
hegyi@31
    79
  Graph::NodeMap<double> * actual_map;
hegyi@31
    80
  if(mapname=="Default")
hegyi@31
    81
    {
hegyi@31
    82
      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
hegyi@31
    83
    }
hegyi@31
    84
  else
hegyi@31
    85
    {
hegyi@31
    86
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@31
    87
    }
hegyi@31
    88
hegyi@31
    89
  double max, min;
hegyi@31
    90
hegyi@31
    91
  if(mapname!="Default")
hegyi@31
    92
    {
hegyi@31
    93
      max=mapstorage.maxOfNodeMap(mapname);
hegyi@31
    94
      min=mapstorage.minOfNodeMap(mapname);
hegyi@31
    95
    }
hegyi@31
    96
  else
hegyi@31
    97
    {
hegyi@31
    98
      max=node_property_defaults[N_COLOR];
hegyi@31
    99
      min=node_property_defaults[N_COLOR];
hegyi@31
   100
    }
hegyi@31
   101
hegyi@31
   102
hegyi@28
   103
  if(node==INVALID)
hegyi@28
   104
    {
hegyi@28
   105
hegyi@28
   106
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@28
   107
	{
hegyi@28
   108
	  Gdk::Color color;
hegyi@31
   109
hegyi@31
   110
	  double w=(*actual_map)[i];
hegyi@31
   111
hegyi@28
   112
	  if(max!=min)
hegyi@28
   113
	    {
hegyi@28
   114
	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   115
	    }
hegyi@28
   116
	  else
hegyi@28
   117
	    {
hegyi@28
   118
	      color.set_rgb_p (0, 0, 100);
hegyi@28
   119
	    }
hegyi@28
   120
hegyi@28
   121
	  nodesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
   122
	}
hegyi@28
   123
    }
hegyi@28
   124
  else
hegyi@28
   125
    {
hegyi@28
   126
      Gdk::Color color;
hegyi@31
   127
hegyi@31
   128
      double w=(*actual_map)[node];
hegyi@31
   129
hegyi@28
   130
      if(max!=min)
hegyi@28
   131
	{
hegyi@28
   132
	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
hegyi@28
   133
	}
hegyi@28
   134
      else
hegyi@28
   135
	{
hegyi@28
   136
	  color.set_rgb_p (0, 0, 100);
hegyi@28
   137
	}
hegyi@28
   138
hegyi@28
   139
      nodesmap[node]->property_fill_color_gdk().set_value(color);
hegyi@28
   140
    }
hegyi@28
   141
  return 0;
hegyi@28
   142
};
hegyi@28
   143
hegyi@28
   144
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
hegyi@28
   145
{
hegyi@28
   146
hegyi@28
   147
  //the number in the map will be written on the node
hegyi@28
   148
  //EXCEPT when the name of the map is Text, because
hegyi@28
   149
  //in that case empty string will be written, because
hegyi@28
   150
  //that is the deleter map
hegyi@31
   151
hegyi@36
   152
  Graph::NodeMap<double> * actual_map=NULL;
hegyi@35
   153
  if(mapname!="Default")
hegyi@31
   154
    {
hegyi@31
   155
      actual_map=(mapstorage.nodemap_storage)[mapname];
hegyi@31
   156
    }
hegyi@28
   157
hegyi@28
   158
  if(node==INVALID)
hegyi@28
   159
    {
hegyi@28
   160
      for (NodeIt i(g); i!=INVALID; ++i)
hegyi@28
   161
	{
hegyi@31
   162
	  if(mapname!="Default")
hegyi@28
   163
	    {
hegyi@35
   164
	      nodemap_to_edit=mapname;
hegyi@31
   165
	      double number=(*actual_map)[i];
hegyi@45
   166
hegyi@45
   167
	      std::ostringstream ostr;
hegyi@45
   168
	      ostr << number;
hegyi@45
   169
	      
hegyi@45
   170
      	      nodetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   171
	    }
hegyi@28
   172
	  else
hegyi@28
   173
	    {
hegyi@35
   174
	      nodemap_to_edit="";
hegyi@28
   175
	      nodetextmap[i]->property_text().set_value("");
hegyi@28
   176
	    }
hegyi@28
   177
	}
hegyi@28
   178
    }
hegyi@28
   179
  else
hegyi@28
   180
    {
hegyi@31
   181
      if(mapname!="Default")
hegyi@28
   182
	{
hegyi@31
   183
	  double number=(*actual_map)[node];
hegyi@45
   184
hegyi@45
   185
	  std::ostringstream ostr;
hegyi@45
   186
	  ostr << number;
hegyi@45
   187
	      
hegyi@45
   188
	  nodetextmap[node]->property_text().set_value(ostr.str());
hegyi@28
   189
	}
hegyi@28
   190
      else
hegyi@28
   191
	{
hegyi@28
   192
	  nodetextmap[node]->property_text().set_value("");
hegyi@28
   193
	}
hegyi@28
   194
    }
hegyi@28
   195
  return 0;
hegyi@28
   196
};