Skip to content

Commit

Permalink
Merge pull request #1133 from chelseybeck/dev
Browse files Browse the repository at this point in the history
Changes pie charts to donut charts
  • Loading branch information
chelseybeck authored Oct 1, 2021
2 parents 1a1da6f + 810f821 commit e27e0c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/dash/dashboards/neighborhood_recent.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def populate_options():
values="srnumber",
color_discrete_sequence=DISCRETE_COLORS,
labels=LABELS,
hole=.3,
)
apply_figure_style(pie_fig)

Expand Down
3 changes: 3 additions & 0 deletions server/dash/dashboards/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
values='counts',
color_discrete_sequence=DISCRETE_COLORS,
labels=LABELS,
hole=.3,
)

# source figure
Expand Down Expand Up @@ -98,6 +99,7 @@
values='counts',
color_discrete_sequence=DISCRETE_COLORS,
labels=LABELS,
hole=.3,
)
# fig3.update_layout(showlegend=False)

Expand Down Expand Up @@ -133,6 +135,7 @@
# LAYOUT
layout = html.Div([
html.H1(title),
html.P("The figures below represent the total number of 311 requests made across LA County from 2016-2021. In 2020, we saw an all-time high of over 1.4 million requests.", style={'padding':'20px', 'font-size':'18px', 'font-style':'italic'}),
html.Div([
html.Div([html.H2(f"{df2['counts'].sum():,}"), html.Label("Total Requests")], className="stats-label"), # noqa
html.Div([html.H2(df1.shape[0] - 1), html.Label("Neighborhoods")], className="stats-label"), # noqa
Expand Down
13 changes: 9 additions & 4 deletions server/dash/dashboards/recent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import dash_html_components as html
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

from config import API_HOST
from design import CONFIG_OPTIONS, DISCRETE_COLORS, LABELS, apply_figure_style

# TITLE
title = "RECENT 311 REQUESTS"

# DATA
start_date = datetime.date.today() - datetime.timedelta(days=15)
start_date = datetime.date.today() - datetime.timedelta(days=30)
end_date = datetime.date.today() - datetime.timedelta(days=1)

query_string = f"/reports?filter=created_date>={start_date}&filter=created_date<={end_date}" # noqa
Expand All @@ -23,6 +25,8 @@
# FIGURES
report_df = df.groupby(['created_date', 'type_name']).agg('sum').reset_index()
report_df.type_name = report_df.type_name.map(lambda x: '<br>'.join(textwrap.wrap(x, width=16))) # noqa

# Line Graph
fig = px.line(
report_df,
x="created_date",
Expand All @@ -40,17 +44,17 @@
mode='markers+lines'
) # add markers to lines


# Pie Chart
pie_df = df.groupby(['type_name']).agg('sum').reset_index()
pie_fig = px.pie(
pie_df,
names="type_name",
values="counts",
color_discrete_sequence=DISCRETE_COLORS,
labels=LABELS,
hole=.3,
)


df['created_date'] = pd.to_datetime(df['created_date'])
dow_df = df.groupby(['created_date']).agg('sum').reset_index()
dow_df['day_of_week'] = dow_df['created_date'].dt.day_name()
Expand All @@ -69,11 +73,12 @@
# LAYOUT
layout = html.Div([
html.H1(title),
html.P("The figures below represent the total number of 311 requests made across LA County over the past 30 days.", style={'padding':'20px', 'font-size':'18px', 'font-style':'italic'}),
html.Div([
html.Div([html.H2(f"{report_df['counts'].sum():,}"), html.Label("Total Requests")], className="stats-label"), # noqa
html.Div([html.H2(f"{start_date.strftime('%b %d')}"), html.Label("Report Start Date")], className="stats-label"), # noqa
html.Div([html.H2(f"{end_date.strftime('%b %d')}"), html.Label("Report End Date")], className="stats-label"), # noqa
], className="graph-row"),
], className="graph-row", style={'color':'white'}),
dcc.Graph(id='graph', figure=fig, config=CONFIG_OPTIONS),
html.Div([
dcc.Graph(id='graph3', figure=dow_fig, config=CONFIG_OPTIONS, className="half-graph"), # noqa
Expand Down

0 comments on commit e27e0c7

Please sign in to comment.