Skip to content

Commit 80dc679

Browse files
committed
fix: correct axis label swapping for horizontal bar charts
1 parent ff6ac6c commit 80dc679

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

survey_dashboard/main.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,18 +307,18 @@ def select_data(question, data_filters, data_filters_method, filter_by=FILTER_BY
307307
print('data before adding All:', data)
308308
print('data_all keys:', list(data_all.keys()))
309309
print('data_all["All"] length:', len(data_all.get("All", [])))
310-
310+
311311
# Add "All" data if it's selected in the filters
312312
if "All" in data_filters:
313313
all_data = data_all.get("All", [])
314314
print('Adding All data, length:', len(all_data), 'x_value length:', len(data["x_value"]))
315-
315+
316316
# OPTION 2: When "All" + specific filters are selected, expand to show all research areas
317317
if "researchArea" in data:
318318
# Use full "All" data and expand x_value to all research areas
319319
data["All"] = all_data
320320
data["x_value"] = data_all["researchArea"]
321-
321+
322322
# Expand specific research area data to match full x_value length
323323
for key in data_filters:
324324
if key != "All" and key in data:
@@ -333,19 +333,19 @@ def select_data(question, data_filters, data_filters_method, filter_by=FILTER_BY
333333
# If not found, just pad with zeros
334334
padding = [0] * (len(data["x_value"]) - len(data[key]))
335335
data[key] = list(data[key]) + padding
336-
336+
337337
print('Research area: Expanded to show all research areas with aligned data')
338338
else:
339339
# For other questions: truncate to match x_value length
340340
if len(all_data) > len(data["x_value"]):
341341
data["All"] = all_data[:len(data["x_value"])]
342-
342+
343343
else:
344344
data["All"] = all_data
345-
346-
345+
346+
347347
print('data after adding All:', data)
348-
348+
349349
# Also expand Cum. Sum to match the new x_value length
350350
if "Cum. Sum" in data:
351351
cum_sum_data = data["Cum. Sum"]
@@ -357,7 +357,7 @@ def select_data(question, data_filters, data_filters_method, filter_by=FILTER_BY
357357
else:
358358
padding = [0] * (len(data["x_value"]) - len(cum_sum_data))
359359
data["Cum. Sum"] = list(cum_sum_data) + padding
360-
360+
361361
# print(data)
362362
# We create two ColumnDataSources, because they have to be n*n and
363363
# it is therefore not posible to put all specifics into one
@@ -888,9 +888,14 @@ def update(target, event, question_sel, f_choice, m_choice, q_filter, charttype)
888888
**display_options,
889889
) # df.data['factors'], legend_labels='legend_labels')#, figure=figure)
890890
elif charttype == "Horizontal Bar chart":
891+
# Swap the ranges for horizontal orientation
891892
y_range = display_options["y_range"]
892893
display_options["y_range"] = display_options["x_range"]
893894
display_options["x_range"] = y_range
895+
896+
# Swap the labels for horizontal orientation
897+
display_options["xlabel"] = "" # X axis lays vertically but shows categorical data
898+
display_options["ylabel"] = "Number of Answers" # Y axis now lays horizontally but still shows numerical data
894899
# TODO change tooltips...
895900
fig = bokeh_barchart(
896901
source,
@@ -899,8 +904,6 @@ def update(target, event, question_sel, f_choice, m_choice, q_filter, charttype)
899904
legend_labels=y_keys,
900905
fill_color=fill_colors,
901906
orientation="horizontal",
902-
xlabel="Number of Answers",
903-
ylabel="",
904907
**display_options,
905908
) #'horizontal')#df.data['factors'], legend_labels='legend_labels')#, figure=figure)
906909
elif charttype == "Pie chart":

0 commit comments

Comments
 (0)