1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/gui/graph_displayer_canvas-edge.cc Fri Jun 24 07:58:18 2005 +0000
1.3 @@ -0,0 +1,93 @@
1.4 +#include <graph_displayer_canvas.h>
1.5 +#include <broken_edge.h>
1.6 +#include <math.h>
1.7 +
1.8 +
1.9 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
1.10 +{
1.11 + for (EdgeIt i(g); i!=INVALID; ++i)
1.12 + {
1.13 + int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
1.14 + if(w>=0)
1.15 + {
1.16 + edgesmap[i]->property_width_pixels().set_value(w);
1.17 + }
1.18 + }
1.19 + return 0;
1.20 +};
1.21 +
1.22 +int GraphDisplayerCanvas::changeColor (std::string mapname)
1.23 +{
1.24 +
1.25 + //function maps the range of the maximum and
1.26 + //the minimum of the nodemap to the range of
1.27 + //green in RGB
1.28 +
1.29 + for (EdgeIt i(g); i!=INVALID; ++i)
1.30 + {
1.31 + double w=(*(mapstorage.edgemap_storage)[mapname])[i];
1.32 + double max=mapstorage.maxOfEdgeMap(mapname);
1.33 + double min=mapstorage.minOfEdgeMap(mapname);
1.34 +
1.35 + //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
1.36 + Gdk::Color color;
1.37 + if(max!=min)
1.38 + {
1.39 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
1.40 + }
1.41 + else
1.42 + {
1.43 + color.set_rgb_p (0, 100, 0);
1.44 + }
1.45 +
1.46 + edgesmap[i]->property_fill_color_gdk().set_value(color);
1.47 + }
1.48 + return 0;
1.49 +};
1.50 +
1.51 +int GraphDisplayerCanvas::changeText (std::string mapname)
1.52 +{
1.53 +
1.54 + //the number in the map will be written on the edge
1.55 + //EXCEPT when the name of the map is Text, because
1.56 + //in that case empty string will be written, because
1.57 + //that is the deleter map
1.58 + //\todo isn't it a bit woodcutter?
1.59 +
1.60 + for (EdgeIt i(g); i!=INVALID; ++i)
1.61 + {
1.62 + if(mapname!="Text")
1.63 + {
1.64 + double number=(*(mapstorage.edgemap_storage)[mapname])[i];
1.65 + int length=1;
1.66 + //if number is smaller than one, length would be negative, or invalid
1.67 + if(number>=1)
1.68 + {
1.69 + length=(int)(floor(log(number)/log(10)))+1;
1.70 + }
1.71 + int maxpos=(int)(pow(10,length-1));
1.72 + int strl=length+1+RANGE;
1.73 + char * str=new char[strl];
1.74 + str[length]='.';
1.75 + str[strl]='\0';
1.76 +
1.77 + for(int j=0;j<strl;j++)
1.78 + {
1.79 + if(j!=length)
1.80 + {
1.81 + int digit=(int)(number/maxpos);
1.82 + str[j]=(digit+'0');
1.83 + number-=digit*maxpos;
1.84 + number*=10;
1.85 + }
1.86 + }
1.87 +
1.88 + edgetextmap[i]->property_text().set_value(str);
1.89 + }
1.90 + else
1.91 + {
1.92 + edgetextmap[i]->property_text().set_value("");
1.93 + }
1.94 + }
1.95 + return 0;
1.96 +};