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