Skip to content

Commit 4892780

Browse files
committed
getting the bars to show up appropriately when multiple research area filters are enabled
1 parent ad4c429 commit 4892780

1 file changed

Lines changed: 33 additions & 3 deletions

File tree

survey_dashboard/core/data.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,44 @@ def select_data(self, question, data_filters, data_filters_method, filter_by=FIL
159159
exclude.append(field)
160160
for filter_key in exclude:
161161
df = df[df[filter_by] != filter_key]
162-
data, y_keys = prepare_data_research_field(df, q_index)
162+
163+
# Special case: if we're querying the research area question itself,
164+
# we need different logic to avoid double-grouping by research areas
165+
if q_index_0 == filter_by: # This is the research area question
166+
# For research area distribution, create data structure directly
167+
data = {}
168+
# Use the full research area list as x_value for proper positioning
169+
data["x_value"] = data_all.get(q_index_0, [])
170+
171+
# Create arrays for each selected research area
172+
for area in data_filters:
173+
if area != "All":
174+
# Create array with value at correct position, zeros elsewhere
175+
area_array = np.zeros(len(data["x_value"]))
176+
if area in data["x_value"]:
177+
position = data["x_value"].index(area)
178+
area_count = len(df[df[filter_by] == area])
179+
area_array[position] = area_count
180+
data[area] = area_array
181+
182+
y_keys = [area for area in data_filters if area != "All"]
183+
else:
184+
# Normal case: use prepare_data_research_field for other questions
185+
data, y_keys = prepare_data_research_field(df, q_index)
163186

164187
# Add "All" data if it's selected in the filters
165188
if "All" in data_filters:
166189
all_data = data_all.get("All", [])
167190

168-
# When "All" + specific filters are selected, expand to show all research areas
169-
if "researchArea" in data:
191+
# Special handling for research area question
192+
if q_index_0 == filter_by: # This is the research area question
193+
# Add "All" data to our research area structure
194+
data["All"] = all_data
195+
# Make sure "All" is in y_keys
196+
if "All" not in y_keys:
197+
y_keys = ["All"] + y_keys
198+
elif "researchArea" in data:
199+
# When "All" + specific filters are selected, expand to show all research areas
170200
# Use full "All" data and expand x_value to all research areas
171201
data["All"] = all_data
172202
data["x_value"] = data_all["researchArea"]

0 commit comments

Comments
 (0)