gui/graph_displayer_canvas-edge.cc
author hegyi
Mon, 21 Nov 2005 12:07:05 +0000
changeset 1819 fd82adfbe905
parent 1731 616bc933c2bc
child 1825 535d2eccfc03
permissions -rwxr-xr-x
Reorganizing.
ladanyi@1606
     1
#include "graph_displayer_canvas.h"
alpar@1632
     2
#include <cmath>
hegyi@1510
     3
hegyi@1510
     4
hegyi@1731
     5
int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
hegyi@1731
     6
{
hegyi@1731
     7
  Graph::EdgeMap<double> * actual_map;
hegyi@1731
     8
  double min, max;
hegyi@1731
     9
hegyi@1731
    10
  min=edge_property_defaults[E_WIDTH];
hegyi@1731
    11
  max=edge_property_defaults[E_WIDTH];
hegyi@1731
    12
  actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
hegyi@1731
    13
  
hegyi@1731
    14
  if(edge==INVALID)
hegyi@1731
    15
    {
hegyi@1731
    16
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1731
    17
	{
hegyi@1731
    18
	  double v=fabs((*actual_map)[i]);
hegyi@1731
    19
	  int w;
hegyi@1731
    20
	  if(min==max)
hegyi@1731
    21
	    {
hegyi@1731
    22
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@1731
    23
	    }
hegyi@1731
    24
	  else
hegyi@1731
    25
	    {
hegyi@1731
    26
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@1731
    27
	    }
hegyi@1731
    28
	  edgesmap[i]->property_width_units().set_value(w);
hegyi@1731
    29
	}
hegyi@1731
    30
    }
hegyi@1731
    31
  else
hegyi@1731
    32
    {
hegyi@1731
    33
      int w=(int)(*actual_map)[edge];
hegyi@1731
    34
      if(w>=0)
hegyi@1731
    35
	{
hegyi@1731
    36
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@1731
    37
	}
hegyi@1731
    38
    }
hegyi@1731
    39
  return 0;
hegyi@1731
    40
}
hegyi@1731
    41
hegyi@1731
    42
alpar@1643
    43
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
hegyi@1510
    44
{
hegyi@1525
    45
  Graph::EdgeMap<double> * actual_map;
hegyi@1599
    46
  double min, max;
hegyi@1599
    47
hegyi@1731
    48
  min=mapstorage.minOfEdgeMap(mapname);
hegyi@1731
    49
  max=mapstorage.maxOfEdgeMap(mapname);
hegyi@1731
    50
  actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@1525
    51
hegyi@1512
    52
  if(edge==INVALID)
hegyi@1510
    53
    {
ladanyi@1606
    54
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1512
    55
	{
hegyi@1614
    56
	  double v=fabs((*actual_map)[i]);
hegyi@1599
    57
	  int w;
hegyi@1599
    58
	  if(min==max)
hegyi@1512
    59
	    {
hegyi@1599
    60
	      w=(int)(edge_property_defaults[E_WIDTH]);
hegyi@1512
    61
	    }
hegyi@1599
    62
	  else
hegyi@1599
    63
	    {
hegyi@1599
    64
	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
hegyi@1599
    65
	    }
hegyi@1599
    66
	  edgesmap[i]->property_width_units().set_value(w);
hegyi@1512
    67
	}
hegyi@1512
    68
    }
hegyi@1512
    69
  else
hegyi@1512
    70
    {
hegyi@1525
    71
      int w=(int)(*actual_map)[edge];
hegyi@1510
    72
      if(w>=0)
hegyi@1510
    73
	{
hegyi@1598
    74
	  edgesmap[edge]->property_width_units().set_value(w);
hegyi@1510
    75
	}
hegyi@1510
    76
    }
hegyi@1510
    77
  return 0;
hegyi@1510
    78
};
hegyi@1510
    79
alpar@1643
    80
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
hegyi@1510
    81
{  
hegyi@1510
    82
hegyi@1510
    83
  //function maps the range of the maximum and
hegyi@1510
    84
  //the minimum of the nodemap to the range of
hegyi@1510
    85
  //green in RGB
hegyi@1525
    86
  Graph::EdgeMap<double> * actual_map;
hegyi@1731
    87
  actual_map=(mapstorage.edgemap_storage)[mapname];
hegyi@1731
    88
hegyi@1731
    89
  double max, min;
hegyi@1731
    90
hegyi@1731
    91
  max=mapstorage.maxOfEdgeMap(mapname);
hegyi@1731
    92
  min=mapstorage.minOfEdgeMap(mapname);
hegyi@1731
    93
hegyi@1731
    94
  if(edge==INVALID)
hegyi@1525
    95
    {
hegyi@1731
    96
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1731
    97
	{
hegyi@1731
    98
	  double w=(*actual_map)[i];
hegyi@1731
    99
hegyi@1731
   100
	  Gdk::Color color;
hegyi@1731
   101
	  if(max!=min)
hegyi@1731
   102
	    {
hegyi@1731
   103
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1731
   104
	    }
hegyi@1731
   105
	  else
hegyi@1731
   106
	    {
hegyi@1731
   107
	      color.set_rgb_p (0, 100, 0);
hegyi@1731
   108
	    }
hegyi@1731
   109
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1731
   110
	}
hegyi@1525
   111
    }
hegyi@1525
   112
  else
hegyi@1525
   113
    {
hegyi@1731
   114
      Gdk::Color color;
hegyi@1731
   115
hegyi@1731
   116
      double w=(*actual_map)[edge];
hegyi@1731
   117
hegyi@1731
   118
      if(max!=min)
hegyi@1731
   119
	{
hegyi@1731
   120
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1731
   121
	}
hegyi@1731
   122
      else
hegyi@1731
   123
	{
hegyi@1731
   124
	  color.set_rgb_p (0, 100, 0);
hegyi@1731
   125
	}
hegyi@1731
   126
hegyi@1731
   127
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@1525
   128
    }
hegyi@1731
   129
  return 0;
hegyi@1731
   130
};
hegyi@1731
   131
