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. 34
      pygal/graph/graph.py

8
pygal/config.py

@ -57,7 +57,7 @@ class Key(object):
@property
def is_numeric(self):
return self.type == int
return self.type in (int, float)
@property
def is_string(self):
@ -134,6 +134,12 @@ class Config(object):
height = Key(
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")
dots_size = Key(2.5, float, "Look", "Radius of the dots")

12
pygal/css/graph.css

@ -75,15 +75,17 @@
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.y2 .guides:hover .guide.line,
{{ id }}.line-graph .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 {
{{ id }}.axis.x .guides:hover .guide.line {
opacity: 1;
}
I
{{ id }}.axis .guides:hover text {
opacity: 1;
}

8
pygal/graph/dot.py

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

34
pygal/graph/graph.py

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

Loading…
Cancel
Save