From 0abfd02b3139fe752acd6fb0670dc8c084bdf922 Mon Sep 17 00:00:00 2001 From: Chris Davis Date: Fri, 20 Nov 2009 00:35:35 -0600 Subject: [PATCH] fixed yMax and yMin parameters, adding a clip region to avoid graph border-crossing anomalies, convenience fix for negative url params --- webapp/graphite/render/glyph.py | 27 ++++++++++++++++++++++----- webapp/graphite/render/views.py | 4 ++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/webapp/graphite/render/glyph.py b/webapp/graphite/render/glyph.py index 473c2cafe..c101d1915 100644 --- a/webapp/graphite/render/glyph.py +++ b/webapp/graphite/render/glyph.py @@ -307,7 +307,7 @@ def drawGraph(self,**params): self.params = params #Now to setup our LineGraph specific options - self.lineWidth = float( params.get('lineWidth', 2.0) ) + self.lineWidth = float( params.get('lineWidth', 1.2) ) self.lineMode = params.get('lineMode','slope').lower() assert self.lineMode in self.validLineModes, "Invalid line mode!" self.areaMode = params.get('areaMode','none').lower() @@ -402,6 +402,12 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'): 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(width) + for series in self.data: if series.options.has_key('lineWidth'): # adjusts the lineWidth of this line if option is set on the series @@ -452,6 +458,7 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'): else: self.ctx.line_to(x,y) + x += series.xStep self.ctx.line_to(x,y) @@ -461,7 +468,6 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'): 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) @@ -521,6 +527,12 @@ def setupYAxis(self): if yMaxValue is None: yMaxValue = 1.0 + if 'yMax' in self.params: + yMaxValue = self.params['yMax'] + + if 'yMin' in self.params: + yMinvalue = self.params['yMin'] + yVariance = yMaxValue - yMinValue if yVariance == 0: @@ -550,12 +562,17 @@ def setupYAxis(self): self.yBottom = self.yStep * math.floor( yMinValue / self.yStep ) #start labels at the greatest multiple of yStep <= yMinValue self.yTop = self.yStep * math.ceil( yMaxValue / self.yStep ) #Extend the top of our graph to the lowest yStep multiple >= yMaxValue - if 'yMin' in self.params and self.params['yMin'] < self.yBottom: - self.yBottom = self.params['yMin'] - if 'yMax' in self.params and self.params['yMax'] > self.yTop: + if 'yMax' in self.params: self.yTop = self.params['yMax'] + if 'yMin' in self.params: + self.yBottom = self.params['yMin'] + self.ySpan = self.yTop - self.yBottom + if self.ySpan == 0: + self.yTop += 1 + self.ySpan += 1 + self.graphHeight = self.area['ymax'] - self.area['ymin'] self.yScaleFactor = float(self.graphHeight) / float(self.ySpan) diff --git a/webapp/graphite/render/views.py b/webapp/graphite/render/views.py index 64aa344c8..dfa6cbac1 100644 --- a/webapp/graphite/render/views.py +++ b/webapp/graphite/render/views.py @@ -158,9 +158,9 @@ def parseOptions(request): for opt in graphClass.customizable: if opt in queryParams: val = queryParams[opt] - if val.isdigit() and opt not in ('fgcolor','bgcolor','fontColor'): + if (val.isdigit() or (val.startswith('-') and val[1:].isdigit())) and opt not in ('fgcolor','bgcolor','fontColor'): val = int(val) - elif '.' in val and val.replace('.','',1).isdigit(): + elif '.' in val and (val.replace('.','',1).isdigit() or (val.startswith('-') and val[1:].replace('.','',1).isdigit())): val = float(val) elif val.lower() in ('true','false'): val = eval( val.lower().capitalize() )