def test_TimeSeries_equal_list_color(self): values = range(0,100) series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series1.color = 'white' series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series2.color = 'white' self.assertEqual(series1, series2)
def test_TimeSeries_equal_list_color(self): values = list(range(0,100)) series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series1.color = 'white' series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series2.color = 'white' self.assertEqual(series1, series2)
def test_TimeSeries_equal_list_color_bad2(self): values = range(0,100) series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series1.color = 'white' with self.assertRaises(AssertionError): self.assertEqual(series1, series2)
def test_TimeSeries_equal_list_color_bad2(self): values = list(range(0,100)) series1 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series2 = TimeSeries("collectd.test-db.load.value", 0, len(values), 1, values) series1.color = 'white' with self.assertRaises(AssertionError): self.assertEqual(series1, series2)
def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'): if not width: width = self.lineWidth self.ctx.set_line_width(width) originalWidth = width width = float(int(width) % 2) / 2 if dash: self.ctx.set_dash(dash, 1) else: self.ctx.set_dash([], 0) self.ctx.set_line_cap({ 'butt': cairo.LINE_CAP_BUTT, 'round': cairo.LINE_CAP_ROUND, 'square': cairo.LINE_CAP_SQUARE, }[linecap]) self.ctx.set_line_join({ 'miter': cairo.LINE_JOIN_MITER, 'round': cairo.LINE_JOIN_ROUND, 'bevel': cairo.LINE_JOIN_BEVEL, }[linejoin]) # stack the values if self.areaMode == 'stacked': total = [] for series in self.data: for i in range(len(series)): if len(total) <= i: total.append(0) if series[i] is not None: original = series[i] series[i] += total[i] total[i] += original self.data = reverse_sort(self.data) # setup the clip region self.ctx.set_line_width(1.0) self.ctx.rectangle(self.area['xmin'], self.area['ymin'], self.area['xmax'] - self.area['xmin'], self.area['ymax'] - self.area['ymin']) self.ctx.clip() self.ctx.set_line_width(originalWidth) if self.params.get('areaAlpha') and self.areaMode == 'first': alphaSeries = TimeSeries(None, self.data[0].start, self.data[0].end, self.data[0].step, [x for x in self.data[0]]) alphaSeries.xStep = self.data[0].xStep alphaSeries.color = self.data[0].color try: alphaSeries.options['alpha'] = float(self.params['areaAlpha']) except ValueError: pass self.data.insert(0, alphaSeries) for series in self.data: if series.options.has_key( 'lineWidth' ): # adjusts the lineWidth of this line if option is set on the series self.ctx.set_line_width(series.options['lineWidth']) if series.options.has_key( 'dashed'): # turn on dashing if dashed option set self.ctx.set_dash([series.options['dashed']], 1) else: self.ctx.set_dash([], 0) x = float(self.area['xmin']) + (self.lineWidth / 2.0) y = float(self.area['ymin']) self.setColor(series.color, series.options.get('alpha') or 1.0) fromNone = True for value in series: if value is None and self.params.get('drawNullAsZero'): value = 0.0 if value is None: if not fromNone and self.areaMode != 'none': #Close off and fill area before unknown interval self.ctx.line_to(x, self.area['ymax']) self.ctx.close_path() self.ctx.fill() x += series.xStep fromNone = True else: y = self.area['ymax'] - ( (float(value) - self.yBottom) * self.yScaleFactor) if y < 0: y = 0 if series.options.has_key('drawAsInfinite') and value > 0: self.ctx.move_to(x, self.area['ymax']) self.ctx.line_to(x, self.area['ymin']) self.ctx.stroke() x += series.xStep continue if self.lineMode == 'staircase': if fromNone: if self.areaMode != 'none': self.ctx.move_to(x, self.area['ymax']) self.ctx.line_to(x, y) else: self.ctx.move_to(x, y) else: self.ctx.line_to(x, y) x += series.xStep self.ctx.line_to(x, y) elif self.lineMode == 'slope': if fromNone: if self.areaMode != 'none': self.ctx.move_to(x, self.area['ymax']) self.ctx.line_to(x, y) else: self.ctx.move_to(x, y) x += series.xStep self.ctx.line_to(x, y) fromNone = False if self.areaMode != 'none': self.ctx.line_to(x, self.area['ymax']) self.ctx.close_path() self.ctx.fill() if self.areaMode == 'first': self.areaMode = 'none' #This ensures only the first line is drawn as area else: self.ctx.stroke() self.ctx.set_line_width( originalWidth) # return to the original line width if series.options.has_key( 'dash' ): # if we changed the dash setting before, change it back now if dash: self.ctx.set_dash(dash, 1) else: self.ctx.set_dash([], 0)
def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'): if not width: width = self.lineWidth self.ctx.set_line_width(width) originalWidth = width width = float(int(width) % 2) / 2 if dash: self.ctx.set_dash(dash,1) else: self.ctx.set_dash([],0) self.ctx.set_line_cap({ 'butt' : cairo.LINE_CAP_BUTT, 'round' : cairo.LINE_CAP_ROUND, 'square' : cairo.LINE_CAP_SQUARE, }[linecap]) self.ctx.set_line_join({ 'miter' : cairo.LINE_JOIN_MITER, 'round' : cairo.LINE_JOIN_ROUND, 'bevel' : cairo.LINE_JOIN_BEVEL, }[linejoin]) # stack the values if self.areaMode == 'stacked': total = [] for series in self.data: for i in range(len(series)): if len(total) <= i: total.append(0) if series[i] is not None: original = series[i] series[i] += total[i] total[i] += original self.data = reverse_sort(self.data) # setup the clip region self.ctx.set_line_width(1.0) self.ctx.rectangle(self.area['xmin'], self.area['ymin'], self.area['xmax'] - self.area['xmin'], self.area['ymax'] - self.area['ymin']) self.ctx.clip() self.ctx.set_line_width(originalWidth) if self.params.get('areaAlpha') and self.areaMode == 'first': alphaSeries = TimeSeries(None, self.data[0].start, self.data[0].end, self.data[0].step, [x for x in self.data[0]]) alphaSeries.xStep = self.data[0].xStep alphaSeries.color = self.data[0].color try: alphaSeries.options['alpha'] = float(self.params['areaAlpha']) except ValueError: pass self.data.insert(0, alphaSeries) for series in self.data: if series.options.has_key('lineWidth'): # adjusts the lineWidth of this line if option is set on the series self.ctx.set_line_width(series.options['lineWidth']) if series.options.has_key('dashed'): # turn on dashing if dashed option set self.ctx.set_dash([ series.options['dashed'] ],1) else: self.ctx.set_dash([], 0) x = float(self.area['xmin']) + (self.lineWidth / 2.0) y = float(self.area['ymin']) self.setColor( series.color, series.options.get('alpha') or 1.0) fromNone = True for value in series: if value is None and self.params.get('drawNullAsZero'): value = 0.0 if value is None: if not fromNone and self.areaMode != 'none': #Close off and fill area before unknown interval self.ctx.line_to(x, self.area['ymax']) self.ctx.close_path() self.ctx.fill() x += series.xStep fromNone = True else: y = self.area['ymax'] - ((float(value) - self.yBottom) * self.yScaleFactor) if y < 0: y = 0 if series.options.has_key('drawAsInfinite') and value > 0: self.ctx.move_to(x, self.area['ymax']) self.ctx.line_to(x, self.area['ymin']) self.ctx.stroke() x += series.xStep continue if self.lineMode == 'staircase': if fromNone: if self.areaMode != 'none': self.ctx.move_to(x,self.area['ymax']) self.ctx.line_to(x,y) else: self.ctx.move_to(x,y) else: self.ctx.line_to(x,y) x += series.xStep self.ctx.line_to(x,y) elif self.lineMode == 'slope': if fromNone: if self.areaMode != 'none': self.ctx.move_to(x,self.area['ymax']) self.ctx.line_to(x,y) else: self.ctx.move_to(x,y) x += series.xStep self.ctx.line_to(x,y) fromNone = False if self.areaMode != 'none': self.ctx.line_to(x, self.area['ymax']) self.ctx.close_path() self.ctx.fill() if self.areaMode == 'first': self.areaMode = 'none' #This ensures only the first line is drawn as area else: self.ctx.stroke() self.ctx.set_line_width(originalWidth) # return to the original line width if series.options.has_key('dash'): # if we changed the dash setting before, change it back now if dash: self.ctx.set_dash(dash,1) else: self.ctx.set_dash([],0)