Skip to content

Commit

Permalink
Remove bar groups and brackets when sorting bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake-Madden committed Sep 27, 2023
1 parent 84208b0 commit e2adbb5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/graphs/barchart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ namespace Wisteria::Graphs
if (barLabels.size() != GetBars().size())
{ return; }

// bar groups and brackets connected to bars' positions will need to be removed
m_barGroups.clear();
GetBarAxis().ClearBrackets();

// verify that provided labels are in the existing bars
// (if not, then add a empty bar for it)
for (const auto& label : labels)
Expand Down Expand Up @@ -602,8 +606,9 @@ namespace Wisteria::Graphs
GetBarAxis().IsReversed())
{ return; }

// bar groups connected to bars' positions will need to be removed
// bar groups and brackets connected to bars' positions will need to be removed
m_barGroups.clear();
GetBarAxis().ClearBrackets();

const bool isDisplayingOuterLabels = GetBarAxis().IsShowingOuterLabels();
GetBarAxis().ClearCustomLabels();
Expand Down
4 changes: 4 additions & 0 deletions src/graphs/barchart.h
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,8 @@ namespace Wisteria::Graphs
/// @param direction SortAscending to sort smallest-to-largest (A-Z),
/// going top-to-bottom or left-to-right.
/// SortDescending to sort largest-to-smallest (A-Z).
/// @warning If there are bar groups or brackets along the bar axis, then those
/// will be removed when sorting.
virtual void SortBars(const BarSortComparison sortMethod, const SortDirection direction);
/// @brief Sorts the bars (based on a specified order of axis labels).
/// This is similar to what @c forcats::fct_relevel() does in R.
Expand All @@ -1001,6 +1003,8 @@ namespace Wisteria::Graphs
/// Finally, all bar labels must be unique for the label ordering to work;
/// otherwise, the sort could not be deterministic. If there are multiple bars
/// with the same axis label, then this will return without sorting.
/// @warning If there are bar groups or brackets along the bar axis, then those
/// will be removed when sorting.
virtual void SortBars(std::vector<wxString> labels, const SortDirection direction);
/// @returns @c true if the bars can be sorted (i.e., reordered) in terms of bar length.
virtual bool IsSortable() const noexcept
Expand Down

0 comments on commit e2adbb5

Please sign in to comment.