ladanyi@53: #include "graph_displayer_canvas.h" ladanyi@53: #include "broken_edge.h" hegyi@28: #include hegyi@28: hegyi@28: hegyi@28: int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node) hegyi@28: { hegyi@31: Graph::NodeMap * actual_map; hegyi@48: double min, max; hegyi@31: if(mapname=="Default") hegyi@31: { hegyi@48: min=node_property_defaults[N_RADIUS]; hegyi@48: max=node_property_defaults[N_RADIUS]; ladanyi@53: actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_RADIUS]); hegyi@31: } hegyi@31: else hegyi@31: { hegyi@48: min=mapstorage.minOfNodeMap(mapname); hegyi@48: max=mapstorage.maxOfNodeMap(mapname); hegyi@31: actual_map=(mapstorage.nodemap_storage)[mapname]; hegyi@31: } hegyi@31: hegyi@28: if(node==INVALID) hegyi@28: { ladanyi@53: for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) hegyi@28: { hegyi@48: double v=abs((*actual_map)[i]); hegyi@48: int w; hegyi@48: if(min==max) hegyi@48: { hegyi@48: w=(int)(node_property_defaults[N_RADIUS]); hegyi@48: } hegyi@48: else hegyi@48: { hegyi@48: w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS)); hegyi@48: } hegyi@28: if(w>=0) hegyi@28: { hegyi@28: double x1, y1, x2, y2; hegyi@31: x1=nodesmap[i]->property_x1().get_value(); hegyi@31: x2=nodesmap[i]->property_x2().get_value(); hegyi@31: y1=nodesmap[i]->property_y1().get_value(); hegyi@31: y2=nodesmap[i]->property_y2().get_value(); hegyi@28: nodesmap[i]->property_x1().set_value((x1+x2)/2-w); hegyi@28: nodesmap[i]->property_x2().set_value((x1+x2)/2+w); hegyi@28: nodesmap[i]->property_y1().set_value((y1+y2)/2-w); hegyi@28: nodesmap[i]->property_y2().set_value((y1+y2)/2+w); hegyi@28: } hegyi@28: } hegyi@28: } hegyi@28: else hegyi@28: { hegyi@31: //I think only new nodes use this case hegyi@31: // int w=(int)(*actual_map)[node]; hegyi@31: int w=(int)(node_property_defaults[N_RADIUS]); hegyi@28: if(w>=0) hegyi@28: { hegyi@28: double x1, y1, x2, y2; hegyi@31: x1=nodesmap[node]->property_x1().get_value(); hegyi@31: x2=nodesmap[node]->property_x2().get_value(); hegyi@31: y1=nodesmap[node]->property_y1().get_value(); hegyi@31: y2=nodesmap[node]->property_y2().get_value(); hegyi@28: nodesmap[node]->property_x1().set_value((x1+x2)/2-w); hegyi@28: nodesmap[node]->property_x2().set_value((x1+x2)/2+w); hegyi@28: nodesmap[node]->property_y1().set_value((y1+y2)/2-w); hegyi@28: nodesmap[node]->property_y2().set_value((y1+y2)/2+w); hegyi@28: } hegyi@28: } hegyi@28: return 0; hegyi@28: }; hegyi@28: hegyi@28: int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node) hegyi@28: { hegyi@28: hegyi@28: //function maps the range of the maximum and hegyi@28: //the minimum of the nodemap to the range of hegyi@28: //green in RGB hegyi@28: hegyi@31: Graph::NodeMap * actual_map; hegyi@31: if(mapname=="Default") hegyi@31: { ladanyi@53: actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_COLOR]); hegyi@31: } hegyi@31: else hegyi@31: { hegyi@31: actual_map=(mapstorage.nodemap_storage)[mapname]; hegyi@31: } hegyi@31: hegyi@31: double max, min; hegyi@31: hegyi@31: if(mapname!="Default") hegyi@31: { hegyi@31: max=mapstorage.maxOfNodeMap(mapname); hegyi@31: min=mapstorage.minOfNodeMap(mapname); hegyi@31: } hegyi@31: else hegyi@31: { hegyi@31: max=node_property_defaults[N_COLOR]; hegyi@31: min=node_property_defaults[N_COLOR]; hegyi@31: } hegyi@31: hegyi@31: hegyi@28: if(node==INVALID) hegyi@28: { hegyi@28: ladanyi@53: for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) hegyi@28: { hegyi@28: Gdk::Color color; hegyi@31: hegyi@31: double w=(*actual_map)[i]; hegyi@31: hegyi@28: if(max!=min) hegyi@28: { hegyi@28: color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: color.set_rgb_p (0, 0, 100); hegyi@28: } hegyi@28: hegyi@28: nodesmap[i]->property_fill_color_gdk().set_value(color); hegyi@28: } hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: Gdk::Color color; hegyi@31: hegyi@31: double w=(*actual_map)[node]; hegyi@31: hegyi@28: if(max!=min) hegyi@28: { hegyi@28: color.set_rgb_p (0, 0, 100*(w-min)/(max-min)); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: color.set_rgb_p (0, 0, 100); hegyi@28: } hegyi@28: hegyi@28: nodesmap[node]->property_fill_color_gdk().set_value(color); hegyi@28: } hegyi@28: return 0; hegyi@28: }; hegyi@28: hegyi@28: int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node) hegyi@28: { hegyi@28: hegyi@28: //the number in the map will be written on the node hegyi@28: //EXCEPT when the name of the map is Text, because hegyi@28: //in that case empty string will be written, because hegyi@28: //that is the deleter map hegyi@31: hegyi@36: Graph::NodeMap * actual_map=NULL; hegyi@35: if(mapname!="Default") hegyi@31: { hegyi@31: actual_map=(mapstorage.nodemap_storage)[mapname]; hegyi@31: } hegyi@28: hegyi@28: if(node==INVALID) hegyi@28: { ladanyi@53: for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) hegyi@28: { hegyi@31: if(mapname!="Default") hegyi@28: { hegyi@35: nodemap_to_edit=mapname; hegyi@31: double number=(*actual_map)[i]; hegyi@45: hegyi@45: std::ostringstream ostr; hegyi@45: ostr << number; hegyi@45: hegyi@45: nodetextmap[i]->property_text().set_value(ostr.str()); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@35: nodemap_to_edit=""; hegyi@28: nodetextmap[i]->property_text().set_value(""); hegyi@28: } hegyi@28: } hegyi@28: } hegyi@28: else hegyi@28: { hegyi@31: if(mapname!="Default") hegyi@28: { hegyi@31: double number=(*actual_map)[node]; hegyi@45: hegyi@45: std::ostringstream ostr; hegyi@45: ostr << number; hegyi@45: hegyi@45: nodetextmap[node]->property_text().set_value(ostr.str()); hegyi@28: } hegyi@28: else hegyi@28: { hegyi@28: nodetextmap[node]->property_text().set_value(""); hegyi@28: } hegyi@28: } hegyi@28: return 0; hegyi@28: };