Author: croberts Date: 2012-10-29 15:34:22 +0000 (Mon, 29 Oct 2012) New Revision: 5523
Modified: trunk/cumin/python/cumin/stat.py trunk/cumin/resources/app.js Log: Laying groundwork for the jqplot charts to be able to display in "stacked" mode rather than overlaid line charts.
Modified: trunk/cumin/python/cumin/stat.py =================================================================== --- trunk/cumin/python/cumin/stat.py 2012-10-24 18:45:46 UTC (rev 5522) +++ trunk/cumin/python/cumin/stat.py 2012-10-29 15:34:22 UTC (rev 5523) @@ -221,7 +221,8 @@ params.append("duration=%s" % self.duration.get(session)) params.append("rpkg=%s" % self.cls._package._name) params.append("rcls=%s" % self.cls._name) - params.append("type=%s" % "reportarea") + if self.chart_type: + params.append("type=%s" % self.chart_type)
for i, stat in enumerate(self.stats): params.append("stat=%s" % stat) @@ -921,6 +922,7 @@ chart = self.get_chart(session, adapter, stats, samples, time_span, max_value, min_value, append, end_seconds_ago) #print "**********\n"+chart.create() chart.graph_div = "%s_chart" % chart.id.replace(".", "_") + chart.stackSeries = self.stackSeries return chart.create()
def get_y_labels(self, absy, intervals, step): @@ -991,6 +993,7 @@ super(AreaChart, self).__init__(app, name, page)
self.alpha = 3 + self.stackSeries = False
def getStatSamples(self, adapter, samples, stat, dur, interval, method, end_seconds_ago, delta): # get more samples than needed to allow chart to clip correctly (explains the + 600) @@ -1113,40 +1116,11 @@ chart.append = self.get_elapsed(session)['value'] return chart
- chart.title.text = "" - chart.title.style = "{text-align: left; font-weight: bold; font-size: 14px;}" - chart.tooltip = {"colour": "#000033", - "background": "#FFFFCC", - "stroke": 1, - "title": "{background-color: #000022; color: #FFFFFF; font-size: 1em;}", - "body": "{font-size: 10px; color: #000000;}" - } - chart.x_axis = XAxis().get_x_axis(duration, end_secs) y_axis, y_axis_right = self.get_y_axis(max_value, min_value) chart.y_axis = y_axis chart.y_axis_right = y_axis_right
- # if we are big enough, add a control slider to pan and zoom - if width > 400: - chart.control.bg_colour = "#DDDDDD" - chart.control.x_axis = XAxis().get_x_axis(self.one_day, 0, tick_height=10) - chart.control.x_axis.labels.colour = "#333333" - chart.control.x_axis.grid_colour = "#FFFFFF" - samples = self.fetch_samples(adapter, self.one_day, 180, "avg", mode, False, stats, end_seconds_ago=0) - self.add_control_points(session, stats, samples) - max_value, min_value = self.get_max_min(session, stats, samples) - self.make_chart_lines(session, chart.control, "area", stats, 1, 0, 0, samples, self.one_day, 0, mode) - chart.control.y_min = max(min_value, 0) - chart.control.y_max = max(max_value-2, 1) - chart.control.slider_low.value = float(self.page.control_min.get(session)) - chart.control.slider_low.colour = "#666666" - chart.control.slider_high.value = float(self.page.control_max.get(session)) - chart.control.slider_high.colour = "#666666" - chart.control.tnow = time() - chart.control.duration = self.one_day - chart.control.end_secs = 0 - #print "sending entire sample set with y_axis.max=%i" % chart.y_axis["max"] return chart
@@ -1179,6 +1153,10 @@ self.add_attribute(self.points)
self.alpha = 1 + self.stackSeries = True + + # removed get_vals method since the new way of rendering stacked charts + # no longer requires a special method of computing the values.
def get_max_min(self, session, stats, samples, time_span, end_seconds_ago): max_value = 0 @@ -1220,22 +1198,6 @@
return max_value, min_value
- def get_vals(self, session, samples, stat, text, duration, end_secs): - tnow = time() - vals = list() - points = self.points.get(session) - - if points: - min_dt = tnow - duration - end_secs - for dt, value, stacked_value in points[stat]: - if value is not None: - vals.append({"dt": secs(dt), "y": stacked_value}) - if secs(dt) < min_dt: - break - - vals.reverse() - return vals - class Points(Attribute): def get_default(self, session): return dict()
Modified: trunk/cumin/resources/app.js =================================================================== --- trunk/cumin/resources/app.js 2012-10-24 18:45:46 UTC (rev 5522) +++ trunk/cumin/resources/app.js 2012-10-29 15:34:22 UTC (rev 5523) @@ -587,6 +587,7 @@ dataContainer['x_axis_values'] = dataContainer['x_axis_values'] .append([ json.x_axis.labels.labels[i].text ]); } + dataContainer['stackSeries'] = json.stackSeries; return dataContainer; }
@@ -649,6 +650,7 @@ } }, series: getSeries(dataContainer), + stackSeries: dataContainer['stackSeries'], seriesColors: ['#009926','#992600','#0036d6','#ffc414','730099','#ff00cc'], seriesDefaults: { lineWidth:1, @@ -751,10 +753,10 @@
// used to let us tweak the contents of the tooltip according to our whim, gets called from highlighter plugin showTooltip function customTooltip = function(str, seriesIndex, pointIndex, plot) { - value = plot.series[seriesIndex]._plotData[pointIndex][1]; + value = plot.series[seriesIndex].data[pointIndex][1]; seriesValues = new Array(); for(i=0; i<plot.series.length; i++) { - series = "<tr><td>" + plot.series[i].label + ": " + plot.series[i]._plotData[pointIndex][1] + "</td></tr>"; + series = "<tr><td>" + plot.series[i].label + ": " + plot.series[i].data[pointIndex][1] + "</td></tr>"; seriesValues.push(series); } str = str.replace(/#allSeries#/,seriesValues.join(""));