Skip to content

Commit a070d04

Browse files
authored
Merge pull request #637 from seleniumbase/improve-chart-maker
Add the ability to create bar charts and column charts with Chart Maker
2 parents 6b5eaf6 + c0942ee commit a070d04

File tree

9 files changed

+239
-30
lines changed

9 files changed

+239
-30
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ env
2323
venv
2424
sbase
2525
sbase*
26+
seleniumbase_env
27+
seleniumbase_venv
28+
sbase_env
29+
sbase_venv
2630
pyvenv.cfg
2731
.Python
2832
include

examples/chart_maker/ReadMe.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,68 @@
44

55
SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
66
The HighCharts library is used for creating charts.
7-
(Currently only <b>pie charts</b> are supported.)
87

98
**Here's a sample chart:**
109

1110
<a href="https://seleniumbase.io/other/chart_presentation.html"><img width="500" src="https://seleniumbase.io/other/sample_pie_chart.png" title="Screenshot"></a><br>
1211

1312
([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))
1413

15-
Here's how to run the example (a chart in a presentation):
16-
```
14+
Here's how to run the example (multiple charts in a presentation):
15+
16+
```bash
1717
cd examples/chart_maker
1818
pytest my_chart.py
1919
```
2020

21+
(Press the Right Arrow to advance to the next slide in the chart presentation)
22+
2123

2224
### Creating a new chart:
2325

2426
```python
25-
self.create_pie_chart(chart_name=None, title="My Chart")
26-
""" Creates a JavaScript pie chart using "HighCharts". """
27+
self.create_pie_chart(chart_name=None, title="My Chart", libs=True)
28+
""" Creates a JavaScript pie chart using "HighCharts".
29+
@Params
30+
chart_name - If creating multiple charts,
31+
use this to select which one.
32+
title - The title displayed for the chart.
33+
libs - The option to include Chart libraries (JS and CSS files).
34+
Should be set to True (default) for the first time creating
35+
a chart on a web page. If creating multiple charts on
36+
a web page, you no longer need to re-import the libraries
37+
when creating additional charts.
38+
"""
39+
```
40+
41+
```python
42+
self.create_bar_chart(chart_name=None, title="My Chart", libs=True)
43+
""" Creates a JavaScript bar chart using "HighCharts".
44+
@Params
45+
chart_name - If creating multiple charts,
46+
use this to select which one.
47+
title - The title displayed for the chart.
48+
libs - The option to include Chart libraries (JS and CSS files).
49+
Should be set to True (default) for the first time creating
50+
a chart on a web page. If creating multiple charts on
51+
a web page, you no longer need to re-import the libraries
52+
when creating additional charts.
53+
"""
54+
```
55+
56+
```python
57+
self.create_column_chart(chart_name=None, title="My Chart", libs=True)
58+
""" Creates a JavaScript column chart using "HighCharts".
59+
@Params
60+
chart_name - If creating multiple charts,
61+
use this to select which one.
62+
title - The title displayed for the chart.
63+
libs - The option to include Chart libraries (JS and CSS files).
64+
Should be set to True (default) for the first time creating
65+
a chart on a web page. If creating multiple charts on
66+
a web page, you no longer need to re-import the libraries
67+
when creating additional charts.
68+
"""
2769
```
2870

2971
If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.
@@ -87,26 +129,38 @@ self.display_chart(chart_name=None, filename=None):
87129
"""
88130
```
89131

90-
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.
132+
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at the same time.
91133

92134

93135
### Here's an example of using SeleniumBase Chart Maker:
94136

95137
```python
96138
from seleniumbase import BaseCase
97139

98-
99140
class MyChartMakerClass(BaseCase):
100141

101142
def test_chart_maker(self):
143+
self.create_presentation()
144+
102145
self.create_pie_chart(title="Automated Tests")
103146
self.add_data_point("Passed", 7, color="#95d96f")
104147
self.add_data_point("Untested", 2, color="#eaeaea")
105148
self.add_data_point("Failed", 1, color="#f1888f")
106-
self.create_presentation()
107149
self.add_slide(self.extract_chart())
108-
self.begin_presentation()
109150

151+
self.create_bar_chart(title="Code", libs=False)
152+
self.add_data_point("Python", 33, color="Orange")
153+
self.add_data_point("JavaScript", 27, color="Teal")
154+
self.add_data_point("HTML + CSS", 21, color="Purple")
155+
self.add_slide(self.extract_chart())
156+
157+
self.create_column_chart(title="Colors", libs=False)
158+
self.add_data_point("Red", 10, color="Red")
159+
self.add_data_point("Green", 25, color="Green")
160+
self.add_data_point("Blue", 15, color="Blue")
161+
self.add_slide(self.extract_chart())
162+
163+
self.begin_presentation()
110164
```
111165

112166
#### This example is from [my_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/my_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command:

examples/chart_maker/my_chart.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,24 @@
44
class MyChartMakerClass(BaseCase):
55

66
def test_chart_maker(self):
7+
self.create_presentation()
8+
79
self.create_pie_chart(title="Automated Tests")
810
self.add_data_point("Passed", 7, color="#95d96f")
911
self.add_data_point("Untested", 2, color="#eaeaea")
1012
self.add_data_point("Failed", 1, color="#f1888f")
11-
self.create_presentation()
1213
self.add_slide(self.extract_chart())
14+
15+
self.create_bar_chart(title="Code", libs=False)
16+
self.add_data_point("Python", 33, color="Orange")
17+
self.add_data_point("JavaScript", 27, color="Teal")
18+
self.add_data_point("HTML + CSS", 21, color="Purple")
19+
self.add_slide(self.extract_chart())
20+
21+
self.create_column_chart(title="Colors", libs=False)
22+
self.add_data_point("Red", 10, color="Red")
23+
self.add_data_point("Green", 25, color="Green")
24+
self.add_data_point("Blue", 15, color="Blue")
25+
self.add_slide(self.extract_chart())
26+
1327
self.begin_presentation()

