Skip to content

Commit 6e8b8ca

Browse files
committed
further integration of pyexcel-chart with sphinx
1 parent 87cb7be commit 6e8b8ca

File tree

3 files changed

+66
-88
lines changed

3 files changed

+66
-88
lines changed

docs/source/conf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import os
33
import sys
4-
import pdb;pdb.set_trace()
54
sys.path.append(os.path.abspath('.'))
65
extensions = [
76
'sphinx.ext.autodoc',

docs/source/pyexcel_sphinx_integration.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,11 @@
4141
class PygalDirective(Directive):
4242
"""Execute the given python file and puts its result in the document."""
4343
required_arguments = 0
44-
optional_arguments = 2
4544
final_argument_whitespace = True
4645
has_content = True
4746

4847
def run(self):
49-
width, height = map(int, self.arguments[:2]) if len(
50-
self.arguments) >= 2 else (600, 400)
51-
if len(self.arguments) == 1:
52-
self.render_fix = bool(self.arguments[0])
53-
elif len(self.arguments) == 3:
54-
self.render_fix = bool(self.arguments[2])
55-
else:
56-
self.render_fix = False
57-
self.content = list(self.content)
5848
content = list(self.content)
59-
if self.render_fix:
60-
content[-1] = 'rv = ' + content[-1]
6149
code = '\n'.join(content)
6250
scope = {'pyexcel': pyexcel}
6351
try:
@@ -69,19 +57,16 @@ def run(self):
6957
'An exception as occured during code parsing:'
7058
' \n %s' % format_exc(), type='ERROR', source='/',
7159
level=3)]
72-
if self.render_fix:
73-
rv = scope['rv']
74-
else:
75-
chart = None
76-
for key, value in scope.items():
77-
if isinstance(value, BytesIO):
78-
chart = value
79-
#self.content.append(key + '.render()')
80-
break
81-
if chart is None:
82-
return [docutils.nodes.system_message(
83-
'No instance of graph found', level=3,
84-
type='ERROR', source='/')]
60+
chart = None
61+
for key, value in scope.items():
62+
if isinstance(value, BytesIO):
63+
chart = value
64+
#self.content.append(key + '.render()')
65+
break
66+
if chart is None:
67+
return [docutils.nodes.system_message(
68+
'No instance of graph found', level=3,
69+
type='ERROR', source='/')]
8570

8671
try:
8772
svg = "%s" % chart.getvalue().decode('utf-8')

docs/source/usage.rst

Lines changed: 56 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Usage
22
================================================================================
33

4-
There are currently four type of data layouts for rendering charts.
4+
There are currently four type of data layouts for rendering charts.
55

66
1 Simple Layout
77
--------------------------------------------------------------------------------
@@ -14,7 +14,7 @@ Pie chart
1414
.. csv-table::
1515
:file: ../../pie.csv
1616

17-
17+
1818
Here is the source code using pyexcel
1919

2020
.. pyexcel-code::
@@ -36,13 +36,15 @@ Box chart
3636
.. image:: _static/pbox.svg
3737
:width: 600px
3838
:height: 400px
39-
40-
Here is the source code using pyexcel::
4139

42-
>>> import pyexcel as p
43-
>>> title = 'V8 benchmark results'
44-
>>> p.save_as(file_name='box.csv', dest_chart_type='box',
45-
... dest_file_name='pbox.svg', dest_title=title)
40+
Here is the source code using pyexcel:
41+
42+
.. pyexcel-code::
43+
44+
title = 'V8 benchmark results'
45+
sheet = pyexcel.get_sheet(file_name='box.csv')
46+
svg = sheet.plot(chart_type='box',
47+
title=title, width=600, height=400, explicit_size=True)
4648

4749
2 Complex layout
4850
--------------------------------------------------------------------------------
@@ -58,50 +60,43 @@ Line
5860
.. csv-table::
5961
:file: ../../line.csv
6062

61-
.. image:: _static/pline.svg
62-
:width: 600px
63-
:height: 400px
64-
65-
Here is the source code using pyexcel::
63+
Here is the source code using pyexcel:
64+
65+
.. pyexcel-code::
6666

67-
>>> import pyexcel as p
68-
>>> title = 'Browser usage evolution (in %)'
69-
>>> p.save_as(file_name='line.csv', dest_chart_type='line',
70-
... dest_file_name='pline.svg', dest_title=title)
67+
title = 'Browser usage evolution (in %)'
68+
sheet = pyexcel.get_sheet(file_name='line.csv')
69+
svg = sheet.plot(chart_type='line',
70+
title=title, width=600, height=400, explicit_size=True)
7171

7272
Dot chart
7373
********************************************************************************
7474

7575
.. csv-table::
7676
:file: ../../radar.csv
7777

