Skip to content

Commit 26a893c

Browse files
committed
Average line only for bar charts
1 parent 9f0a3a9 commit 26a893c

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

dash_service/pages/home.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
create_subdomain_buttons,
3636
create_indicator_buttons,
3737
update_domain_with_url,
38-
highlight_option
38+
highlight_option,
39+
average_option,
3940
)
4041

4142
from dash_service.static.page_config import (
@@ -200,6 +201,16 @@ def update_current_indicator(dropdown_value, active_indicator_buttons, crm_view_
200201
return indicator_button_ids[active_index]['index']
201202
return dropdown_value # Otherwise, return the dropdown value
202203

204+
@callback(
205+
Output('average_option', 'style'),
206+
[
207+
Input({"type": "area_breakdowns", "index": "AIO_AREA"}, "value"),
208+
Input({"type": "area_types", "index": "AIO_AREA"}, "value"),
209+
]
210+
)
211+
def show_average_option(compare, selected_type):
212+
return average_option(compare, selected_type)
213+
203214
@callback(
204215
[
205216
Output('search_by_indicator_div', 'style'),

dash_service/pages/transmonee.py

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,30 +1571,51 @@ def get_base_layout(**kwargs):
15711571
[
15721572
dbc.Row(
15731573
[
1574+
# Checkbox and Label
1575+
dbc.Col(
1576+
[
1577+
dbc.Checkbox(
1578+
id='show-average-checkbox',
1579+
className='custom-checkbox',
1580+
value=True,
1581+
),
1582+
html.Label(
1583+
'Show average line',
1584+
htmlFor='show-average-checkbox',
1585+
style={'margin-top':'3px', 'margin-left': '5px'}
1586+
),
1587+
],
1588+
id='average_option',
1589+
style={'display':'none'},
1590+
width='auto'
1591+
),
1592+
# Radio Items
15741593
dbc.Col(
15751594
dbc.RadioItems(
15761595
id={
15771596
"type": "area_breakdowns",
15781597
"index": "AIO_AREA",
15791598
},
1580-
value = "TOTAL",
1599+
value="TOTAL",
15811600
class_name="force-inline-control responsive-radio-items",
15821601
inline=True,
15831602
),
15841603
width="auto",
15851604
className="radio-items-col",
15861605
),
1606+
# Dropdown and label
15871607
dbc.Col(
15881608
html.Div([
15891609
html.P("Select country to highlight:", style={"margin-bottom": "10px", "margin-top": "5px", "margin-right": "5px"}),
15901610
dcc.Dropdown(
15911611
id="highlighted_country"
1592-
),
1593-
], style={"display": "none"}),
1594-
id = "highlight_option",
1612+
),
1613+
], style={"display": "none"}),
1614+
id="highlight_option",
15951615
width="auto",
1596-
),
1616+
),
15971617
],
1618+
style={"display": "flex", "align-items": "center"},
15981619
)
15991620
],
16001621
style={
@@ -1812,25 +1833,6 @@ def get_base_layout(**kwargs):
18121833
),
18131834
dbc.Col(
18141835
[
1815-
dbc.Row(
1816-
[
1817-
dbc.Col(
1818-
dbc.Checkbox(
1819-
id='show-average-checkbox',
1820-
className='custom-checkbox',
1821-
value=True,
1822-
),
1823-
style={"padding":"0px"},
1824-
width='auto'
1825-
),
1826-
dbc.Col(
1827-
html.Label('Show average line', htmlFor='show-average-checkbox', style={'margin-top':'3px'}),
1828-
style={"padding":"0px"},
1829-
width='auto'
1830-
),
1831-
],
1832-
style={"display":"flex", "justifyContent":"center", "marginTop":"25px"},
1833-
),
18341836
dbc.Row(
18351837
[
18361838
html.Button(
@@ -2718,6 +2720,19 @@ def default_compare(compare_options, selected_type, indicator):
27182720
return compare_options[0]["value"]
27192721

27202722

2723+
def average_option(compare, selected_type):
2724+
if selected_type == "bar" and compare == 'TOTAL':
2725+
return {
2726+
"padding":"0px",
2727+
"display": "flex",
2728+
"align-items": "center"
2729+
}
2730+
else:
2731+
return {
2732+
"display": "none"
2733+
}
2734+
2735+
27212736
def highlight_option(fig_type, indicator, years_slider, countries, country_group, compare):
27222737
if fig_type == "line" and indicator:
27232738
filters, country_selector, selected_years, country_text = get_filters(

0 commit comments

Comments
 (0)