Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First version of the dashboard with most charts #5

Merged
merged 33 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
62ccb14
added .envrc to gitignore
benoitfrisque Oct 3, 2024
eae7598
added .envrc file
benoitfrisque Oct 3, 2024
238b596
Exploratory data analysis
benoitfrisque Oct 3, 2024
a4ec97c
reimplemented histogram 3
benoitfrisque Oct 3, 2024
75b180c
updated color scheme
benoitfrisque Oct 3, 2024
fc37bc9
created a dummy dashboard with hist3 and observation id selection
benoitfrisque Oct 3, 2024
cc411dd
added hist4
benoitfrisque Oct 3, 2024
921adf5
updated hist3 design
benoitfrisque Oct 4, 2024
f814a84
updated hist3
benoitfrisque Oct 4, 2024
607b3a0
added jupyterlab and dash-mantine-components for the dashboarding"
benoitfrisque Oct 4, 2024
454c299
first layout for the dashboard with hist3 and hist4
benoitfrisque Oct 4, 2024
33fe5fe
added OS files to gitignore
benoitfrisque Oct 4, 2024
1e2fef2
moved dataset functions to computed_datasets.py
benoitfrisque Oct 4, 2024
2daeb39
updated layout with divider
benoitfrisque Oct 4, 2024
6c590a1
dashboard split in 2 tabs
benoitfrisque Oct 4, 2024
4fd573c
added info hovers with DashIconify and refactored the layout
benoitfrisque Oct 10, 2024
3da808a
implemented styles in a CSS file
benoitfrisque Oct 10, 2024
8880629
added styling for plotly hovering
benoitfrisque Oct 10, 2024
18f83c0
moved connstants to separate file
benoitfrisque Oct 10, 2024
85b8883
renamed data manipulation functions for better clarity
benoitfrisque Oct 10, 2024
33e240a
refactored charts in other file
benoitfrisque Oct 10, 2024
4966697
added color for selected values in dropdown
benoitfrisque Oct 10, 2024
421c57e
refactored data manipulation functions
benoitfrisque Oct 11, 2024
244e41c
first interactive dashboard with map
benoitfrisque Oct 11, 2024
abbda04
updated layout
benoitfrisque Oct 11, 2024
28ad75f
updated layout
benoitfrisque Oct 11, 2024
1b4294f
new layout with flex dividers
benoitfrisque Oct 14, 2024
40f7d57
improved layout
benoitfrisque Oct 14, 2024
5ddc95c
refactored gauge chart
benoitfrisque Oct 14, 2024
1b65144
compared names of lichen with ecology df
benoitfrisque Oct 14, 2024
a548e85
added gauge charts
benoitfrisque Oct 14, 2024
4904407
solved precommit issues
benoitfrisque Oct 14, 2024
1a2daa8
fixed commit issues
benoitfrisque Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotenv
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ docs/_build/
target/

# Jupyter Notebook
.pytest_cache
__pycache__
*checkpoint.ipynb
.ipynb_checkpoints

# IPython
Expand Down Expand Up @@ -160,4 +163,10 @@ dmypy.json
cython_debug/

# Precommit hooks: ruff cache
.ruff_cache
.ruff_cache

# OS generated files #
######################
.DS_Store
__MACOSX
Zone.Identifier
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ repos:
rev: v1.3.1
hooks:
- id: python-safety-dependencies-check
args: [--ignore, "70612"] # Ignoring Jinja2 Vulnerability ID: 70612
25 changes: 25 additions & 0 deletions Dashboards/assets/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Set default text styling */
body {
color: #495057;
/* color: #c35a25; */
font-family: "Source Sans Pro", sans-serif;
text-align: left;
letter-spacing: normal;
}

.graph-title {
text-align: left;
margin: 0;
}

.info-icon {
font-size: 15px;
margin-left: 5px;
}


/* Text color of the selected value in the dropdown */
.Select-value-label {
color: #495057!important;
/* color: #c35a25!important; */
}
175 changes: 175 additions & 0 deletions Dashboards/charts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import plotly.express as px
import plotly.graph_objects as go
from constants import BASE_COLOR_PALETTE, PASTEL_COLOR_PALETTE, PLOTLY_LAYOUT

def create_hist1_nb_species(observation_with_vdl_df, nb_species_clicked):
hist1 = px.histogram(
observation_with_vdl_df,
x='nb_species',
color_discrete_sequence=BASE_COLOR_PALETTE
)

hist1.update_layout(
**PLOTLY_LAYOUT,
xaxis_title="Nombre d'espèces",
yaxis_title="Nombre de sites",
yaxis_showgrid=True,
bargap=0.1,
)

# Add vertical line for the clicked number of species
if nb_species_clicked:
hist1.add_shape(
go.layout.Shape(
type="line",
x0=nb_species_clicked, x1=nb_species_clicked,
y0=0, y1=1,
xref='x', yref='paper',
line=dict(color='red', width=2, dash="dot")
)
)

return hist1


def create_hist2_vdl(observation_with_vdl_df, vdl_clicked):
hist2 = px.histogram(
observation_with_vdl_df,
x='VDL',
color_discrete_sequence=BASE_COLOR_PALETTE
)

hist2.update_layout(
**PLOTLY_LAYOUT,
xaxis_title="Valeur de Diversité Lichénique (VDL)",
yaxis_title="Nombre de sites",
yaxis_showgrid=True,
bargap=0.1,
)