help_docs/chart_maker.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,68 @@
44

55
SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
66
The HighCharts library is used for creating charts.
7-
(Currently only <b>pie charts</b> are supported.)
87

98
**Here's a sample chart:**
109

1110
<a href="https://seleniumbase.io/other/chart_presentation.html"><img width="500" src="https://seleniumbase.io/other/sample_pie_chart.png" title="Screenshot"></a><br>
1211

1312
([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))
1413

15-
Here's how to run the example (a chart in a presentation):
16-
```
14+
Here's how to run the example (multiple charts in a presentation):
15+
16+
```bash
1717
cd examples/chart_maker
1818
pytest my_chart.py
1919
```
2020

21+
(Press the Right Arrow to advance to the next slide in the chart presentation)
22+
2123

2224
### Creating a new chart:
2325

2426
```python
25-
self.create_pie_chart(chart_name=None, title="My Chart")
26-
""" Creates a JavaScript pie chart using "HighCharts". """
27+
self.create_pie_chart(chart_name=None, title="My Chart", libs=True)
28+
""" Creates a JavaScript pie chart using "HighCharts".
29+
@Params
30+
chart_name - If creating multiple charts,
31+
use this to select which one.
32+
title - The title displayed for the chart.
33+
libs - The option to include Chart libraries (JS and CSS files).
34+
Should be set to True (default) for the first time creating
35+
a chart on a web page. If creating multiple charts on
36+
a web page, you no longer need to re-import the libraries
37+
when creating additional charts.
38+
"""
39+
```
40+
41+
```python
42+
self.create_bar_chart(chart_name=None, title="My Chart", libs=True)
43+
""" Creates a JavaScript bar chart using "HighCharts".
44+
@Params
45+
chart_name - If creating multiple charts,
46+
use this to select which one.
47+
title - The title displayed for the chart.
48+
libs - The option to include Chart libraries (JS and CSS files).
49+
Should be set to True (default) for the first time creating
50+
a chart on a web page. If creating multiple charts on
51+
a web page, you no longer need to re-import the libraries
52+
when creating additional charts.
53+
"""
54+
```
55+
56+
```python
57+
self.create_column_chart(chart_name=None, title="My Chart", libs=True)
58+
""" Creates a JavaScript column chart using "HighCharts".
59+
@Params
60+
chart_name - If creating multiple charts,
61+
use this to select which one.
62+
title - The title displayed for the chart.
63+
libs - The option to include Chart libraries (JS and CSS files).
64+
Should be set to True (default) for the first time creating
65+
a chart on a web page. If creating multiple charts on
66+
a web page, you no longer need to re-import the libraries
67+
when creating additional charts.
68+
"""
2769
```
2870

2971
If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.
@@ -87,26 +129,38 @@ self.display_chart(chart_name=None, filename=None):
87129
"""
88130
```
89131

90-
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.
132+
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at the same time.
91133

92134

93135
### Here's an example of using SeleniumBase Chart Maker:
94136

95137
```python
96138
from seleniumbase import BaseCase
97139

98-
99140
class MyChartMakerClass(BaseCase):
100141

101142
def test_chart_maker(self):
143+
self.create_presentation()
144+
102145
self.create_pie_chart(title="Automated Tests")
103146
self.add_data_point("Passed", 7, color="#95d96f")
104147
self.add_data_point("Untested", 2, color="#eaeaea")
105148
self.add_data_point("Failed", 1, color="#f1888f")
106-
self.create_presentation()
107149
self.add_slide(self.extract_chart())
108-
self.begin_presentation()
109150

151+
self.create_bar_chart(title="Code", libs=False)
152+
self.add_data_point("Python", 33, color="Orange")
153+
self.add_data_point("JavaScript", 27, color="Teal")
154+
self.add_data_point("HTML + CSS", 21, color="Purple")
155+
self.add_slide(self.extract_chart())
156+
157+
self.create_column_chart(title="Colors", libs=False)
158+
self.add_data_point("Red", 10, color="Red")
159+
self.add_data_point("Green", 25, color="Green")
160+
self.add_data_point("Blue", 15, color="Blue")
161+
self.add_slide(self.extract_chart())
162+
163+
self.begin_presentation()
110164
```
111165

112166
#### This example is from [my_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/my_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command:

help_docs/method_summary.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ self.begin_presentation(name=None, filename=None, show_notes=False, interval=0)
371371

372372
############
373373

374-
self.create_pie_chart(chart_name=None, title=None)
374+
self.create_pie_chart(chart_name=None, title=None, libs=True)
375+
376+
self.create_bar_chart(chart_name=None, title=None, libs=True)
377+
378+
self.create_column_chart(chart_name=None, title=None, libs=True)
375379

376380
self.add_data_point(label, value, color=None, chart_name=None)
377381

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ coverage==5.2.1
4343
brython>=3.8.9
4444
pyotp==2.3.0
4545
boto==2.49.0
46-
cffi==1.14.0
46+
cffi==1.14.1
4747
rich==4.1.0;python_version>="3.6" and python_version<"4.0"
4848
flake8==3.7.9;python_version<"3.5"
4949
flake8==3.8.3;python_version>="3.5"

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def main():
147147
data.append("venv")
148148
data.append("sbase")
149149
data.append("sbase*")
150+
data.append("seleniumbase_env")
151+
data.append("seleniumbase_venv")
152+
data.append("sbase_env")
153+
data.append("sbase_venv")
150154
data.append("pyvenv.cfg")
151155
data.append(".Python")
152156
data.append("include")

0 commit comments

Comments
 (0)