graph_displayer_canvas-edge.cc
author hegyi
Thu, 28 Jul 2005 15:54:00 +0000
branchgui
changeset 48 b8ec84524fa2
parent 47 9a0e6e92d06c
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@27
     1
#include <graph_displayer_canvas.h>
hegyi@27
     2
#include <broken_edge.h>
hegyi@27
     3
#include <math.h>
hegyi@27
     4
hegyi@27
     5
hegyi@28
     6
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
hegyi@27
     7
{
hegyi@31
     8
  Graph::EdgeMap<double> * actual_map;
hegyi@48
     9
  double min, max;
hegyi@48
    10
hegyi@31
    11
  if(mapname=="Default")
hegyi@31
    12
    {
hegyi@48
    13
      min=edge_property_defaults[E_WIDTH];
hegyi@48
    14
      max=edge_property_defaults[E_WIDTH];
hegyi@31
    15
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
hegyi@31
    16
    }
hegyi@31
    17
  else
hegyi@31
    18
    {
hegyi@48
    19
      min=mapstorage.minOfEdgeMap(mapname);
hegyi@48
    20
      max=mapstorage.maxOfEdgeMap(mapname);
hegyi@31
    21
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    22
    }
hegyi@31
    23
hegyi@28
    24
  if(edge==INVALID)
hegyi@27
    25
    {
hegyi@28
    26
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    27
	{
hegyi@48
    28
	  double v=abs((*actual_map)[i]);
hegyi@48
    29
	  int w;
hegyi@48
    30
	  if(min==max)
hegyi@28
    31
	    {
hegyi@48
    32
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@28
    33
	    }
hegyi@48
    34
	  else
hegyi@48
    35
	    {
hegyi@48
    36
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@48
    37
	    }
hegyi@48
    38
	  edgesmap[i]->property_width_units().set_value(w);
hegyi@28
    39
	}
hegyi@28
    40
    }
hegyi@28
    41
  else
hegyi@28
    42
    {
hegyi@31
    43
      int w=(int)(*actual_map)[edge];
hegyi@27
    44
      if(w>=0)
hegyi@27
    45
	{
hegyi@47
    46
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@27
    47
	}
hegyi@27
    48
    }
hegyi@27
    49
  return 0;
hegyi@27
    50
};
hegyi@27
    51
hegyi@28
    52
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
hegyi@27
    53
{  
hegyi@27
    54
hegyi@27
    55
  //function maps the range of the maximum and
hegyi@27
    56
  //the minimum of the nodemap to the range of
hegyi@27
    57
  //green in RGB
hegyi@31
    58
  Graph::EdgeMap<double> * actual_map;
hegyi@31
    59
  if(mapname=="Default")
hegyi@31
    60
    {
hegyi@31
    61
      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
hegyi@31
    62
    }
hegyi@31
    63
  else
hegyi@31
    64
    {
hegyi@31
    65
      actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@31
    66
    }
hegyi@31
    67
hegyi@31
    68
  double max, min;
hegyi@31
    69
hegyi@31
    70
  if(mapname!="Default")
hegyi@31
    71
    {
hegyi@31
    72
      max=mapstorage.maxOfEdgeMap(mapname);
hegyi@31
    73
      min=mapstorage.minOfEdgeMap(mapname);
hegyi@31
    74
    }
hegyi@31
    75
  else
hegyi@31
    76
    {
hegyi@31
    77
      max=edge_property_defaults[E_COLOR];
hegyi@31
    78
      min=edge_property_defaults[E_COLOR];
hegyi@31
    79
    }
hegyi@31
    80
hegyi@28
    81
  if(edge==INVALID)
hegyi@28
    82
    {
hegyi@28
    83
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@28
    84
	{
hegyi@31
    85
	  double w=(*actual_map)[i];
hegyi@31
    86
hegyi@28
    87
	  Gdk::Color color;
hegyi@28
    88
	  if(max!=min)
hegyi@28
    89
	    {
hegyi@28
    90
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
    91
	    }
hegyi@28
    92
	  else
hegyi@28
    93
	    {
hegyi@28
    94
	      color.set_rgb_p (0, 100, 0);
hegyi@28
    95
	    }
hegyi@28
    96
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@28
    97
	}
hegyi@28
    98
    }
hegyi@28
    99
  else
hegyi@27
   100
    {
hegyi@28
   101
      Gdk::Color color;
hegyi@31
   102
hegyi@31
   103
      double w=(*actual_map)[edge];
hegyi@31
   104
hegyi@28
   105
      if(max!=min)
hegyi@28
   106
	{
hegyi@28
   107
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@28
   108
	}
hegyi@28
   109
      else
hegyi@28
   110
	{
hegyi@28
   111
	  color.set_rgb_p (0, 100, 0);
hegyi@28
   112
	}
hegyi@28
   113
hegyi@28
   114
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@27
   115
    }
hegyi@27
   116
  return 0;
hegyi@27
   117
};
hegyi@27
   118
hegyi@28
   119
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
hegyi@27
   120
{
hegyi@27
   121
  //the number in the map will be written on the edge
hegyi@40
   122
  //EXCEPT when the name of the map is Default, because
hegyi@27
   123
  //in that case empty string will be written, because
hegyi@27
   124
  //that is the deleter map
hegyi@27
   125
hegyi@28
   126
  if(edge==INVALID)
hegyi@27
   127
    {
hegyi@28
   128
      for (EdgeIt i(g); i!=INVALID; ++i)
hegyi@27
   129
	{
hegyi@31
   130
	  if(mapname!="Default")
hegyi@28
   131
	    {
hegyi@35
   132
	      edgemap_to_edit=mapname;
hegyi@28
   133
	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@44
   134
hegyi@44
   135
	      std::ostringstream ostr;
hegyi@44
   136
	      ostr << number;
hegyi@45
   137
	      
hegyi@44
   138
      	      edgetextmap[i]->property_text().set_value(ostr.str());
hegyi@28
   139
	    }
hegyi@28
   140
	  else
hegyi@28
   141
	    {
hegyi@35
   142
	      edgemap_to_edit="";
hegyi@28
   143
	      edgetextmap[i]->property_text().set_value("");
hegyi@28
   144
	    }
hegyi@28
   145
	}
hegyi@28
   146
hegyi@28
   147
    }
hegyi@28
   148
  else
hegyi@28
   149
    {
hegyi@31
   150
      if(mapname!="Default")
hegyi@28
   151
	{
hegyi@28
   152
	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
hegyi@45
   153
hegyi@45
   154
	  std::ostringstream ostr;
hegyi@45
   155
	  ostr << number;
hegyi@45
   156
	  
hegyi@45
   157
	  edgetextmap[edge]->property_text().set_value(ostr.str());
hegyi@27
   158
	}
hegyi@27
   159
      else
hegyi@27
   160
	{
hegyi@28
   161
	  edgetextmap[edge]->property_text().set_value("");
hegyi@27
   162
	}
hegyi@28
   163
	  
hegyi@27
   164
    }
hegyi@28
   165
hegyi@27
   166
  return 0;
hegyi@28
   167
hegyi@27
   168
};