[27] | 1 | #include <graph_displayer_canvas.h> |
---|
| 2 | #include <broken_edge.h> |
---|
| 3 | #include <math.h> |
---|
| 4 | |
---|
| 5 | |
---|
[28] | 6 | int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge) |
---|
[27] | 7 | { |
---|
[31] | 8 | Graph::EdgeMap<double> * actual_map; |
---|
| 9 | if(mapname=="Default") |
---|
| 10 | { |
---|
| 11 | actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]); |
---|
| 12 | } |
---|
| 13 | else |
---|
| 14 | { |
---|
| 15 | actual_map=(mapstorage.edgemap_storage)[mapname]; |
---|
| 16 | } |
---|
| 17 | |
---|
[28] | 18 | if(edge==INVALID) |
---|
[27] | 19 | { |
---|
[28] | 20 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
| 21 | { |
---|
[31] | 22 | int w=(int)(*actual_map)[i]; |
---|
[28] | 23 | if(w>=0) |
---|
| 24 | { |
---|
| 25 | edgesmap[i]->property_width_pixels().set_value(w); |
---|
| 26 | } |
---|
| 27 | } |
---|
| 28 | } |
---|
| 29 | else |
---|
| 30 | { |
---|
[31] | 31 | int w=(int)(*actual_map)[edge]; |
---|
[27] | 32 | if(w>=0) |
---|
| 33 | { |
---|
[28] | 34 | edgesmap[edge]->property_width_pixels().set_value(w); |
---|
[27] | 35 | } |
---|
| 36 | } |
---|
| 37 | return 0; |
---|
| 38 | }; |
---|
| 39 | |
---|
[28] | 40 | int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge) |
---|
[27] | 41 | { |
---|
| 42 | |
---|
| 43 | //function maps the range of the maximum and |
---|
| 44 | //the minimum of the nodemap to the range of |
---|
| 45 | //green in RGB |
---|
[31] | 46 | Graph::EdgeMap<double> * actual_map; |
---|
| 47 | if(mapname=="Default") |
---|
| 48 | { |
---|
| 49 | actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]); |
---|
| 50 | } |
---|
| 51 | else |
---|
| 52 | { |
---|
| 53 | actual_map=(mapstorage.edgemap_storage)[mapname]; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | double max, min; |
---|
| 57 | |
---|
| 58 | if(mapname!="Default") |
---|
| 59 | { |
---|
| 60 | max=mapstorage.maxOfEdgeMap(mapname); |
---|
| 61 | min=mapstorage.minOfEdgeMap(mapname); |
---|
| 62 | } |
---|
| 63 | else |
---|
| 64 | { |
---|
| 65 | max=edge_property_defaults[E_COLOR]; |
---|
| 66 | min=edge_property_defaults[E_COLOR]; |
---|
| 67 | } |
---|
| 68 | |
---|
[28] | 69 | if(edge==INVALID) |
---|
| 70 | { |
---|
| 71 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
| 72 | { |
---|
[31] | 73 | double w=(*actual_map)[i]; |
---|
| 74 | |
---|
[28] | 75 | Gdk::Color color; |
---|
| 76 | if(max!=min) |
---|
| 77 | { |
---|
| 78 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 79 | } |
---|
| 80 | else |
---|
| 81 | { |
---|
| 82 | color.set_rgb_p (0, 100, 0); |
---|
| 83 | } |
---|
| 84 | edgesmap[i]->property_fill_color_gdk().set_value(color); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | else |
---|
[27] | 88 | { |
---|
[28] | 89 | Gdk::Color color; |
---|
[31] | 90 | |
---|
| 91 | double w=(*actual_map)[edge]; |
---|
| 92 | |
---|
[28] | 93 | if(max!=min) |
---|
| 94 | { |
---|
| 95 | color.set_rgb_p (0, 100*(w-min)/(max-min), 0); |
---|
| 96 | } |
---|
| 97 | else |
---|
| 98 | { |
---|
| 99 | color.set_rgb_p (0, 100, 0); |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | edgesmap[edge]->property_fill_color_gdk().set_value(color); |
---|
[27] | 103 | } |
---|
| 104 | return 0; |
---|
| 105 | }; |
---|
| 106 | |
---|
[28] | 107 | int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge) |
---|
[27] | 108 | { |
---|
| 109 | //the number in the map will be written on the edge |
---|
[40] | 110 | //EXCEPT when the name of the map is Default, because |
---|
[27] | 111 | //in that case empty string will be written, because |
---|
| 112 | //that is the deleter map |
---|
| 113 | |
---|
[28] | 114 | if(edge==INVALID) |
---|
[27] | 115 | { |
---|
[28] | 116 | for (EdgeIt i(g); i!=INVALID; ++i) |
---|
[27] | 117 | { |
---|
[31] | 118 | if(mapname!="Default") |
---|
[28] | 119 | { |
---|
[35] | 120 | edgemap_to_edit=mapname; |
---|
[28] | 121 | double number=(*(mapstorage.edgemap_storage)[mapname])[i]; |
---|
| 122 | int length=1; |
---|
| 123 | //if number is smaller than one, length would be negative, or invalid |
---|
| 124 | if(number>=1) |
---|
| 125 | { |
---|
| 126 | length=(int)(floor(log(number)/log(10)))+1; |
---|
| 127 | } |
---|
| 128 | int maxpos=(int)(pow(10,length-1)); |
---|
| 129 | int strl=length+1+RANGE; |
---|
| 130 | char * str=new char[strl]; |
---|
| 131 | str[length]='.'; |
---|
| 132 | str[strl]='\0'; |
---|
| 133 | |
---|
| 134 | for(int j=0;j<strl;j++) |
---|
| 135 | { |
---|
| 136 | if(j!=length) |
---|
| 137 | { |
---|
[36] | 138 | if((number-(int)number)>ALMOST_ONE) |
---|
| 139 | { |
---|
| 140 | number=round(number); |
---|
| 141 | } |
---|
[28] | 142 | int digit=(int)(number/maxpos); |
---|
| 143 | str[j]=(digit+'0'); |
---|
| 144 | number-=digit*maxpos; |
---|
| 145 | number*=10; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | edgetextmap[i]->property_text().set_value(str); |
---|
| 150 | } |
---|
| 151 | else |
---|
| 152 | { |
---|
[35] | 153 | edgemap_to_edit=""; |
---|
[28] | 154 | edgetextmap[i]->property_text().set_value(""); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | { |
---|
[31] | 161 | if(mapname!="Default") |
---|
[28] | 162 | { |
---|
| 163 | double number=(*(mapstorage.edgemap_storage)[mapname])[edge]; |
---|
[27] | 164 | int length=1; |
---|
| 165 | //if number is smaller than one, length would be negative, or invalid |
---|
| 166 | if(number>=1) |
---|
| 167 | { |
---|
| 168 | length=(int)(floor(log(number)/log(10)))+1; |
---|
| 169 | } |
---|
| 170 | int maxpos=(int)(pow(10,length-1)); |
---|
| 171 | int strl=length+1+RANGE; |
---|
| 172 | char * str=new char[strl]; |
---|
| 173 | str[length]='.'; |
---|
| 174 | str[strl]='\0'; |
---|
| 175 | |
---|
| 176 | for(int j=0;j<strl;j++) |
---|
| 177 | { |
---|
| 178 | if(j!=length) |
---|
| 179 | { |
---|
[36] | 180 | if((number-(int)number)>ALMOST_ONE) |
---|
| 181 | { |
---|
| 182 | number=round(number); |
---|
| 183 | } |
---|
[27] | 184 | int digit=(int)(number/maxpos); |
---|
| 185 | str[j]=(digit+'0'); |
---|
| 186 | number-=digit*maxpos; |
---|
| 187 | number*=10; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | |
---|
[28] | 191 | edgetextmap[edge]->property_text().set_value(str); |
---|
[27] | 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
[28] | 195 | edgetextmap[edge]->property_text().set_value(""); |
---|
[27] | 196 | } |
---|
[28] | 197 | |
---|
[27] | 198 | } |
---|
[28] | 199 | |
---|
[27] | 200 | return 0; |
---|
[28] | 201 | |
---|
[27] | 202 | }; |
---|