diff --git a/pygal/config.py b/pygal/config.py index 00b2b10..e813cfa 100644 --- a/pygal/config.py +++ b/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") diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 18f23d6..b349be7 100644 --- a/pygal/graph/graph.py +++ b/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( diff --git a/pygal/svg.py b/pygal/svg.py index 927d868..06b2487 100644 --- a/pygal/svg.py +++ b/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))