Skip to content

Commit 03dad4c

Browse files
committed
making pyexcel-chart as interface plugin
1 parent ca307f4 commit 03dad4c

File tree

11 files changed

+22
-150
lines changed

11 files changed

+22
-150
lines changed

.moban.d/tests/requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{% extends 'tests/requirements.txt.jj2' %}
22
{%block extras %}
33
pyexcel
4+
pyexcel-pygal
45
{%endblock%}

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ language: python
33
notifications:
44
email: false
55
python:
6+
- pypy
67
- 3.6
78
- 3.5
89
- 3.4
910
- 3.3
1011
- 2.7
1112
- 2.6
12-
- pypy
1313
before_install:
1414
- if [[ $TRAVIS_PYTHON_VERSION == "2.6" ]]; then pip install flake8==2.6.2; fi
1515
- if [[ -f min_requirements.txt && "$MINREQ" -eq 1 ]]; then
1616
mv min_requirements.txt requirements.txt ;
1717
fi
18-
- pip install --upgrade setuptools "pip==7.1"
1918
- test ! -f rnd_requirements.txt || pip install --no-deps -r rnd_requirements.txt
2019
- test ! -f rnd_requirements.txt || pip install -r rnd_requirements.txt ;
2120
- pip install -r tests/requirements.txt

docs/source/conf.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
'sphinx.ext.doctest',
1212
'sphinx.ext.intersphinx',
1313
'sphinx.ext.viewcode',
14-
'pyexcel_sphinx_integration',
15-
'sphinxcontrib.excel'
14+
'pyexcel_sphinx_integration'
1615
]
1716

1817
intersphinx_mapping = {
19-
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None)
18+
'pyexcel': ('http://pyexcel.readthedocs.org/en/latest/', None),
2019
}
2120
spelling_word_list_filename = 'spelling_wordlist.txt'
2221
templates_path = ['_templates']

docs/source/index.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
`pyexcel-chart` - Let you focus on data, instead of file formats
22
================================================================================
33

4-
.. note::
5-
6-
It is still under writing. My effort is spent elsewhere. Please star this
7-
project to show your interest
8-
9-
104
:Author: C.W.
115
:Source code: http://github.com/pyexcel/pyexcel-chart.git
126
:Issues: http://github.com/pyexcel/pyexcel-chart/issues
@@ -45,4 +39,4 @@ Content
4539
.. toctree::
4640

4741
charts
48-
usage
42+
usage

pyexcel_chart.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ version: 0.0.1
55
release: 0.0.1
66
file_type: xls
77
dependencies:
8-
- pyexcel>=0.3.4
9-
- pygal>=2.2.3
10-
- six
8+
- pyexcel>=0.5.0
119
description: A wrapper library of pygal to visualize pyexcel data

pyexcel_chart/chart.py