78-
.. image:: _static/pdot.svg
79-
:width: 600px
80-
:height: 400px
78+
Here is the source code using pyexcel:
8179

82-
Here is the source code using pyexcel::
80+
.. pyexcel-code::
8381

84-
>>> import pyexcel as p
85-
>>> title = 'V8 benchmark results'
86-
>>> p.save_as(file_name='radar.csv', dest_chart_type='dot',
87-
... dest_file_name='pdot.svg', dest_title=title)
82+
title = 'V8 benchmark results'
83+
sheet = pyexcel.get_sheet(file_name='radar.csv')
84+
svg = sheet.plot(chart_type='dot',
85+
title=title, width=600, height=400, explicit_size=True)
8886

8987
Funnel chart
9088
********************************************************************************
9189

9290
.. csv-table::
9391
:file: ../../funnel.csv
9492

95-
.. image:: _static/pfunnel.svg
96-
:width: 600px
97-
:height: 400px
98-
93+
9994
Here is the source code using pyexcel::
10095

101-
>>> import pyexcel as p
102-
>>> title = 'V8 benchmark results'
103-
>>> p.save_as(file_name='funnel.csv', dest_chart_type='funnel',
104-
... dest_file_name='pfunnel.svg', dest_title=title)
96+
title = 'V8 benchmark results'
97+
sheet = p.get_sheet(file_name='funnel.csv')
98+
svg = sheet.plot(chart_type='funnel',
99+
title=title, width=600, height=400, explicit_size=True)
105100

106101
Radar chart
107102
********************************************************************************
@@ -111,16 +106,14 @@ Radar chart
111106
:file: ../../radar.csv
112107

113108

114-
.. image:: _static/pradar.svg
115-
:width: 600px
116-
:height: 400px
117-
118109
Here is the source code using pyexcel::
119110

120-
>>> import pyexcel as p
121-
>>> title = 'V8 benchmark results'
122-
>>> p.save_as(file_name='radar.csv', dest_chart_type='radar',
123-
... dest_file_name='pradar.svg', dest_title=title)
111+
.. pyexcel-code::
112+
113+
title = 'V8 benchmark results'
114+
sheet = pyexcel.get_sheet(file_name='radar.csv')
115+
svg = sheet.plot(chart_type='radar',
116+
title=title, width=600, height=400, explicit_size=True)
124117

125118
Histogram
126119
--------------------------------------------------------------------------------
@@ -131,15 +124,14 @@ in first, second and third columns.
131124
.. csv-table::
132125
:file: ../../histogram_wide_bars.csv
133126

134-
.. image:: _static/phistogram_wide_bars.svg
135-
:width: 600px
136-
:height: 400px
137-
138-
Here is the source code using pyexcel::
139127

140-
>>> import pyexcel as p
141-
>>> p.save_as(file_name='histogram_wide_bars.csv', dest_chart_type='histogram',
142-
... dest_file_name='phistogram_wide_bars.svg')
128+
Here is the source code using pyexcel:
129+
130+
.. pyexcel-code::
131+
132+
sheet = pyexcel.get_sheet(file_name='histogram_wide_bars.csv')
133+
svg = sheet.plot(chart_type='histogram',
134+
width=600, height=400, explicit_size=True)
143135

144136

145137
In order to draw multiple histogram on the same chart, you will need to use a
@@ -148,12 +140,15 @@ Book, each sheet of which become a histogram. Here is how you can draw multiple
148140
.. image:: _static/phistogram.svg
149141
:width: 600px
150142
:height: 400px
151-
152-
Here is the source code using pyexcel::
153143

154-
>>> import pyexcel as p
155-
>>> p.save_book_as(file_name='histogram.xlsx', dest_chart_type='histogram',
156-
... dest_file_name='phistogram.svg')
144+
Here is the source code using pyexcel
145+
146+
147+
.. pyexcel-code::
148+
149+
book = pyexcel.get_book(file_name='histogram.xlsx')
150+
svg = book.plot(chart_type='histogram',
151+
width=600, height=400, explicit_size=True)
157152

158153
XY
159154
--------------------------------------------------------------------------------
@@ -165,12 +160,11 @@ in individual sheets.
165160
.. csv-table::
166161
:file: ../../radar.csv
167162

168-
.. image:: _static/pxy.svg
169-
:width: 600px
170-
:height: 400px
171-
172-
Here is the source code using pyexcel::
173163

174-
>>> import pyexcel as p
175-
>>> p.save_book_as(file_name='xy.xlsx', dest_chart_type='xy',
176-
... dest_file_name='pxy.svg')
164+
Here is the source code using pyexcel
165+
166+
.. pyexcel-code::
167+
168+
book = pyexcel.get_book(file_name='xy.xlsx')
169+
svg = book.plot(chart_type='xy',
170+
width=600, height=400, explicit_size=True)

0 commit comments

Comments
 (0)