Browse Source

Add inline css + css tests

pull/98/head
Florian Mounier 11 years ago
parent
commit
0a481165f0
  1. 2
      pygal/graph/datey.py
  2. 27
      pygal/svg.py
  3. 26
      pygal/test/test_config.py

2
pygal/graph/datey.py

@ -51,7 +51,7 @@ class DateY(XY):
def _todate(self, d): def _todate(self, d):
""" Converts a number to a date """ """ Converts a number to a date """
currDateTime = self._offset + datetime.timedelta(seconds=d or 0) currDateTime = self._offset + datetime.timedelta(seconds=d or 0)
return currDateTime.strftime( self.x_label_format ) return currDateTime.strftime(self.x_label_format)
def _tonumber(self, d): def _tonumber(self, d):
""" Converts a date to a number """ """ Converts a date to a number """

27
pygal/svg.py

@ -74,18 +74,21 @@ class Svg(object):
etree.PI( etree.PI(
u('xml-stylesheet'), u('href="%s"' % css))) u('xml-stylesheet'), u('href="%s"' % css)))
else: else:
if not os.path.exists(css): if css.startswith('inline:'):
css = os.path.join( css_text = css[len('inline:'):]
os.path.dirname(__file__), 'css', css) else:
with io.open(css, encoding='utf-8') as f: if not os.path.exists(css):
css_text = template( css = os.path.join(
f.read(), os.path.dirname(__file__), 'css', css)
style=self.graph.config.style, with io.open(css, encoding='utf-8') as f:
colors=colors, css_text = template(
font_sizes=self.graph.config.font_sizes(), f.read(),
id=self.id) style=self.graph.config.style,
if not self.graph.pretty_print: colors=colors,
css_text = minify_css(css_text) font_sizes=self.graph.config.font_sizes(),
id=self.id)
if not self.graph.pretty_print:
css_text = minify_css(css_text)
all_css.append(css_text) all_css.append(css_text)
self.node( self.node(
self.defs, 'style', type='text/css').text = '\n'.join(all_css) self.defs, 'style', type='text/css').text = '\n'.join(all_css)

26
pygal/test/test_config.py

@ -288,3 +288,29 @@ def test_include_x_axis(Chart):
chart.include_x_axis = True chart.include_x_axis = True
q = chart.render_pyquery() q = chart.render_pyquery()
assert '0.0' in q(yaxis).map(texts) assert '0.0' in q(yaxis).map(texts)
def test_css(Chart):
css = "{{ id }}text { fill: #bedead; }\n"
css_file = '/tmp/pygal_custom_style.css'
with open(css_file, 'w') as f:
f.write(css)
config = Config()
config.css.append(css_file)
chart = Chart(config)
chart.add('/', [10, 1, 5])
svg = chart.render().decode('utf-8')
assert '#bedead' in svg
def test_inline_css(Chart):
css = "{{ id }}text { fill: #bedead; }\n"
config = Config()
config.css.append('inline:' + css)
chart = Chart(config)
chart.add('/', [10, 1, 5])
svg = chart.render().decode('utf-8')
assert '#bedead' in svg

Loading…
Cancel
Save