Browse Source

Quick hack for addressing issue #30.

svg.py: Added the viewBox height by 20 so that I can put X-Axis title
there.
config.py: Added xtitle and ytitle for giving title name for the
respective axes.
graph.py: Added functions _x_title() and _y_title() which adds title
for the respective axes.
pull/38/head
Sibi 12 years ago
parent
commit
3b79dcca1c
  1. 8
      pygal/config.py
  2. 30
      pygal/graph/graph.py
  3. 2
      pygal/svg.py

8
pygal/config.py

@ -104,6 +104,14 @@ class Config(object):
None, str, "Look",
"Graph title.", "Leave it to None to disable title.")
xtitle = Key(
None, str, "Look",
"Graph X-Axis title.", "Leave it to None to disable X-Axis title.")
ytitle = Key(
None, str, "Look",
"Graph Y-Axis title.", "Leave it to None to disable Y-Axis title.")
width = Key(
800, int, "Look", "Graph width")

30
pygal/graph/graph.py

@ -43,6 +43,8 @@ class Graph(BaseGraph):
self._axes()
self._legend()
self._title()
self._x_title()
self._y_title()
def _axes(self):
"""Draw axes"""
@ -363,6 +365,34 @@ class Graph(BaseGraph):
y=i * (self.title_font_size + 10)
).text = title_line
def _x_title(self):
"""Make the X-Axis title"""
if self.xtitle:
title_node = self.svg.node(
self.nodes['graph'],
class_="titles")
self.svg.node(
title_node, 'text', class_='title',
x= (self.width / 2) + 80,
y= self.height + 10
).text = self.xtitle
def _y_title(self):
"""Make the Y-Axis title"""
if self.ytitle:
title_node = self.svg.node(
self.nodes['graph'],
class_="titles")
text = self.svg.node(
title_node, 'text', class_='title',
x= 40,
y= self.height / 2,
)
text.text = self.ytitle
text.attrib['transform'] = "rotate(%d %f %f)" % (
-90, 40, self.height / 2)
def _serie(self, serie):
"""Make serie node"""
return dict(

2
pygal/svg.py

@ -192,7 +192,7 @@ class Svg(object):
self.add_styles()
self.add_scripts()
self.root.set(
'viewBox', '0 0 %d %d' % (self.graph.width, self.graph.height))
'viewBox', '0 0 %d %d' % (self.graph.width, self.graph.height + 20))
if self.graph.explicit_size:
self.root.set('width', str(self.graph.width))
self.root.set('height', str(self.graph.height))

Loading…
Cancel
Save