Browse Source

Merge branch 'master' of github.com:Kozea/pygal

Conflicts:
	demo/moulinrouge/tests.py
pull/109/merge
Florian Mounier 11 years ago
parent
commit
106fdc0233
  1. 10
      demo/moulinrouge/tests.py
  2. 4
      pygal/config.py
  3. 24
      pygal/graph/line.py
  4. 8
      pygal/test/test_line.py
  5. 2
      tox.ini

10
demo/moulinrouge/tests.py

@ -429,4 +429,14 @@ def get_test_routes(app):
pie.add(str(i), 1)
return pie.render_response()
@app.route('/test/major_dots')
def test_major_dots():
line = Line(x_labels_major_every=3, show_only_major_dots=True)
line.add('test', range(12))
line.x_labels = [
'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5',
'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11']
line.x_labels_major = ['lol3']
return line.render_response()
return filter(lambda x: x.startswith('test'), locals())

4
pygal/config.py

@ -140,6 +140,10 @@ class Config(MetaConfig('ConfigBase', (object,), {})):
show_dots = Key(True, bool, "Look", "Set to false to remove dots")
show_only_major_dots = Key(
False, bool, "Look",
"Set to true to show only major dots according to their majored label")
dots_size = Key(2.5, float, "Look", "Radius of the dots")
stroke = Key(

24
pygal/graph/line.py

@ -67,10 +67,30 @@ class Line(Graph):
points = serie.points
view_values = list(map(self.view, points))
if self.show_dots:
if self.show_only_major_dots:
major_dots_index = []
if self.x_labels:
if self.x_labels_major:
major_dots_index = []
for major in self.x_labels_major:
start = -1
while True:
try:
index = self.x_labels.index(
major, start + 1)
except ValueError:
break
else:
major_dots_index.append(index)
start = index
elif self.x_labels_major_every:
major_dots_index = range(
0, len(self.x_labels), self.x_labels_major_every)
for i, (x, y) in enumerate(view_values):
if None in (x, y):
if None in (x, y) or (self.show_only_major_dots
and i not in major_dots_index):
continue
metadata = serie.metadata.get(i)
classes = []
if x > self.view.width / 2:

8
pygal/test/test_line.py

@ -92,3 +92,11 @@ def test_not_equal_x_labels():
assert len(q(".axis.x")) == 1
assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', '10']
def test_only_major_dots():
line = Line(show_only_major_dots=True, x_labels_major_every=3)
line.add('test', range(12))
line.x_labels = map(str, range(12))
q = line.render_pyquery()
assert len(q(".dots")) == 4

2
tox.ini

@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,py32,py33
envlist = py26,py27,py32,py33,py34
[testenv]
sitepackages=True

Loading…
Cancel
Save