Skip to content

Commit

Permalink
Fix state and add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Apr 26, 2016
1 parent a6e0dcf commit 16642fd
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Changelog
2.1.0
=====

* Bar print value positioning with `print_values_position`. Can be `top`, `center` or `bottom` (thanks @chartique #291) `doc <documentation/configuration/value.html#confidence-intervals>`_
* Confidence intervals (thanks @chartique #292) `doc <documentation/configuration/data.html#print-values-position>`_
* Bar print value positioning with `print_values_position`. Can be `top`, `center` or `bottom` (thanks @chartique #291) `ci doc <documentation/configuration/value.html#confidence-intervals>`_
* Confidence intervals (thanks @chartique #292) `data doc <documentation/configuration/data.html#print-values-position>`_


2.0.12
Expand Down
31 changes: 31 additions & 0 deletions docs/documentation/configuration/rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ see `styles <../styles.html>`_
You can add or replace css/js files in pygal using the `css` and `js` array options.
These lists contain absolute filenames and/or external URI. (Relative filenames are relative to pygal internal files)

All config lists now support the use of ellipsis as an extender. For instance:

.. code-block:: python
config = Config()
config.css.append('style.css')
chart = pygal.Line(config)
can now be replaced with:

.. code-block:: python
chart = pygal.Line(css=(..., 'style.css'))
or if you are still using python from the last decade:

.. code-block:: python
from pygal._compat import _ellipsis
chart = pygal.Line(css=(_ellipsis, 'style.css'))
css
---
Expand All @@ -132,6 +153,16 @@ Css can also specified inline by prepending `inline:` to the css:
css = ['inline:.rect { fill: blue; }']
classes
-------

You can alter pygal svg node classes with the classes option:

.. code-block:: python
chart = pygal.Line(classes=(..., 'flex'))
defs
----

Expand Down
4 changes: 2 additions & 2 deletions docs/documentation/types/line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Basic simple line graph:
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])


Horizontal Line
~~~~~~~~~~~~~~~
Expand All @@ -31,7 +31,7 @@ Same graph but horizontal and with a range of 0-100.
line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3])
line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1])
line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5])
line.range = [0, 100]
line_chart.range = [0, 100]


Stacked
Expand Down
1 change: 1 addition & 0 deletions docs/ext/pygal_sphinx_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def run(self):
try:
exec(code, scope)
except Exception:
print(code)
print_exc()
return [docutils.nodes.system_message(
'An exception as occured during code parsing:'
Expand Down
10 changes: 4 additions & 6 deletions pygal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from pygal.interpolate import INTERPOLATIONS
from pygal.style import DefaultStyle, Style
from pygal.util import mergextend
from pygal import formatters


Expand Down Expand Up @@ -169,12 +168,11 @@ def __call__(self, **kwargs):

def _update(self, kwargs):
"""Update the config with the given dictionary"""
from pygal.util import merge
dir_self_set = set(dir(self))
self.__dict__.update(
dict([
(k, mergextend(v, self.__dict__.get(k, ())))
if getattr(Config, k, Key(*[''] * 4)).type == list
else (k, v) for (k, v) in kwargs.items()
merge(
self.__dict__, dict([
(k, v) for (k, v) in kwargs.items()
if not k.startswith('_') and k in dir_self_set]))

def to_dict(self):
Expand Down
10 changes: 6 additions & 4 deletions pygal/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

"""Class holding state during render"""

from pygal.util import merge


class State(object):

Expand All @@ -30,7 +32,7 @@ class State(object):

def __init__(self, graph, **kwargs):
"""Create the transient state"""
self.__dict__.update(**graph.config.__class__.__dict__)
self.__dict__.update(**graph.config.__dict__)
self.__dict__.update(**graph.__dict__)
self.__dict__.update(**kwargs)
merge(self.__dict__, graph.config.__class__.__dict__)
merge(self.__dict__, graph.config.__dict__)
merge(self.__dict__, graph.__dict__)
merge(self.__dict__, kwargs)
7 changes: 6 additions & 1 deletion pygal/test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from pygal.graph.horizontal import HorizontalGraph
from pygal.graph.dual import Dual
from pygal import formatters
from pygal._compat import u
from pygal._compat import u, _ellipsis
from pygal.test.utils import texts
from tempfile import NamedTemporaryFile

Expand Down Expand Up @@ -337,6 +337,11 @@ def test_css(Chart):
svg = chart.render().decode('utf-8')
assert '#bedead' in svg

chart = Chart(css=(_ellipsis, 'file://' + f.name))
chart.add('/', [10, 1, 5])
svg = chart.render().decode('utf-8')
assert '#bedead' in svg


def test_inline_css(Chart):
"""Test inline css option"""
Expand Down
15 changes: 14 additions & 1 deletion pygal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,20 @@ def coord_abs_project(center, rho, theta):


def mergextend(list1, list2):
if _ellipsis not in list1:
if list1 is None or _ellipsis not in list1:
return list1
index = list1.index(_ellipsis)
return list(list1[:index]) + list(list2) + list(list1[index + 1:])


def merge(dict1, dict2):
from pygal.config import CONFIG_ITEMS, Key
_list_items = [item.name for item in CONFIG_ITEMS if item.type == list]
for key, val in dict2.items():
if isinstance(val, Key):
val = val.value

if key in _list_items:
dict1[key] = mergextend(val, dict1.get(key, ()))
else:
dict1[key] = val

0 comments on commit 16642fd

Please sign in to comment.