Browse Source

ups - default style did not work!

pull/217/head
never-eat-yellow-snow 10 years ago
parent
commit
30dd263826
  1. 13
      pygal/graph/pie.py
  2. 43
      pygal/svg.py

13
pygal/graph/pie.py

@ -32,6 +32,15 @@ class Pie(Graph):
"""Pie graph"""
_adapters = [positive, none_to_zero]
@property
def _format(self):
"""Return the value formatter for this graph"""
def percentage_formatter(y, self=self):
total = sum(map(sum, map(lambda x: x.values, self.series)))
perc = y/total
return '{0:.2%}'.format(perc)
return self.value_formatter or percentage_formatter
def slice(self, serie, start_angle, total):
"""Make a serie slice"""
@ -57,7 +66,7 @@ class Pie(Graph):
else:
angle = 2 * pi * perc
serie_angle += angle
val = '{0:.2%}'.format(perc)
val = self._format(val)
metadata = serie.metadata.get(i)
slice_ = decorate(
self.svg,
@ -77,7 +86,7 @@ class Pie(Graph):
total_perc += perc
if dual:
val = '{0:.2%}'.format(total_perc)
val = self._format(total_perc*total)
self.svg.slice(serie_node,
self.svg.node(slices, class_="big_slice"),
radius * .9, 0, serie_angle,

43
pygal/svg.py

@ -95,31 +95,32 @@ class Svg(object):
css_text = css[len('inline:'):]
else:
if type(css) == str and css.startswith("!"):
css_text = importlib.import_module(css[1:]).data
css_raw = importlib.import_module(css[1:]).data
elif type(css) == str:
if not os.path.exists(css):
css = os.path.join(
os.path.dirname(__file__), 'css', css)
class FontSizes(object):
"""Container for font sizes"""
fs = FontSizes()
for name in dir(self.graph.state):
if name.endswith('_font_size'):
setattr(
fs,
name.replace('_font_size', ''),
('%dpx' % getattr(self.graph, name)))
with io.open(css, encoding='utf-8') as f:
css_text = template(
f.read(),
style=self.graph.style,
colors=colors,
font_sizes=fs,
id=self.id)
css_raw = f.read()
else:
css_text = css.data
css_raw = css.data
class FontSizes(object):
"""Container for font sizes"""
fs = FontSizes()
for name in dir(self.graph.state):
if name.endswith('_font_size'):
setattr(
fs,
name.replace('_font_size', ''),
('%dpx' % getattr(self.graph, name)))
css_text = template(
css_raw,
style=self.graph.style,
colors=colors,
font_sizes=fs,
id=self.id)
if not self.graph.pretty_print:
css_text = minify_css(css_text)
all_css.append(css_text)
@ -134,7 +135,9 @@ class Svg(object):
return dict((k, getattr(self.graph.state, k))
for k in dir(self.graph.config)
if not k.startswith('_') and not hasattr(
getattr(self.graph.config, k), '__call__'))
getattr(self.graph.config, k), '__call__')
and not hasattr(getattr(self.graph.state, k), '__call__')
)
def json_default(o):
if isinstance(o, (datetime, date)):

Loading…
Cancel
Save