def _pre_bar_draw(self, cr): """ Calculate where each bar will be draw, and then call _draw_bar to draw it. """ for multiplier, item in enumerate(changes_list): curr_x_pos = self.bar_draw["bars_distance"] + \ (self.bar_draw["bars_distance"] * multiplier) + \ (self.bar_draw["bar_width"] * multiplier) bar_height = self._draw_bar(cr, self.currselection[item], colors_from_file()[item], curr_x_pos) self._write_bar_text(cr, "%.1f%%" % self.percent[item], bar_height, curr_x_pos)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA import gtk import cairo import gobject from umit.inventory.TLBase import colors_from_file PI = 3.1415926535897931 colors = colors_from_file() (VERTICAL, HORIZONTAL) = range(2) (LINEGRAPH, AREAGRAPH) = range(2) class InteractiveGraph(gtk.Widget): """ Timeline Graph. """ def __init__(self, data, start_points, line_filter, connector=None, y_label='', x_label='', graph_label='', descr_label='', vdiv_labels=None, graph_type=LINEGRAPH, hdivs=5, balloons=True, startup_animation=True, progressive_selection_effect=True, draw_dashed_vert=False, draw_solid_vert=False,
def _update_graph(self, obj, range_start, range_end): """ New selection, grab changes by category for selection timerange and do everything needed to draw new selection. """ if range_start is None and range_end is None: # no selection self.noselection = True self.total = self._changes_sum_in_selection(self.currselection) self.multiplier = { } for key, value in self.emptygraph()[0].items(): self.multiplier[key] = abs(value - self.currselection[key]) / \ self.piece_cut self.newcolor = EMPTY_COLOR self.percent, self.newselection = self.emptygraph() return self.noselection = False categories = self.datagrabber.get_categories() data = { } # grab changes by category in current selection for key in categories: c = self.datagrabber.timerange_changes_count_generic(range_start, range_end, key, self.datagrabber.inventory, self.datagrabber.hostaddr) data[categories[key][1]] = c data_keys = data.keys() for item in changes_list: if item not in data_keys: data[item] = 0 # changes sum self.total = self._changes_sum_in_selection(data) # calculate bars height based on their amount of changes bars_height = { } for key, value in data.items(): if self.total == 0: bars_height[key] = 0 else: bars_height[key] = ((value * self.bar_draw["bars_y_area"]) / \ float(self.total)) if not self.total: # range without changes was selected self.total = self._changes_sum_in_selection(self.currselection) self.percent = { } self.multiplier = { } for key, value in data.items(): if not self.total: # present and previous selection have no changes self.percent[key] = 0.0 else: self.percent[key] = (float(data[key])/self.total) * 100 # calculate increment needed to complete this bar animation self.multiplier[key] = abs(bars_height[key] - \ self.currselection[key]) / self.piece_cut # get new color more_changes = self._category_with_more_changes(bars_height) if more_changes.values()[0] == 0: # no changes in current selection newcolor = EMPTY_COLOR color_from = newcolor[0] color_to = newcolor[1] else: color_name = more_changes.keys()[0] color_from = colors_from_file()[color_name] color_to = gradient_colors_from_file()[color_name] self.newcolor = (color_from, color_to) self.newselection = bars_height # set new selection, this will start
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA import gtk import cairo import gobject from umit.inventory.TLBase import colors_from_file PI = 3.1415926535897931 colors = colors_from_file() (VERTICAL, HORIZONTAL) = range(2) (LINEGRAPH, AREAGRAPH) = range(2) class InteractiveGraph(gtk.Widget): """ Timeline Graph. """ def __init__(self, data, start_points, line_filter, connector=None, y_label='',