From 26a893cecbdfd9f098f3e1d43f08f4c0fd9c10a1 Mon Sep 17 00:00:00 2001 From: Amy Reidy <73396449+Amy-Reidy@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:47:08 +0200 Subject: [PATCH] Average line only for bar charts --- dash_service/pages/home.py | 13 ++++++- dash_service/pages/transmonee.py | 63 ++++++++++++++++++++------------ 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/dash_service/pages/home.py b/dash_service/pages/home.py index c5da6c0..b71bcaa 100644 --- a/dash_service/pages/home.py +++ b/dash_service/pages/home.py @@ -35,7 +35,8 @@ create_subdomain_buttons, create_indicator_buttons, update_domain_with_url, - highlight_option + highlight_option, + average_option, ) from dash_service.static.page_config import ( @@ -200,6 +201,16 @@ def update_current_indicator(dropdown_value, active_indicator_buttons, crm_view_ return indicator_button_ids[active_index]['index'] return dropdown_value # Otherwise, return the dropdown value +@callback( + Output('average_option', 'style'), + [ + Input({"type": "area_breakdowns", "index": "AIO_AREA"}, "value"), + Input({"type": "area_types", "index": "AIO_AREA"}, "value"), + ] +) +def show_average_option(compare, selected_type): + return average_option(compare, selected_type) + @callback( [ Output('search_by_indicator_div', 'style'), diff --git a/dash_service/pages/transmonee.py b/dash_service/pages/transmonee.py index c7b3335..311b025 100644 --- a/dash_service/pages/transmonee.py +++ b/dash_service/pages/transmonee.py @@ -1571,30 +1571,51 @@ def get_base_layout(**kwargs): [ dbc.Row( [ + # Checkbox and Label + dbc.Col( + [ + dbc.Checkbox( + id='show-average-checkbox', + className='custom-checkbox', + value=True, + ), + html.Label( + 'Show average line', + htmlFor='show-average-checkbox', + style={'margin-top':'3px', 'margin-left': '5px'} + ), + ], + id='average_option', + style={'display':'none'}, + width='auto' + ), + # Radio Items dbc.Col( dbc.RadioItems( id={ "type": "area_breakdowns", "index": "AIO_AREA", }, - value = "TOTAL", + value="TOTAL", class_name="force-inline-control responsive-radio-items", inline=True, ), width="auto", className="radio-items-col", ), + # Dropdown and label dbc.Col( html.Div([ html.P("Select country to highlight:", style={"margin-bottom": "10px", "margin-top": "5px", "margin-right": "5px"}), dcc.Dropdown( id="highlighted_country" - ), - ], style={"display": "none"}), - id = "highlight_option", + ), + ], style={"display": "none"}), + id="highlight_option", width="auto", - ), + ), ], + style={"display": "flex", "align-items": "center"}, ) ], style={ @@ -1812,25 +1833,6 @@ def get_base_layout(**kwargs): ), dbc.Col( [ - dbc.Row( - [ - dbc.Col( - dbc.Checkbox( - id='show-average-checkbox', - className='custom-checkbox', - value=True, - ), - style={"padding":"0px"}, - width='auto' - ), - dbc.Col( - html.Label('Show average line', htmlFor='show-average-checkbox', style={'margin-top':'3px'}), - style={"padding":"0px"}, - width='auto' - ), - ], - style={"display":"flex", "justifyContent":"center", "marginTop":"25px"}, - ), dbc.Row( [ html.Button( @@ -2718,6 +2720,19 @@ def default_compare(compare_options, selected_type, indicator): return compare_options[0]["value"] +def average_option(compare, selected_type): + if selected_type == "bar" and compare == 'TOTAL': + return { + "padding":"0px", + "display": "flex", + "align-items": "center" + } + else: + return { + "display": "none" + } + + def highlight_option(fig_type, indicator, years_slider, countries, country_group, compare): if fig_type == "line" and indicator: filters, country_selector, selected_years, country_text = get_filters(