def makeGraph(self, data, *args, **kw): start = time.time() # Evaluate all the preferences self.prefs = evalPrefs(*args, **kw) prefs = self.prefs if DEBUG: print "makeGraph time 1", time.time() - start start = time.time() if prefs.has_key('text_image'): self.makeTextGraph(str(prefs['text_image'])) return # Evaluate the number of plots and their requested layout metadata = prefs.get('metadata', {}) plot_grid = prefs.get('plot_grid', '1:1') nx = int(plot_grid.split(':')[0]) ny = int(plot_grid.split(':')[1]) nPlots = nx * ny if nPlots == 1: if not isinstance(data, list): data = [data] if not isinstance(metadata, list): metadata = [metadata] else: if not isinstance(data, list): #return S_ERROR('Single data for multiplot graph') print 'Single data for multiplot graph' return if not isinstance(metadata, list): metaList = [] for _ in range(nPlots): metaList.append(metadata) metadata = metaList # Initialize plot data graphData = [] plot_prefs = [] for i in range(nPlots): plot_prefs.append(evalPrefs(prefs, metadata[i])) gdata = GraphData(data[i]) if i == 0: plot_type = plot_prefs[i]['plot_type'] if plot_prefs[i].has_key('sort_labels'): reverse = plot_prefs[i].get('reverse_labels', False) gdata.sortLabels(plot_prefs[i]['sort_labels'], reverse_order=reverse) if plot_prefs[i].has_key('limit_labels'): if plot_prefs[i]['limit_labels'] > 0: gdata.truncateLabels(plot_prefs[i]['limit_labels']) if plot_prefs[i].has_key('cumulate_data'): gdata.makeCumulativeGraph() plot_title = plot_prefs[i].get('plot_title', '') if plot_title != "NoTitle": begin = '' end = '' if plot_prefs[i].has_key( 'starttime') and plot_prefs[i].has_key('endtime'): begin = to_timestamp(plot_prefs[i]['starttime']) end = to_timestamp(plot_prefs[i]['endtime']) elif gdata.key_type == "time": begin = gdata.min_key end = gdata.max_key if begin and end: time_title = add_time_to_title(begin, end) if plot_title: plot_title += ":" plot_prefs[i]['plot_title'] = plot_title + ' ' + time_title graphData.append(gdata) # Do not make legend for the plot with non-string keys (except for PieGraphs) if not graphData[0].subplots and graphData[ 0].key_type != 'string' and not plot_type == 'PieGraph': prefs['legend'] = False if prefs['legend'] and graphData[ 0].key_type != 'string' and plot_type == 'PieGraph': graphData[0].initialize(key_type='string') legend = Legend(graphData[0], None, prefs) self.figure = Figure() # Make Water Mark image = prefs.get('watermark', None) self.drawWaterMark(image) legend_ax, plot_axes = self.layoutFigure(legend) if DEBUG: print "makeGraph time layout", time.time() - start start = time.time() # Make plots for i in range(nPlots): plot_type = plot_prefs[i]['plot_type'] try: exec "import %s" % plot_type except ImportError, x: print "Failed to import graph type %s: %s" % (plot_type, str(x)) return None ax = plot_axes[i] plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" % (plot_type, plot_type)) plot.draw()
def makeGraph(self, data, *args, **kw): start = time.time() # Evaluate all the preferences self.prefs = evalPrefs(*args, **kw) prefs = self.prefs if DEBUG: print("makeGraph time 1", time.time() - start) start = time.time() if "text_image" in prefs: self.makeTextGraph(str(prefs["text_image"])) return # Evaluate the number of plots and their requested layout metadata = prefs.get("metadata", {}) plot_grid = prefs.get("plot_grid", "1:1") nx = int(plot_grid.split(":")[0]) ny = int(plot_grid.split(":")[1]) nPlots = nx * ny if nPlots == 1: if not isinstance(data, list): data = [data] if not isinstance(metadata, list): metadata = [metadata] else: if not isinstance(data, list): # return S_ERROR('Single data for multiplot graph') print("Single data for multiplot graph") return if not isinstance(metadata, list): metaList = [] for _ in range(nPlots): metaList.append(metadata) metadata = metaList # Initialize plot data graphData = [] plot_prefs = [] for i in range(nPlots): plot_prefs.append(evalPrefs(prefs, metadata[i])) gdata = GraphData(data[i]) if i == 0: plot_type = plot_prefs[i]["plot_type"] if "sort_labels" in plot_prefs[i]: reverse = plot_prefs[i].get("reverse_labels", False) gdata.sortLabels(plot_prefs[i]["sort_labels"], reverse_order=reverse) if "limit_labels" in plot_prefs[i]: if plot_prefs[i]["limit_labels"] > 0: gdata.truncateLabels(plot_prefs[i]["limit_labels"]) if "cumulate_data" in plot_prefs[i]: gdata.makeCumulativeGraph() plot_title = plot_prefs[i].get("plot_title", "") if plot_title != "NoTitle": begin = "" end = "" if "starttime" in plot_prefs[i] and "endtime" in plot_prefs[i]: begin = to_timestamp(plot_prefs[i]["starttime"]) end = to_timestamp(plot_prefs[i]["endtime"]) elif gdata.key_type == "time": begin = gdata.min_key end = gdata.max_key if begin and end: time_title = add_time_to_title(begin, end) if plot_title: plot_title += ":" plot_prefs[i]["plot_title"] = plot_title + " " + time_title graphData.append(gdata) # Do not make legend for the plot with non-string keys (except for PieGraphs) if not graphData[0].subplots and graphData[ 0].key_type != "string" and not plot_type == "PieGraph": prefs["legend"] = False if prefs["legend"] and graphData[ 0].key_type != "string" and plot_type == "PieGraph": graphData[0].initialize(key_type="string") legend = Legend(graphData[0], None, prefs) self.figure = Figure() # Make Water Mark image = prefs.get("watermark", None) self.drawWaterMark(image) legend_ax, plot_axes = self.layoutFigure(legend) if DEBUG: print("makeGraph time layout", time.time() - start) start = time.time() # Make plots for i in range(nPlots): plot_type = plot_prefs[i]["plot_type"] try: # TODO: Remove when we moved to python3 exec("import %s" % plot_type) except ImportError: print("Trying to use python like import") try: exec("from . import %s" % plot_type) except ImportError as x: print("Failed to import graph type %s: %s" % (plot_type, str(x))) return None ax = plot_axes[i] plot = eval("%s.%s(graphData[i],ax,plot_prefs[i])" % (plot_type, plot_type)) plot.draw() if DEBUG: print("makeGraph time plots", time.time() - start) start = time.time() # Make legend if legend_ax: legend.setAxes(legend_ax) legend.draw() if DEBUG: print("makeGraph time legend", time.time() - start) start = time.time()