|
19 | 19 | #include "base/math/floating.h" |
20 | 20 | #include "base/math/range.h" |
21 | 21 | #include "base/refl/auto_enum.h" |
| 22 | +#include "base/text/naturalcmp.h" |
22 | 23 | #include "chart/main/style.h" |
23 | 24 | #include "chart/options/align.h" |
24 | 25 | #include "chart/options/channel.h" |
@@ -161,19 +162,40 @@ std::vector<PlotBuilder::BucketSortInfo> PlotBuilder::sortedBuckets( |
161 | 162 | {}, |
162 | 163 | &BucketSortInfo::index); |
163 | 164 | if (it == sorted.end() || it->index != idx.itemId) |
164 | | - it = sorted.emplace(it, idx.itemId, 0.0); |
| 165 | + it = sorted.emplace(it, |
| 166 | + idx.itemId, |
| 167 | + 0.0, |
| 168 | + (marker.*buckets.marker_id_get).label |
| 169 | + ? &(marker.*buckets.marker_id_get) |
| 170 | + .label->value |
| 171 | + : nullptr); |
165 | 172 |
|
166 | 173 | it->size += marker.size.getCoord( |
167 | 174 | !plot->getOptions()->getOrientation()); |
168 | 175 | } |
169 | 176 |
|
170 | | - if (plot->getOptions()->getChannels().axisPropsAt(axisIndex).sort |
171 | | - == Sort::byValue) |
| 177 | + switch (plot->getOptions() |
| 178 | + ->getChannels() |
| 179 | + .axisPropsAt(axisIndex) |
| 180 | + .sort) { |
| 181 | + case Sort::byValue: |
172 | 182 | std::ranges::stable_sort(sorted, |
173 | 183 | [](const BucketSortInfo &lhs, const BucketSortInfo &rhs) |
174 | 184 | { |
175 | 185 | return Math::Floating::less(lhs.size, rhs.size); |
176 | 186 | }); |
| 187 | + break; |
| 188 | + case Sort::byLabel: |
| 189 | + std::ranges::stable_sort(sorted, |
| 190 | + [](const BucketInfo &lhs, const BucketInfo &rhs) |
| 191 | + { |
| 192 | + if (rhs.label == nullptr || lhs.label == nullptr) |
| 193 | + return lhs.label != nullptr; |
| 194 | + return Text::NaturalCmp{}(*lhs.label, *rhs.label); |
| 195 | + }); |
| 196 | + break; |
| 197 | + default: break; |
| 198 | + } |
177 | 199 |
|
178 | 200 | if (plot->getOptions() |
179 | 201 | ->getChannels() |
@@ -476,10 +498,10 @@ void PlotBuilder::calcAxis(const Data::DataTable &dataTable, |
476 | 498 | } |
477 | 499 | else { |
478 | 500 | for (auto merge = |
479 | | - plot->getOptions()->dimLabelIndex(+type) == 0 |
480 | | - && (type != plot->getOptions()->mainAxisType() |
481 | | - || axisProps.sort != Sort::byValue |
482 | | - || scale.dimensions().size() == 1); |
| 501 | + axisProps.sort == Sort::byLabel |
| 502 | + || (plot->getOptions()->dimLabelIndex(+type) == 0 |
| 503 | + && (axisProps.sort == Sort::none |
| 504 | + || scale.dimensions().size() == 1)); |
483 | 505 | const auto &marker : plot->markers) { |
484 | 506 | if (!marker.enabled) continue; |
485 | 507 |
|
|
0 commit comments