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