Skip to content

Commit

Permalink
fixed yMax and yMin parameters, adding a clip region to avoid graph b…
Browse files Browse the repository at this point in the history
…order-crossing anomalies, convenience fix for negative url params
  • Loading branch information
cdavis committed Nov 20, 2009
1 parent 08956bd commit 0abfd02
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions webapp/graphite/render/glyph.py
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions webapp/graphite/render/views.py
Expand Up @@ -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() )
Expand Down

0 comments on commit 0abfd02

Please sign in to comment.