Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation on how to contribute new graphs #534

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributing
============


Github
GitHub
======

Submit your bug reports and feature requests to the `github bug tracker <http://github.com/Kozea/pygal/issues>`_.
Expand All @@ -18,7 +18,7 @@ The pygal code tries to respect the `pep8 <https://www.python.org/dev/peps/pep-0
Testing
=======

Before submiting a pull request, please check that all tests still pass.
Before submitting a pull request, please check that all tests still pass.


To do this install ``py.test`` and them run ``py.test`` in the root of your pygal clone:
Expand All @@ -36,3 +36,45 @@ Continuous Integration

The current build status can be seen at our `ymci <https://ymci.kozea.fr/project/view/12>`_


Contributing a New Graph Visualization
======================================

* Fork the pygal repository on GitHub
* Clone your own fork: ``git clone [email protected]:<Your_GH_User>/pygal.git``
* ``cd pygal``
* Create a virtual environment for development: ``python -m venv .pygal_dev``
* Activate the virtual environment ``source .pygal_dev/bin/activate`` (see `PyPA documentation <https://setuptools.pypa.io/en/latest/userguide/development_mode.html>` for how to do that on Windows)
* Install pygal in development mode into the virtual environment ``pip install --editable ".[test]"``

The following steps are illustrated on reusing an existing graph, the Pie Graph. For your new visualization, adapt the names, the respective test code, and the actual visualization code accordingly.

* Add a test ``touch pygal/test/test_mypie.py``. For example, add the following code to it

.. code-block:: python

from pygal import MyPie

def test_donut():
"""Test a donut pie chart"""
chart = MyPie(inner_radius=.3, pretty_print=True)
chart.title = 'Browser usage in February 2012 (in %)'
chart.add('IE', 19.5)
chart.add('Firefox', 36.6)
chart.add('Chrome', 36.3)
chart.add('Safari', 4.5)
chart.add('Opera', 2.3)
chart.render_to_file('/tmp/chart.svg')
assert chart.render()



* Create a new file for your new graph visualization: ``touch pygal/graph/my_viz.py``. (For this example: ``cp pygal/graph/pie.py pygal/graph/mypie.py``.)
* Add an import for your new visualization class to the ``__init__.py`` module. For this example, add ``from pygal.graph.mypie import MyPie`` to the block of imports at the top of this file.
* To manually test your new visualization: ``pytest pygal/test/test_mypie.py``.
* After the test completes, inspect the file that it generated (e.g., via ``open /tmp/chart.svg``) if it looks as intended.


Now, edit the code for the visualization and its respective test.
Once your visualization works as intended run the entire test suite as described above.
Thereafter, send a pull-request to the main branch of the original repository (``Kozea/pygal``).