# Add vertical line for the clicked VDL value
if vdl_clicked:
hist2.add_shape(
go.layout.Shape(
type="line",
x0=vdl_clicked, x1=vdl_clicked,
y0=0, y1=1,
xref='x', yref='paper',
line=dict(color='red', width=2, dash="dot")
)
)

return hist2


def create_hist3(lichen_frequency_df):

hist3 = px.bar(
lichen_frequency_df,
x="nb_lichen",
y="unique_name",
orientation="h",
color_discrete_sequence=BASE_COLOR_PALETTE,
)

hist3.update_layout(
**PLOTLY_LAYOUT,
xaxis_title="Nombre",
yaxis_title="",
xaxis_showgrid=True,
)

# Update hover template
hist3.update_traces(
hovertemplate=(
"<b>%{y}</b><br><br>"
"<b>Nombre:</b> %{x}<br>"
"<b>Nord:</b> %{customdata[0]:<2}<br>"
"<b>Sud:</b> %{customdata[1]:<2}<br>"
"<b>Ouest:</b> %{customdata[2]:<2}<br>"
"<b>Est:</b> %{customdata[3]:<2}<br>"
"<extra></extra>"
),
customdata=lichen_frequency_df[['nb_lichen_N', 'nb_lichen_S', 'nb_lichen_O', 'nb_lichen_E']].values
)

return hist3

## Gauge charts


def create_gauge_chart(value, title=None):
fig = go.Figure(
go.Indicator(
domain={"x": [0, 1], "y": [0, 1]},
value=value,
number={"suffix": "%", "font": {"size": 18}},
mode="gauge+number",
title={"text": title},
gauge={
"axis": {"range": [0, 100], "dtick": 25},
'bar': {'color': "rgba(0,0,0,1)", 'thickness': 0.3},
"steps": [
{'range': [0, 25], 'color': "rgba(34, 139, 34, 0.7)"},
{'range': [25, 50], 'color': "rgba(255, 215, 0, 0.7)"},
{'range': [50, 75], 'color': "rgba(255, 140, 0, 0.7)"},
{'range': [75, 100], 'color': "rgba(255, 69, 0, 0.7)"}
],
"threshold": {
"line": {"color": "rgba(0,0,0,1)", "width": 3},
"thickness": 0.75,
"value": value,
},
},
)
)

fig.update_layout(
margin={'l': 30, 'r': 30, 'b': 0, 't': 0}
)

return fig


## Histograms for species

def create_hist4(count_lichen_per_species_df, user_selection_species_id):
# Find the index of the selected species ID in the merged table
user_selection_idx = count_lichen_per_species_df[count_lichen_per_species_df["species_id"] == user_selection_species_id].index

# Adjust the color of the selected specie to be darker
pastel_color = PASTEL_COLOR_PALETTE[0]
selected_color = BASE_COLOR_PALETTE[0]
color_hist4 = [pastel_color] * len(count_lichen_per_species_df)
color_hist4[int(user_selection_idx[0])] = selected_color

# Bar plot
hist4 = px.bar(
count_lichen_per_species_df,
x="count",
y="name",
orientation="h",
color="name",
color_discrete_sequence=color_hist4,
)

# Update layout
hist4.update_layout(
**PLOTLY_LAYOUT,
showlegend=False,
)

# Update axes
hist4.update_xaxes(
title_text="Nombre",
showgrid=True,
)
hist4.update_yaxes(
title="",
# tickfont=dict(size=10) # Adjust tick font size
)
hist4.update_traces(
hovertemplate="<b>%{y}</b><br><b>Nombre:</b> %{x}<extra></extra>"
)

return hist4
52 changes: 52 additions & 0 deletions Dashboards/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from utils.css_reader import get_css_properties

# Constants for color palettes, font families, etc.
BASE_COLOR_PALETTE = [
"#387CA6",
"#1C6C8C",
"#3887A6",
"#ADCCD9",
"#F2F2F2"
]

PASTEL_COLOR_PALETTE = [
'#c3d7e4',
'#bad2dc',
'#c3dbe4',
'#e6eff3',
'#fbfbfb'
]

ORIENTATIONS_MAPPING = {
"N": "Nord",
"E": "Est",
"S": "Sud",
"O": "Ouest"
}

ORIENTATIONS = list(ORIENTATIONS_MAPPING.keys())

SQUARE_COLUMNS = ['sq1', 'sq2', 'sq3', 'sq4', 'sq5']

BODY_STYLE = get_css_properties("body")
BODY_FONT_FAMILY = BODY_STYLE.get("font-family", "Arial")
BODY_FONT_COLOR = BODY_STYLE.get("color", "grey")

# Define the plotly style for hover labels
PLOTLY_HOVER_STYLE = {
"font": dict(
family=BODY_FONT_FAMILY,
)
}

# Define the plotly layout for all plots
PLOTLY_LAYOUT = {
"font": dict(
family=BODY_FONT_FAMILY,
color=BODY_FONT_COLOR
),
"template": "plotly_white",
"margin": dict(l=10, r=10, t=10, b=10),
"barcornerradius":"30%",
"hoverlabel": PLOTLY_HOVER_STYLE
}
Loading
Loading