Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into pregenerate_figures
Browse files Browse the repository at this point in the history
  • Loading branch information
surchs committed Sep 25, 2024
2 parents abd9d8c + 6771c1a commit 4ec6353
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 46 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ repos:
rev: v2.3.0
hooks:
- id: codespell
args: [--ignore-words-list=doubleClick]

- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 ORIGAMI Lab

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions climate_emotions_map/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .utility import ( # IMPACT_COLORMAP,; OPINION_COLORMAP,
ALL_STATES_LABEL,
DEFAULT_QUESTION,
NUM_DECIMALS,
SECTION_TITLES,
)

Expand All @@ -36,6 +37,9 @@
app = Dash(
__name__,
title="US Climate Emotions Map",
external_stylesheets=[
"https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css"
],
)

app.layout = dmc.MantineProvider(construct_layout(), forceColorScheme="light")
Expand Down Expand Up @@ -142,6 +146,7 @@ def update_sample_descriptive_plot(state):
"""Update the sample descriptive plot based on the selected state."""
return make_descriptive_plots(
state=state,
decimals=NUM_DECIMALS,
)


Expand Down Expand Up @@ -213,6 +218,7 @@ def update_map(question_value, state, impact):
impact=impact,
colormap_range_padding=MAP_LAYOUT["colormap_range_padding"],
margins=MAP_LAYOUT["margin"],
decimals=NUM_DECIMALS,
# opinion_colormap=OPINION_COLORMAP,
# impact_colormap=IMPACT_COLORMAP,
)
Expand Down Expand Up @@ -248,6 +254,7 @@ def update_selected_question_bar_plot(
state=state,
stratify=is_party_stratify_checked,
threshold=threshold,
decimals=NUM_DECIMALS,
fig_kw=SINGLE_SUBQUESTION_FIG_KW,
)
return figure
Expand Down
113 changes: 92 additions & 21 deletions climate_emotions_map/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
from .utility import ( # IMPACT_COLORMAP,; OPINION_COLORMAP,
ALL_STATES_LABEL,
DEFAULT_QUESTION,
NUM_DECIMALS,
SECTION_TITLES,
)

HEADER_HEIGHT = 110

SUPP_TEXT = {
"hover_tip": "Hover over bars for full proportions",
"weighted_descriptives": "*N are unweighted while proportions are weighted according to US census estimates for age, sex, race, and ethnicity",
"map_disclaimer": "Map does not support making statistical comparisons between states",
}

MAP_LAYOUT = {
Expand All @@ -32,6 +35,13 @@
"margin": {"l": 30, "r": 30, "t": 10, "b": 20},
}

# See https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js for all options
DCC_GRAPH_CONFIG = {
"displayModeBar": False,
"scrollZoom": False,
"doubleClick": "reset",
}


