Browse Source

Add show_{x,y}_guides options fixes #29

pull/58/head
Florian Mounier 12 years ago
parent
commit
fb1cac78f9
  1. 8
      pygal/config.py
  2. 12
      pygal/css/graph.css
  3. 8
      pygal/graph/dot.py
  4. 20
      pygal/graph/graph.py

8
pygal/config.py

@ -57,7 +57,7 @@ class Key(object):
@property @property
def is_numeric(self): def is_numeric(self):
return self.type == int return self.type in (int, float)
@property @property
def is_string(self): def is_string(self):
@ -134,6 +134,12 @@ class Config(object):
height = Key( height = Key(
600, int, "Look", "Graph height") 600, int, "Look", "Graph height")
show_x_guides = Key(False, bool, "Look",
"Set to true to always show x guide lines")
show_y_guides = Key(True, bool, "Look",
"Set to false to hide y guide lines")
show_dots = Key(True, bool, "Look", "Set to false to remove dots") show_dots = Key(True, bool, "Look", "Set to false to remove dots")
dots_size = Key(2.5, float, "Look", "Radius of the dots") dots_size = Key(2.5, float, "Look", "Radius of the dots")

12
pygal/css/graph.css

@ -75,15 +75,17 @@
opacity: 0; opacity: 0;
} }
{{ id }}.horizontal .axis.always_show .guide.line,
{{ id }}.vertical .axis.always_show .guide.line {
opacity: 1 !important;
}
{{ id }}.axis.y .guides:hover .guide.line, {{ id }}.axis.y .guides:hover .guide.line,
{{ id }}.axis.y2 .guides:hover .guide.line, {{ id }}.axis.y2 .guides:hover .guide.line,
{{ id }}.line-graph .axis.x .guides:hover .guide.line, {{ id }}.axis.x .guides:hover .guide.line {
{{ id }}.gauge-graph .axis.x .guides:hover .guide.line,
{{ id }}.stackedline-graph .axis.x .guides:hover .guide.line,
{{ id }}.xy-graph .axis.x .guides:hover .guide.line {
opacity: 1; opacity: 1;
} }
I
{{ id }}.axis .guides:hover text { {{ id }}.axis .guides:hover text {
opacity: 1; opacity: 1;
} }

8
pygal/graph/dot.py

@ -32,10 +32,10 @@ class Dot(Graph):
_adapters = [positive] _adapters = [positive]
def _axes(self): # def _axes(self):
"""Draw axes""" # """Draw axes"""
self._x_axis(False) # self._x_axis(False)
self._y_axis(False) # self._y_axis(False)
def dot(self, serie_node, serie, r_max): def dot(self, serie_node, serie, r_max):
"""Draw a dot line""" """Draw a dot line"""

20
pygal/graph/graph.py

@ -116,11 +116,13 @@ class Graph(BaseGraph):
self.svg.node(text, 'tspan', class_='label') self.svg.node(text, 'tspan', class_='label')
self.svg.node(text, 'tspan', class_='value') self.svg.node(text, 'tspan', class_='value')
def _x_axis(self, draw_axes=True): def _x_axis(self):
"""Make the x axis: labels and guides""" """Make the x axis: labels and guides"""
if not self._x_labels: if not self._x_labels:
return return
axis = self.svg.node(self.nodes['plot'], class_="axis x") axis = self.svg.node(self.nodes['plot'], class_="axis x%s" % (
' always_show' if self.show_x_guides else ''
))
truncation = self.truncate_label truncation = self.truncate_label
if not truncation: if not truncation:
if self.x_label_rotation or len(self._x_labels) <= 1: if self.x_label_rotation or len(self._x_labels) <= 1:
@ -134,7 +136,7 @@ class Graph(BaseGraph):
truncation = reverse_text_len( truncation = reverse_text_len(
available_space, self.label_font_size) available_space, self.label_font_size)
if 0 not in [label[1] for label in self._x_labels] and draw_axes: if 0 not in [label[1] for label in self._x_labels]:
self.svg.node(axis, 'path', self.svg.node(axis, 'path',
d='M%f %f v%f' % (0, 0, self.view.height), d='M%f %f v%f' % (0, 0, self.view.height),
class_='line') class_='line')
@ -162,7 +164,6 @@ class Graph(BaseGraph):
guides = self.svg.node(axis, class_='guides') guides = self.svg.node(axis, class_='guides')
x = self.view.x(position) x = self.view.x(position)
y = self.view.height + 5 y = self.view.height + 5
if draw_axes:
last_guide = (self._y_2nd_labels and label == lastlabel) last_guide = (self._y_2nd_labels and label == lastlabel)
self.svg.node( self.svg.node(
guides, 'path', guides, 'path',
@ -186,7 +187,9 @@ class Graph(BaseGraph):
if self._x_2nd_labels: if self._x_2nd_labels:
secondary_ax = self.svg.node( secondary_ax = self.svg.node(
self.nodes['plot'], class_="axis x x2") self.nodes['plot'], class_="axis x x2%s" % (
' always_show' if self.show_x_guides else ''
))
for label, position in self._x_2nd_labels: for label, position in self._x_2nd_labels:
major = label in x_labels_major major = label in x_labels_major
if not (self.show_minor_x_labels or major): if not (self.show_minor_x_labels or major):
@ -206,14 +209,15 @@ class Graph(BaseGraph):
text.attrib['transform'] = "rotate(%d %f %f)" % ( text.attrib['transform'] = "rotate(%d %f %f)" % (
-self.x_label_rotation, x, y) -self.x_label_rotation, x, y)
def _y_axis(self, draw_axes=True): def _y_axis(self):
"""Make the y axis: labels and guides""" """Make the y axis: labels and guides"""
if not self._y_labels or not self.show_y_labels: if not self._y_labels or not self.show_y_labels:
return return
axis = self.svg.node(self.nodes['plot'], class_="axis y") axis = self.svg.node(self.nodes['plot'], class_="axis y")
if 0 not in [label[1] for label in self._y_labels] and draw_axes: if (0 not in [label[1] for label in self._y_labels] and
self.show_y_guides):
self.svg.node( self.svg.node(
axis, 'path', axis, 'path',
d='M%f %f h%f' % (0, self.view.height, self.view.width), d='M%f %f h%f' % (0, self.view.height, self.view.width),
@ -228,7 +232,7 @@ class Graph(BaseGraph):
y = self.view.y(position) y = self.view.y(position)
if not y: if not y:
continue continue
if draw_axes: if self.show_y_guides:
self.svg.node( self.svg.node(
guides, 'path', guides, 'path',
d='M%f %f h%f' % (0, y, self.view.width), d='M%f %f h%f' % (0, y, self.view.width),

Loading…
Cancel
Save