@@ -76,11 +76,14 @@ def map_qkey_to_question(self, key: str, lang: str = LANGUAGE) -> str:
7676 def map_question_to_qkey (self , question : str , lang : str = LANGUAGE ) -> list :
7777 """
7878 Map a given question String to the corresponding columns keys in the dataframe
79-
79+
8080 usually this is one column, but for multiple choice this can be several columns.
81+ Handles question strings with or without the ★ correlation indicator prefix.
8182 """
8283 column_keys = []
83- key = HCS_QUESTIONS_REVERT [lang ][question ]
84+ # Strip the ★ indicator if present (used to mark correlation-compatible questions)
85+ clean_question = question .replace ("★ " , "" )
86+ key = HCS_QUESTIONS_REVERT [lang ][clean_question ]
8487 if key in HCS_MCList :
8588 print (f"Multiple Choice,{ key } " )
8689 # for multiple choice this is a list of subquestions
@@ -112,11 +115,10 @@ def get_real_research_areas(data_filters):
112115 pseudo_cats = [area for area in data_filters if area in pseudo_categories ]
113116 return real_areas , pseudo_cats
114117
115- print (question )
116118 q_index = self .map_question_to_qkey (question )
117- print (q_index )
118119 q_index_0 = q_index [0 ]
119- question_full = question
120+ # Strip ★ indicator for cleaner chart titles
121+ question_full = question .replace ("★ " , "" )
120122
121123 # Clean up missing columns
122124 q_index_clean = []
@@ -166,10 +168,17 @@ def get_real_research_areas(data_filters):
166168 key : data_all .get (key , []),
167169 "x_value" : data_all .get (key , [])
168170 }
171+ y_keys = ["All" ]
169172 else :
170- # Multiple columns case
171- data = data_all
172- y_keys = ["All" ] + [data_all .get (q_index_clean [0 ], [])]
173+ # Multiple columns case (multiple-choice questions)
174+ data = data_all .copy ()
175+ # For multiple-choice, get_all_values returns {All: values, last_key: labels}
176+ # We need to add x_value for the plotting code
177+ # The last key in q_index_clean contains the x-axis labels
178+ last_key = q_index_clean [- 1 ]
179+ if last_key in data_all and "x_value" not in data :
180+ data ["x_value" ] = data_all [last_key ]
181+ y_keys = data_filters
173182 else :
174183 # Handle filtering based on real research areas (not pseudo-categories)
175184 if real_research_areas :
@@ -266,7 +275,7 @@ def get_real_research_areas(data_filters):
266275 # Prepare display specifications
267276 ydata_spec = {}
268277 colors = []
269- for key in data_filters :
278+ for key in y_keys :
270279 colors .append (RESEARCH_AREA_COLORS [key ])
271280
272281 # Determine axis configuration
@@ -275,7 +284,8 @@ def get_real_research_areas(data_filters):
275284 xtype = HCS_dtypesWOmc [q_index_0 ]
276285
277286 if len (q_index ) > 1 : # multiple choice case
278- x_range = data ["x_value" ]
287+ # Defensive: ensure x_value exists, fallback to using q_index_0 data
288+ x_range = data .get ("x_value" , data .get (q_index_0 , []))
279289 width = 0.1
280290 elif xtype == "category" :
281291 x_range = HCS_orderedCats [q_index_0 ]
@@ -285,9 +295,9 @@ def get_real_research_areas(data_filters):
285295 width = 0.6
286296 y_range = None
287297
288- ydata_spec ["y_keys" ] = data_filters
298+ ydata_spec ["y_keys" ] = y_keys
289299 ydata_spec ["colors" ] = colors
290- ydata_spec ["legend_labels" ] = data_filters
300+ ydata_spec ["legend_labels" ] = y_keys
291301 selected = ColumnDataSource (data = data )
292302 ydata_spec = ColumnDataSource (data = ydata_spec )
293303
@@ -382,8 +392,9 @@ def select_data_corr(self, question, question2, data_filters, data_filters_metho
382392 ]
383393
384394 title = f""
385- xlabel = f"{ question } "
386- ylabel = f"{ question2 } "
395+ # Strip ★ indicator for cleaner axis labels
396+ xlabel = f"{ question .replace ('★ ' , '' )} "
397+ ylabel = f"{ question2 .replace ('★ ' , '' )} "
387398
388399 selected = ColumnDataSource (cross_tab )
389400
0 commit comments