Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fill area from y-zero instead of from bottom of graph #249

Closed
wants to merge 2 commits into from

2 participants

@piotr1212

When drawing graphs with negative values the area was filled from the bottom of the graph (ymax). In my opionion it should be filled from the 0 on the Y axis. This patch filles the area from y-0, works with mixed posive and negative values and works with second y axis.

@obfuscurity
Owner

If this does what I think it does, I'm very happy to see this fixed. Would you mind fixing the conflicts and I'll take a closer look?

:boom: :cherries: :sparkles:

@piotr1212

I see I mixed up two commits. I'm still new to git I think I messed up with branching. I will clean it up and let you know.

@obfuscurity
Owner

If it's easier, start a new clean PR and link to it from this one. Thanks!

@piotr1212

I've created a new clean pr #308 this one can be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 30, 2012
  1. @piotr1212

    simple hack to be able to render bar type chart

    piotr1212 authored
    graphType=bar
Commits on Mar 17, 2013
  1. @piotr1212
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 9 deletions.
  1. +33 −9 webapp/graphite/render/glyph.py
View
42 webapp/graphite/render/glyph.py
@@ -505,7 +505,7 @@ class LineGraph(Graph):
'yStepRight', 'rightWidth', 'rightColor', 'rightDashed', \
'leftWidth', 'leftColor', 'leftDashed', 'xFormat', 'minorY', \
'hideYAxis', 'uniqueLegend', 'vtitleRight')
- validLineModes = ('staircase','slope','connected')
+ validLineModes = ('staircase','slope','connected','bar')
validAreaModes = ('none','first','all','stacked')
validPieModes = ('maximum', 'minimum', 'average')
@@ -858,7 +858,13 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'):
if not fromNone:
self.ctx.line_to(x, y)
if 'stacked' in series.options: #Close off and fill area before unknown interval
- self.fillAreaAndClip(x, y, startX)
+ if self.secondYAxis:
+ if 'secondYAxis' in series.options:
+ self.fillAreaAndClip(x, y, startX, self.getYCoord(0, "right"))
+ else:
+ self.fillAreaAndClip(x, y, startX, self.getYCoord(0, "left"))
+ else:
+ self.fillAreaAndClip(x, y, startX, self.getYCoord(0))
x += series.xStep
fromNone = True
@@ -910,7 +916,14 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'):
fromNone = False
if 'stacked' in series.options:
- self.fillAreaAndClip(x-series.xStep, y, startX)
+ if self.secondYAxis:
+ if 'secondYAxis' in series.options:
+ areaYFrom = self.getYCoord(0, "right")
+ else:
+ areaYFrom = self.getYCoord(0, "left")
+ else:
+ areaYFrom = self.getYCoord(0)
+ self.fillAreaAndClip(x-series.xStep, y, startX, areaYFrom)
else:
self.ctx.stroke()
@@ -921,22 +934,33 @@ def drawLines(self, width=None, dash=None, linecap='butt', linejoin='miter'):
else:
self.ctx.set_dash([],0)
- def fillAreaAndClip(self, x, y, startX=None):
+ def fillAreaAndClip(self, x, y, startX=None, areaYFrom=None):
startX = (startX or self.area['xmin'])
+ areaYFrom = (areaYFrom or self.area['ymax'])
pattern = self.ctx.copy_path()
- self.ctx.line_to(x, self.area['ymax']) # bottom endX
- self.ctx.line_to(startX, self.area['ymax']) # bottom startX
+ # fill
+ self.ctx.line_to(x, areaYFrom) # bottom endX
+ self.ctx.line_to(startX, areaYFrom) # bottom startX
self.ctx.close_path()
self.ctx.fill()
+ # clip above y axis
self.ctx.append_path(pattern)
- self.ctx.line_to(x, self.area['ymax']) # bottom endX
- self.ctx.line_to(self.area['xmax'], self.area['ymax']) # bottom right
+ self.ctx.line_to(x, areaYFrom) # yZero endX
+ self.ctx.line_to(self.area['xmax'], areaYFrom) # yZero right
self.ctx.line_to(self.area['xmax'], self.area['ymin']) # top right
self.ctx.line_to(self.area['xmin'], self.area['ymin']) # top left
+ self.ctx.line_to(self.area['xmin'], areaYFrom) # yZero left
+ self.ctx.line_to(startX, areaYFrom) # yZero startX
+
+ # clip below y axis
+ self.ctx.line_to(x, areaYFrom) # yZero endX
+ self.ctx.line_to(self.area['xmax'], areaYFrom) # yZero right
+ self.ctx.line_to(self.area['xmax'], self.area['ymax']) # bottom right
self.ctx.line_to(self.area['xmin'], self.area['ymax']) # bottom left
- self.ctx.line_to(startX, self.area['ymax']) # bottom startX
+ self.ctx.line_to(self.area['xmin'], areaYFrom) # yZero left
+ self.ctx.line_to(startX, areaYFrom) # yZero startX
self.ctx.close_path()
self.ctx.clip()
Something went wrong with that request. Please try again.