@@ -304,6 +304,17 @@ def update_pie_chart_dock(self, sheet_dict: Dict[Any, Any]) -> None:
304304 clear_layout (self .pie_chart_layout )
305305 categorybox = self .dataselectiongroupbox .category_combobox
306306 categories : List [str ] = [categorybox .itemText (i ) for i in range (categorybox .count ())]
307+
308+ # Create a mapping for a fixed ordering per category using the first sheet encountered that has it.
309+ common_order : Dict [str , List [str ]] = {}
310+ for category in categories :
311+ common_order [category ] = []
312+ for sheets in sheet_dict .values ():
313+ if category in sheets :
314+ for col in sheets [category ].data_columns :
315+ if col not in common_order [category ]:
316+ common_order [category ].append (col )
317+
307318 timepoint : int = - 1
308319 file_comboboxes = self .dataselectiongroupbox .file_comboboxes
309320 labels : List [QLabel ] = JsdWindow ._create_pie_chart_labels (sheet_dict , file_comboboxes )
@@ -317,9 +328,17 @@ def update_pie_chart_dock(self, sheet_dict: Dict[Any, Any]) -> None:
317328 if category not in sheets :
318329 continue
319330 df = sheets [category ].df
320- cols_to_use = sheets [category ].data_columns
331+ sheet_order = sheets [category ].data_columns
332+ # Use common order, but include only columns that exist in the current sheet.
333+ final_order = [col for col in common_order .get (category , []) if col in sheet_order ]
334+ # Append any extra columns from the sheet that are not already in final_order.
335+ final_order += [col for col in sheet_order if col not in final_order ]
336+ # Ensure 'Not Reported' is always the last column.
337+ if "Not Reported" in final_order :
338+ final_order = [col for col in final_order if col != "Not Reported" ] + ["Not Reported" ]
339+
321340 series = QPieSeries ()
322- for col in cols_to_use :
341+ for col in final_order :
323342 value = df [col ].iloc [timepoint ]
324343 if value > 0 :
325344 series .append (col , value )
0 commit comments