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