|
18 | 18 | #include "base/math/floating.h"
|
19 | 19 | #include "base/math/range.h"
|
20 | 20 | #include "base/refl/auto_enum.h"
|
| 21 | +#include "base/text/naturalcmp.h" |
21 | 22 | #include "chart/main/style.h"
|
22 | 23 | #include "chart/options/align.h"
|
23 | 24 | #include "chart/options/channel.h"
|
@@ -135,19 +136,40 @@ std::vector<PlotBuilder::BucketInfo> PlotBuilder::sortedBuckets(
|
135 | 136 | {},
|
136 | 137 | &BucketInfo::index);
|
137 | 138 | if (it == sorted.end() || it->index != idx.itemId)
|
138 |
| - it = sorted.emplace(it, idx.itemId, 0.0); |
| 139 | + it = sorted.emplace(it, |
| 140 | + idx.itemId, |
| 141 | + 0.0, |
| 142 | + (marker.*buckets.marker_id_get).label |
| 143 | + ? &(marker.*buckets.marker_id_get) |
| 144 | + .label->value |
| 145 | + : nullptr); |
139 | 146 |
|
140 | 147 | it->size += marker.size.getCoord(
|
141 | 148 | !plot->getOptions()->getOrientation());
|
142 | 149 | }
|
143 | 150 |
|
144 |
| - if (plot->getOptions()->getChannels().axisPropsAt(axisIndex).sort |
145 |
| - == Sort::byValue) |
| 151 | + switch (plot->getOptions() |
| 152 | + ->getChannels() |
| 153 | + .axisPropsAt(axisIndex) |
| 154 | + .sort) { |
| 155 | + case Sort::byValue: |
146 | 156 | std::ranges::stable_sort(sorted,
|
147 | 157 | [](const BucketInfo &lhs, const BucketInfo &rhs)
|
148 | 158 | {
|
149 | 159 | return Math::Floating::less(lhs.size, rhs.size);
|
150 | 160 | });
|
| 161 | + break; |
| 162 | + case Sort::byLabel: |
| 163 | + std::ranges::stable_sort(sorted, |
| 164 | + [](const BucketInfo &lhs, const BucketInfo &rhs) |
| 165 | + { |
| 166 | + if (rhs.label == nullptr || lhs.label == nullptr) |
| 167 | + return lhs.label != nullptr; |
| 168 | + return Text::NaturalCmp{}(*lhs.label, *rhs.label); |
| 169 | + }); |
| 170 | + break; |
| 171 | + default: break; |
| 172 | + } |
151 | 173 |
|
152 | 174 | if (plot->getOptions()
|
153 | 175 | ->getChannels()
|
@@ -440,10 +462,10 @@ void PlotBuilder::calcAxis(const Data::DataTable &dataTable,
|
440 | 462 | }
|
441 | 463 | else {
|
442 | 464 | for (auto merge =
|
443 |
| - plot->getOptions()->dimLabelIndex(+type) == 0 |
444 |
| - && (type != plot->getOptions()->mainAxisType() |
445 |
| - || axisProps.sort != Sort::byValue |
446 |
| - || scale.dimensions().size() == 1); |
| 465 | + axisProps.sort == Sort::byLabel |
| 466 | + || (plot->getOptions()->dimLabelIndex(+type) == 0 |
| 467 | + && (axisProps.sort == Sort::none |
| 468 | + || scale.dimensions().size() == 1)); |
447 | 469 | const auto &marker : plot->markers) {
|
448 | 470 | if (!marker.enabled) continue;
|
449 | 471 |
|
|
0 commit comments