def create_question_dropdown():
"""
Expand Down Expand Up @@ -107,6 +117,16 @@ def create_drawer_sample_size():
return dmc.Text(id="drawer-sample-size", size="md")


def create_sample_descriptives_hover_tip():
"""Create the tip to hover over bars in the sample characteristics drawer."""
return dmc.Text(
children=SUPP_TEXT["hover_tip"],
fs="italic",
size="sm",
mt="xs",
)


def create_sample_descriptive_note():
"""Create the note for the sample characteristics section."""
return dmc.Text(
Expand All @@ -121,8 +141,9 @@ def create_sample_descriptive_plot():
id="sample-descriptive-plot",
figure=make_descriptive_plots(
state=None,
decimals=NUM_DECIMALS,
),
config={"displayModeBar": False},
config=DCC_GRAPH_CONFIG,
# TODO: Revisit
# We use px instead of viewport height here for now to more easily control scrolling
# on smaller screens
Expand All @@ -143,6 +164,7 @@ def create_sample_description_drawer():
children=[
create_drawer_state(),
create_drawer_sample_size(),
create_sample_descriptives_hover_tip(),
create_sample_descriptive_plot(),
create_sample_descriptive_note(),
],
Expand Down Expand Up @@ -266,11 +288,28 @@ def create_header():
gap=5,
justify="center",
children=[
dmc.Anchor(
SECTION_TITLES["app"],
size="xl",
href="/",
underline=False,
dmc.Grid(
children=[
dmc.GridCol(
dmc.Anchor(
SECTION_TITLES["app"],
size="xl",
href="/",
underline=False,
),
span="content",
),
# TODO: Uncomment once the more info page is created
# dmc.GridCol(
# dmc.Anchor(
# SECTION_TITLES["more_info"],
# href="/"
# ),
# span="content"
# )
],
justify="space-between",
align="flex-end",
),
create_app_subtitle(),
],
Expand Down Expand Up @@ -309,17 +348,14 @@ def create_map_title():

def create_impact_dropdown():
"""Create the dropdown for selecting the impact to display."""
return dmc.Flex(
dmc.Select(
id="impact-select",
label="Distribution of severe weather events (self-reported)",
placeholder="Select a severe weather event",
data=utils.get_impact_options(),
clearable=True,
searchable=True,
nothingFoundMessage="No matches",
),
justify="flex-end",
return dmc.Select(
id="impact-select",
label="Distribution of severe weather events (self-reported)",
placeholder="Select a severe weather event",
data=utils.get_impact_options(),
clearable=True,
searchable=True,
nothingFoundMessage="No matches",
)


Expand All @@ -334,11 +370,12 @@ def create_map_plot():
outcome=DEFAULT_QUESTION["outcome"],
colormap_range_padding=MAP_LAYOUT["colormap_range_padding"],
margins=MAP_LAYOUT["margin"],
decimals=NUM_DECIMALS,
# opinion_colormap=OPINION_COLORMAP,
),
# vh = % of viewport height
# TODO: Revisit once plot margins are adjusted
config={"displayModeBar": False, "scrollZoom": False},
config=DCC_GRAPH_CONFIG,
style={"height": "65vh"},
),
# set max width
Expand All @@ -349,6 +386,25 @@ def create_map_plot():
return us_map


def create_map_disclaimer():
"""Create the disclaimer for the map section of the dashboard."""
return dmc.Flex(
[
html.I(
className="bi bi-exclamation-circle", style={"fontSize": 15}
),
dmc.Text(
children=SUPP_TEXT["map_disclaimer"],
fs="italic",
size="sm",
# ta="center",
),
],
gap=5,
align="center",
)


def create_domain_heading(domain_text: str) -> dmc.Title:
"""Create a domain heading for the stacked bar plots."""
return dmc.Title(
Expand Down Expand Up @@ -390,8 +446,9 @@ def create_bar_plots_for_question(question_id: str, subquestion_id: str):
state=None,
stratify=False,
threshold=DEFAULT_QUESTION["outcome"],
decimals=NUM_DECIMALS,
),
config={"displayModeBar": False},
config=DCC_GRAPH_CONFIG,
),
w=1200,
# size="xl",
Expand All @@ -417,9 +474,10 @@ def create_selected_question_bar_plot():
state=None,
stratify=False,
threshold=DEFAULT_QUESTION["outcome"],
decimals=NUM_DECIMALS,
fig_kw=SINGLE_SUBQUESTION_FIG_KW,
),
config={"displayModeBar": False},
config=DCC_GRAPH_CONFIG,
),
w=1200,
)
Expand Down Expand Up @@ -529,7 +587,20 @@ def create_main():
fluid=True,
children=[
create_map_title(),
create_impact_dropdown(),
dmc.Grid(
[
dmc.GridCol(
create_map_disclaimer(),
span="content",
),
dmc.GridCol(
create_impact_dropdown(),
span="content",
),
],
justify="space-between",
align="flex-end",
),
create_map_plot(),
create_selected_question_bar_plot(),
create_all_questions_section_title(),
Expand Down
Loading

0 comments on commit 4ec6353

Please sign in to comment.