+4-129
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,15 @@
88
:license: New BSD License, see LICENSE for further details
99
"""
1010
import sys
11-
import pygal
1211
from functools import partial
1312

14-
from lml.plugin import PluginInfo, PluginManager
15-
1613
from pyexcel.renderer import Renderer
14+
from lml.plugin import PluginManager
1715

1816

1917
PY2 = sys.version_info[0] == 2
20-
DEFAULT_TITLE = 'pyexcel chart rendered by pygal'
21-
KEYWORD_CHART_TYPE = 'chart_type'
18+
DEFAULT_TITLE = 'pyexce-chart renders'
2219
DEFAULT_CHART_TYPE = 'bar'
23-
CHART_TYPES = dict(
24-
pie='Pie',
25-
box='Box',
26-
line='Line',
27-
bar='Bar',
28-
stacked_bar='StackedBar',
29-
radar='Radar',
30-
dot='Dot',
31-
funnel='Funnel',
32-
xy='XY',
33-
histogram='Histogram')
3420

3521

3622
if PY2:
@@ -39,119 +25,6 @@
3925
from io import BytesIO
4026

4127

42-
class Chart(object):
43-
44-
def __init__(self, cls_name):
45-
self._chart_class = CHART_TYPES.get(cls_name, 'line')
46-
47-
48-
@PluginInfo('chart', tags=['pie', 'box'])
49-
class SimpleLayout(Chart):
50-
51-
def render_sheet(self, sheet, title=DEFAULT_TITLE,
52-
label_y_in_row=0,
53-
**keywords):
54-
params = {}
55-
self.params = {}
56-
if len(sheet.colnames) == 0:
57-
sheet.name_columns_by_row(label_y_in_row)
58-
params.update(keywords)
59-
the_dict = sheet.to_dict()
60-
cls = getattr(pygal, self._chart_class)
61-
instance = cls(title=title, **params)
62-
for key in the_dict:
63-
data_array = [value for value in the_dict[key] if value != '']
64-
instance.add(key, data_array)
65-
chart_content = instance.render()
66-
return chart_content
67-
68-
69-
@PluginInfo('chart',
70-
tags=['line', 'bar', 'stacked_bar', 'radar', 'dot', 'funnel'])
71-
class ComplexLayout(Chart):
72-
73-
def render_sheet(self, sheet, title=DEFAULT_TITLE,
74-
label_x_in_column=0, label_y_in_row=0,
75-
**keywords):
76-
params = {}
77-
self.params = {}
78-
if len(sheet.colnames) == 0:
79-
sheet.name_columns_by_row(label_y_in_row)
80-
if len(sheet.rownames) == 0:
81-
sheet.name_rows_by_column(label_x_in_column)
82-
params['x_labels'] = sheet.rownames
83-
params.update(keywords)
84-
the_dict = sheet.to_dict()
85-
cls = getattr(pygal, self._chart_class)
86-
instance = cls(title=title, **params)
87-
for key in the_dict:
88-
data_array = [value for value in the_dict[key] if value != '']
89-
instance.add(key, data_array)
90-
chart_content = instance.render()
91-
return chart_content
92-
93-
94-
@PluginInfo('chart', tags=['histogram'])
95-
class Histogram(Chart):
96-
def render_sheet(self, sheet, title=DEFAULT_TITLE,
97-
height_in_column=0, start_in_column=1,
98-
stop_in_column=2,
99-
**keywords):
100-
histograms = zip(sheet.column[height_in_column],
101-
sheet.column[start_in_column],
102-
sheet.column[stop_in_column])
103-
cls = getattr(pygal, self._chart_class)
104-
instance = cls(title=title, **keywords)
105-
instance.add(sheet.name, histograms)
106-
chart_content = instance.render()
107-
return chart_content
108-
109-
def render_book(self, book, title=DEFAULT_TITLE,
110-
height_in_column=0, start_in_column=1,
111-
stop_in_column=2,
112-
**keywords):
113-
from pyexcel.book import to_book
114-
cls = getattr(pygal, self._chart_class)
115-
instance = cls(title=title, **keywords)
116-
for sheet in to_book(book):
117-
histograms = zip(sheet.column[height_in_column],
118-
sheet.column[start_in_column],
119-
sheet.column[stop_in_column])
120-
instance.add(sheet.name, histograms)
121-
chart_content = instance.render()
122-
return chart_content
123-
124-
125-
@PluginInfo('chart', tags=['xy'])
126-
class XY(Chart):
127-
128-
def render_sheet(self, sheet, title=DEFAULT_TITLE,
129-
x_in_column=0,
130-
y_in_column=1,
131-
**keywords):
132-
cls = getattr(pygal, self._chart_class)
133-
instance = cls(title=title, **keywords)
134-
points = zip(sheet.column[x_in_column],
135-
sheet.column[y_in_column])
136-
instance.add(sheet.name, points)
137-
chart_content = instance.render()
138-
return chart_content
139-
140-
def render_book(self, book, title=DEFAULT_TITLE,
141-
x_in_column=0,
142-
y_in_column=1,
143-
**keywords):
144-
from pyexcel.book import to_book
145-
cls = getattr(pygal, self._chart_class)
146-
instance = cls(title=title, **keywords)
147-
for sheet in to_book(book):
148-
points = zip(sheet.column[x_in_column],
149-
sheet.column[y_in_column])
150-
instance.add(sheet.name, points)
151-
chart_content = instance.render()
152-
return chart_content
153-
154-
15528
class ChartManager(PluginManager):
15629
def __init__(self):
15730
PluginManager.__init__(self, 'chart')
@@ -164,8 +37,10 @@ def get_a_plugin(self, key, **keywords):
16437
def raise_exception(self, key):
16538
raise Exception("No support for " + key)
16639

40+
16741
MANAGER = ChartManager()
16842

43+
16944
class ChartRenderer(Renderer):
17045

17146
def __init__(self, file_type):

pyexcel_chart/plugin.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from lml.plugin import PluginInfoChain
2+
3+
4+
class ChartPluginChain(PluginInfoChain):
5+
def add_a_plugin(self, submodule=None, **keywords):
6+
return PluginInfoChain.add_a_plugin(
7+
self, 'chart', submodule=submodule, **keywords)

requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
pyexcel>=0.3.4
2-
pygal>=2.2.3
3-
six
1+
pyexcel>=0.5.0

rnd_requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
https://github.com/chfw/lml/archive/master.zip
22
https://github.com/pyexcel/pyexcel-io/archive/v0.4.x.zip
33
https://github.com/pyexcel/pyexcel/archive/master.zip
4+
https://github.com/pyexcel/pyexcel-pygal/archive/master.zip

setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
]
4343

4444
INSTALL_REQUIRES = [
45-
'pyexcel>=0.3.4',
46-
'pygal>=2.2.3',
47-
'six',
45+
'pyexcel>=0.5.0',
4846
]
4947

5048

tests/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
nose
2+
mock;python_version<"3"
23
codecov
34
coverage
45
flake8
56
pyexcel
7+
pyexcel-pygal

0 commit comments

Comments
 (0)