Browse Source

Reduce scale and add fill option

pull/8/head
Florian Mounier 13 years ago
parent
commit
8c5237f359
  1. 8
      demo/moulinrouge/__init__.py
  2. 2
      out.py
  3. 6
      pygal/graph/base.py
  4. 3
      pygal/graph/radar.py
  5. 1
      pygal/svg.py

8
demo/moulinrouge/__init__.py

@ -36,8 +36,8 @@ def create_app():
def index():
return render_template('index.jinja2')
@app.route("/all-<type>-<style>.svg")
def all_svg(type, style):
@app.route("/all-<type>-<style>(fill=<fill>).svg")
def all_svg(type, style, fill):
data = random.randrange(1, 10)
order = random.randrange(1, 10)
max = 10 ** order
@ -45,6 +45,7 @@ def create_app():
config = Config()
config.width = 600
config.height = 400
config.fill = fill == 'True'
config.style = styles[style]
if type != 'Pie':
config.x_labels = [random_label() for i in range(data)]
@ -68,8 +69,9 @@ def create_app():
@app.route("/all")
def all():
width, height = 600, 400
svgs = [url_for('all_svg', type=type, style=style)
svgs = [url_for('all_svg', type=type, style=style, fill=fill)
for style in styles
for fill in (False, True)
for type in ('Bar', 'Line', 'XY', 'Pie', 'StackedBar',
'HorizontalBar', 'HorizontalStackedBar', 'Radar')]
return render_template('svgs.jinja2',

2
out.py

@ -88,7 +88,7 @@ config.x_labels = (
'black', 'red', 'blue', 'yellow', 'orange', 'green', 'white')
radar = Radar(config)
radar.add('test', [1, 4, 1, 5, 7, 2, 5])
radar.add('test2', [10, 2, 0, 5, 1, 9, 4])
radar.add('test2', [10, 2, 7, 5, 1, 9, 4])
radar.title = "Radar test"
with open('out-radar.svg', 'w') as f:

6
pygal/graph/base.py

@ -23,12 +23,12 @@ class BaseGraph(object):
return object.__getattribute__(self.config, attr)
return object.__getattribute__(self, attr)
def _pos(self, min_, max_, scale):
def _pos(self, min_, max_, scale, min_scale=4, max_scale=20):
order = round(log10(max(abs(min_), abs(max_)))) - 1
while (max_ - min_) / float(10 ** order) < 4:
while (max_ - min_) / float(10 ** order) < min_scale:
order -= 1
step = float(10 ** order)
while (max_ - min_) / step > 20:
while (max_ - min_) / step > max_scale:
step *= 2.
positions = set()
if self.x_start_at_zero:

3
pygal/graph/radar.py

@ -70,7 +70,8 @@ class Radar(Line):
x_step = len(self.series[0].values)
delta = 2 * pi / float(len(self.x_labels))
self._x_pos = [.5 * pi - i * delta for i in range(x_step)]
self._y_pos = self._pos(self._box.ymin, self._box.ymax, self.y_scale
self._y_pos = self._pos(
self._box.ymin, self._box.ymax, self.y_scale, max_scale=8
) if not self.y_labels else map(int, self.y_labels)
self._x_labels = self.x_labels and zip(self.x_labels, self._x_pos)
self._y_labels = zip(map(str, self._y_pos), self._y_pos)

1
pygal/svg.py

@ -2,7 +2,6 @@
import os
from lxml import etree
from pygal.util import template
from math import cos, sin, pi
class Svg(object):

Loading…
Cancel
Save