Skip to content

Commit c8cd591

Browse files
committed
fixed correlational graph functionality
1 parent f5a54e2 commit c8cd591

8 files changed

Lines changed: 306 additions & 126 deletions

File tree

survey_dashboard/app.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# Initialize UI components
3434
widget_factory = WidgetFactory(data_processor)
3535
layout_manager = LayoutManager()
36-
callback_manager = CallbackManager(data_processor, chart_manager)
36+
callback_manager = CallbackManager(data_processor, chart_manager, widget_factory)
3737

3838
print("Creating widgets...")
3939

@@ -145,6 +145,10 @@ def bind_callbacks():
145145
methods_tools_tabs=methods_tools_tabs
146146
)
147147

148+
# Wire correlation_row to callbacks for visibility toggling
149+
correlation_row = layout_manager.get_correlation_row()
150+
callback_manager.set_correlation_row(correlation_row)
151+
148152
print("Setting up template...")
149153

150154
# Setup template and make servable

survey_dashboard/core/charts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ def create_chart(self, question, data_filters, data_filters_method, chart_type):
175175
df, ydata_spec, display_options = self.data_processor.select_data(
176176
question, data_filters, data_filters_method
177177
)
178-
178+
179179
y_keys = ydata_spec.data["y_keys"]
180180
fill_colors = ydata_spec.data["colors"]
181-
181+
182182
if chart_type == "Vertical Bar chart":
183183
fig = bokeh_barchart(
184184
df,

survey_dashboard/core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def get_data_path():
8888
TOOLTIPS = [("Title", "@title"), ("Answer", "@x"), ("Number of Answers", "@y")]
8989

9090
# Widget Configuration
91-
CHART_TYPES = ['Vertical Bar chart', 'Horizontal Bar chart', 'Pie chart']
91+
# Note: Pie chart removed due to data structure incompatibilities with multiple filters
92+
CHART_TYPES = ['Vertical Bar chart', 'Horizontal Bar chart']
9293

9394
# Word Cloud Content Configuration
9495
WORDCLOUD_CONTENT = {

survey_dashboard/core/data.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)