1414"""
1515
1616import panel as pn
17- from pathlib import Path
1817from jinja2 import Environment , FileSystemLoader
1918
2019from survey_dashboard .config import (
2120 LANGUAGE ,
22- SIZING_MODE ,
2321 PANEL_CONFIG ,
2422 get_template_path ,
2523 get_assets_path
4038
4139class LayoutManager :
4240 """Manages the dashboard layout and template integration."""
43-
41+
4442 def __init__ (self ):
4543 """Initialize layout manager and configure Panel."""
4644 self .setup_panel_config ()
4745 self .setup_template ()
4846 self .setup_overview_icons ()
49-
47+
5048 def setup_panel_config (self ):
5149 """Configure Panel global settings."""
5250 pn .config .loading_spinner = PANEL_CONFIG ["loading_spinner" ]
5351 pn .config .loading_color = PANEL_CONFIG ["loading_color" ]
5452 pn .config .raw_css = [hmc_custom_css_accordion ]
55-
53+
5654 def setup_template (self ):
5755 """Setup Jinja2 template for the dashboard."""
5856 template_path = get_template_path ()
59- this_folder = Path ( __file__ ). parent
60- env = Environment (loader = FileSystemLoader (this_folder ))
61- jinja_template = env .get_template (f"hmc_layout/ { LANGUAGE . lower () } _template.html" )
57+ # Set the loader to look in the directory containing the template
58+ env = Environment (loader = FileSystemLoader (template_path . parent ))
59+ jinja_template = env .get_template (template_path . name )
6260 self .template = pn .Template (jinja_template )
63-
61+
6462 def setup_overview_icons (self ):
6563 """Create overview icons with SVG images."""
6664 assets_path = get_assets_path ()
67-
65+
6866 people_ic = pn .Row (
6967 pn .pane .SVG (assets_path / "people.svg" ),
7068 md_text_descriptions_icons ["people" ][LANGUAGE ],
@@ -77,19 +75,19 @@ def setup_overview_icons(self):
7775 pn .pane .SVG (assets_path / "quiz_black_48dp.svg" ),
7876 md_text_descriptions_icons ["questions" ][LANGUAGE ],
7977 )
80-
78+
8179 self .overview_icons = pn .Row (people_ic , inst_ic , questions_ic )
82-
80+
8381 def create_global_filters_section (self , control_groups ):
8482 """Create the global filters section."""
8583 global_filters_sec = pn .Column (
86- md_text_global_filter [LANGUAGE ],
87- control_groups ["global_filters" ][0 ],
88- control_groups ["global_filters" ][1 ],
84+ md_text_global_filter [LANGUAGE ],
85+ control_groups ["global_filters" ][0 ],
86+ control_groups ["global_filters" ][1 ],
8987 sizing_mode = "stretch_width"
9088 )
9189 return global_filters_sec
92-
90+
9391 def create_overview_section (self , overview_charts ):
9492 """Create the overview section with charts."""
9593 overview_sec = pn .Column (
@@ -99,46 +97,46 @@ def create_overview_section(self, overview_charts):
9997 sizing_mode = "stretch_width" ,
10098 )
10199 return overview_sec
102-
100+
103101 def create_question_explorer_section (self , control_groups , exploration_charts , correlation_chart ):
104102 """Create the question explorer section with exploration and correlation charts."""
105103 half_width = 400 # Approximate half width for controls
106-
104+
107105 # Control inputs
108106 inputs = pn .Column (* control_groups ["controls_bar1" ], width = half_width )
109107 inputs2 = pn .Column (* control_groups ["controls_bar2" ], width = half_width )
110-
108+
111109 # Charts row with controls and visualizations
112110 charts_row = pn .Column (
113- pn .Row (inputs , inputs2 , sizing_mode = "stretch_width" ),
114- pn .Row (exploration_charts [0 ], exploration_charts [1 ], sizing_mode = "stretch_width" ),
111+ pn .Row (inputs , inputs2 , sizing_mode = "stretch_width" ),
112+ pn .Row (exploration_charts [0 ], exploration_charts [1 ], sizing_mode = "stretch_width" ),
115113 sizing_mode = "stretch_width"
116114 )
117-
115+
118116 # Correlation section
119117 fig_corr , leg_corr = correlation_chart
120118 correlation_row = pn .Column (
121119 md_text_corrchart [LANGUAGE ],
122120 pn .Row (
123- pn .layout .VSpacer (),
124- fig_corr ,
125- leg_corr ,
126- pn .layout .VSpacer (),
121+ pn .layout .VSpacer (),
122+ fig_corr ,
123+ leg_corr ,
124+ pn .layout .VSpacer (),
127125 sizing_mode = "stretch_width"
128126 ),
129127 sizing_mode = "stretch_width"
130128 )
131-
129+
132130 # Combined question explorer section
133131 question_ex_sec = pn .Column (
134- md_text_barchart [LANGUAGE ],
135- charts_row ,
136- correlation_row ,
132+ md_text_barchart [LANGUAGE ],
133+ charts_row ,
134+ correlation_row ,
137135 sizing_mode = "stretch_width"
138136 )
139-
137+
140138 return question_ex_sec
141-
139+
142140 def create_accordion_layout (self , sections ):
143141 """Create the main accordion layout."""
144142 overall_accordion = pn .Accordion (
@@ -148,17 +146,17 @@ def create_accordion_layout(self, sections):
148146 (accordion_titles [LANGUAGE ][3 ], sections ["question_explorer" ]),
149147 sizing_mode = "stretch_both" ,
150148 )
151-
149+
152150 # Configure accordion settings
153151 overall_accordion .active = [0 , 3 ] # Open global filters and question explorer by default
154152 overall_accordion .scroll = True
155153 overall_accordion .margin = (20 , 20 , 20 , 20 ) # Add consistent margin on all sides
156154 overall_accordion .width = None # Remove fixed width constraint
157155 overall_accordion .min_width = None # Remove min-width constraint
158-
156+
159157 return overall_accordion
160-
161- def create_complete_layout (self , control_groups , overview_charts , exploration_charts ,
158+
159+ def create_complete_layout (self , control_groups , overview_charts , exploration_charts ,
162160 correlation_chart , methods_tools_tabs ):
163161 """Create the complete dashboard layout."""
164162 # Create all sections
@@ -170,24 +168,24 @@ def create_complete_layout(self, control_groups, overview_charts, exploration_ch
170168 control_groups , exploration_charts , correlation_chart
171169 )
172170 }
173-
171+
174172 # Create accordion
175173 accordion = self .create_accordion_layout (sections )
176-
174+
177175 # Main layout container
178176 layout = pn .Column (accordion , sizing_mode = "stretch_both" )
179-
177+
180178 return layout
181-
179+
182180 def setup_template_variables (self , layout ):
183181 """Setup template with layout and variables."""
184182 self .template .add_panel ("App" , layout )
185183 self .template .add_variable ("app_title" , md_text_title [LANGUAGE ])
186184 self .template .add_variable ("image_url" , "./en_files/Banner.png" )
187-
185+
188186 return self .template
189-
187+
190188 def make_servable (self ):
191189 """Make the template servable."""
192190 self .template .servable (title = md_text_title [LANGUAGE ])
193- return self .template
191+ return self .template
0 commit comments