Skip to content

Commit 446753e

Browse files
committed
cleaning up bar chart code
1 parent d9836fc commit 446753e

File tree

1 file changed

+9
-17
lines changed
  • bar-charts-bokeh-flask-python-3

1 file changed

+9
-17
lines changed

bar-charts-bokeh-flask-python-3/app.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def chart(bars_count):
1818
bars_count = 1
1919

2020
data = {"days": [], "bugs": [], "costs": []}
21-
for i in range(1, bars_count+1):
21+
for i in range(1, bars_count + 1):
2222
data['days'].append(i)
2323
data['bugs'].append(random.randint(1,100))
2424
data['costs'].append(random.uniform(1.00, 1000.00))
@@ -33,6 +33,7 @@ def chart(bars_count):
3333

3434

3535
def create_hover_tool():
36+
"""Generates the HTML for the Bokeh's hover data tool on our graph."""
3637
hover_html = """
3738
<div>
3839
<span class="hover-tooltip">$x</span>
@@ -41,18 +42,17 @@ def create_hover_tool():
4142
<span class="hover-tooltip">@bugs bugs</span>
4243
</div>
4344
<div>
44-
<span class="hover-tooltip">$@cost{0.00}</span>
45+
<span class="hover-tooltip">$@costs{0.00}</span>
4546
</div>
4647
"""
4748
return HoverTool(tooltips=hover_html)
4849

4950

5051
def create_bar_chart(data, title, x_name, y_name, hover_tool=None,
5152
width=1200, height=300):
52-
"""
53-
Creates a bar chart plot with the exact styling for the centcom
54-
dashboard. Pass in data as a dictionary, desired plot title,
55-
name of x axis, y axis and the hover tool HTML.
53+
"""Creates a bar chart plot with the exact styling for the centcom
54+
dashboard. Pass in data as a dictionary, desired plot title,
55+
name of x axis, y axis and the hover tool HTML.
5656
"""
5757
source = ColumnDataSource(data)
5858
xdr = FactorRange(factors=data[x_name])
@@ -77,21 +77,13 @@ def create_bar_chart(data, title, x_name, y_name, hover_tool=None,
7777
plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker))
7878
plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
7979
plot.toolbar.logo = None
80-
plot.title.text_color = "white"
81-
plot.background_fill_alpha = 0.05
82-
plot.border_fill_alpha = 0
8380
plot.min_border_top = 0
84-
plot.min_border_bottom = 0
8581
plot.xgrid.grid_line_color = None
8682
plot.ygrid.grid_line_color = "#999999"
87-
plot.yaxis.axis_label_text_color = "white"
88-
plot.yaxis.major_label_text_color = "white"
89-
plot.yaxis.axis_label = None
83+
plot.yaxis.axis_label = "Bugs found"
9084
plot.ygrid.grid_line_alpha = 0.1
91-
plot.xaxis.axis_label_text_color = "white"
92-
plot.xaxis.major_label_text_color = "white"
93-
plot.xaxis.axis_label = None
94-
plot.xaxis.major_label_orientation = .785
85+
plot.xaxis.axis_label = "Days after app deployment"
86+
plot.xaxis.major_label_orientation = 1
9587
return plot
9688

9789

0 commit comments

Comments
 (0)