hegyi@1731
   132
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
hegyi@1731
   133
{  
hegyi@1731
   134
hegyi@1731
   135
  //function maps the range of the maximum and
hegyi@1731
   136
  //the minimum of the nodemap to the range of
hegyi@1731
   137
  //green in RGB
hegyi@1731
   138
  Graph::EdgeMap<double> * actual_map;
hegyi@1731
   139
  actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
hegyi@1525
   140
hegyi@1525
   141
  double max, min;
hegyi@1525
   142
hegyi@1731
   143
  max=edge_property_defaults[E_COLOR];
hegyi@1731
   144
  min=edge_property_defaults[E_COLOR];
hegyi@1525
   145
hegyi@1512
   146
  if(edge==INVALID)
hegyi@1512
   147
    {
ladanyi@1606
   148
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1512
   149
	{
hegyi@1525
   150
	  double w=(*actual_map)[i];
hegyi@1525
   151
hegyi@1512
   152
	  Gdk::Color color;
hegyi@1512
   153
	  if(max!=min)
hegyi@1512
   154
	    {
hegyi@1512
   155
	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1512
   156
	    }
hegyi@1512
   157
	  else
hegyi@1512
   158
	    {
hegyi@1512
   159
	      color.set_rgb_p (0, 100, 0);
hegyi@1512
   160
	    }
hegyi@1512
   161
	  edgesmap[i]->property_fill_color_gdk().set_value(color);
hegyi@1512
   162
	}
hegyi@1512
   163
    }
hegyi@1512
   164
  else
hegyi@1510
   165
    {
hegyi@1512
   166
      Gdk::Color color;
hegyi@1525
   167
hegyi@1525
   168
      double w=(*actual_map)[edge];
hegyi@1525
   169
hegyi@1512
   170
      if(max!=min)
hegyi@1512
   171
	{
hegyi@1512
   172
	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
hegyi@1512
   173
	}
hegyi@1512
   174
      else
hegyi@1512
   175
	{
hegyi@1512
   176
	  color.set_rgb_p (0, 100, 0);
hegyi@1512
   177
	}
hegyi@1512
   178
hegyi@1512
   179
      edgesmap[edge]->property_fill_color_gdk().set_value(color);
hegyi@1510
   180
    }
hegyi@1510
   181
  return 0;
hegyi@1510
   182
};
hegyi@1510
   183
alpar@1643
   184
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
hegyi@1510
   185
{
hegyi@1510
   186
  //the number in the map will be written on the edge
hegyi@1589
   187
  //EXCEPT when the name of the map is Default, because
hegyi@1510
   188
  //in that case empty string will be written, because
hegyi@1510
   189
  //that is the deleter map
ladanyi@1645
   190
  
hegyi@1512
   191
  if(edge==INVALID)
hegyi@1510
   192
    {
ladanyi@1606
   193
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1510
   194
	{
hegyi@1731
   195
	  edgemap_to_edit=mapname;
hegyi@1731
   196
	  double number=(*(mapstorage.edgemap_storage)[mapname])[i];
hegyi@1731
   197
	  
hegyi@1731
   198
	  std::ostringstream ostr;
hegyi@1731
   199
	  ostr << number;
hegyi@1731
   200
	  
hegyi@1731
   201
	  edgetextmap[i]->property_text().set_value(ostr.str());
hegyi@1512
   202
	}
hegyi@1512
   203
hegyi@1512
   204
    }
hegyi@1512
   205
  else
hegyi@1512
   206
    {
hegyi@1512
   207
	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
hegyi@1596
   208
hegyi@1596
   209
	  std::ostringstream ostr;
hegyi@1596
   210
	  ostr << number;
hegyi@1596
   211
	  
hegyi@1596
   212
	  edgetextmap[edge]->property_text().set_value(ostr.str());
hegyi@1510
   213
    }
hegyi@1512
   214
hegyi@1510
   215
  return 0;
hegyi@1512
   216
hegyi@1510
   217
};
hegyi@1731
   218
hegyi@1731
   219
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
hegyi@1731
   220
{
hegyi@1731
   221
  //the number in the map will be written on the edge
hegyi@1731
   222
  //EXCEPT when the name of the map is Default, because
hegyi@1731
   223
  //in that case empty string will be written, because
hegyi@1731
   224
  //that is the deleter map
hegyi@1731
   225
  
hegyi@1731
   226
  if(edge==INVALID)
hegyi@1731
   227
    {
hegyi@1731
   228
      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
hegyi@1731
   229
	{
hegyi@1731
   230
	  edgemap_to_edit="";
hegyi@1731
   231
	  edgetextmap[i]->property_text().set_value("");
hegyi@1731
   232
	}
hegyi@1731
   233
hegyi@1731
   234
    }
hegyi@1731
   235
  else
hegyi@1731
   236
    {
hegyi@1731
   237
      edgetextmap[edge]->property_text().set_value("");
hegyi@1731
   238
    }
hegyi@1731
   239
hegyi@1731
   240
  return 0;
hegyi@1731
   241
hegyi@1731
   242
};