Skip to content

Commit 159c07c

Browse files
committed
Normalize split chart inside addSeparation
1 parent d7f8c4b commit 159c07c

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

src/base/math/range.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ template <std::floating_point T = double> struct Range
4242

4343
[[nodiscard]] bool includes(const T &value) const
4444
{
45-
return !less(value, min) && !less(max, value);
45+
return !is_lt(std::weak_order(value, min))
46+
&& !is_lt(std::weak_order(max, value));
4647
}
4748

4849
[[nodiscard]] T rescale(const T &value, T def = 0.5) const

src/chart/generator/plotbuilder.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ void PlotBuilder::calcAxises(const Data::DataTable &dataTable,
357357
for (auto &&[axis, needRanges, boundSize] :
358358
{std::tuple{mainAxis, mainRanges.empty(), mainBoundRect},
359359
{!mainAxis, subRanges.empty(), subBoundRect}}) {
360+
if (!needRanges) continue;
360361

361362
for (auto &marker : plot->markers) {
362363
auto &&markerSize = marker.getSizeBy(axis);
@@ -368,7 +369,7 @@ void PlotBuilder::calcAxises(const Data::DataTable &dataTable,
368369
{boundSize.rescale(markerSize.min, 0.0),
369370
boundSize.rescale(markerSize.max, 0.0)});
370371
}
371-
if (needRanges) stats.setIfRange(axis, boundSize);
372+
stats.setIfRange(axis, boundSize);
372373
}
373374

374375
for (auto &&[ch, ranges] :
@@ -595,17 +596,22 @@ PlotBuilder::addSeparation(const Buckets &buckets,
595596
onMax += res[i].containsValues.size();
596597
}
597598

599+
if (plot->getOptions()->coordSystem == CoordSystem::polar
600+
&& axisIndex == AxisId::x)
601+
onMax += splitSpace;
602+
598603
for (auto &&bucket : buckets)
599604
for (auto &&[marker, idx] : bucket) {
600605
auto buc = res[idx.itemId];
601606
auto markerSize = marker.getSizeBy(axisIndex);
602607

603608
marker.setSizeBy(axisIndex,
604-
Base::Align{align,
605-
buc.atRange - buc.atRange.min
606-
+ buc.containsValues.min}
609+
(Base::Align{align,
610+
buc.atRange - buc.atRange.min
611+
+ buc.containsValues.min}
607612
.getAligned(markerSize - markerSize.min)
608-
+ buc.atRange.min - buc.containsValues.min);
613+
+ buc.atRange.min - buc.containsValues.min)
614+
/ onMax);
609615
}
610616

611617
auto alignedRange = maxRange;

src/chart/options/options.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ std::optional<LegendId> Options::getAutoLegend() const
293293
return std::nullopt;
294294
}
295295

296-
void Options::setAutoRange(bool hPositive, bool vPositive)
296+
void Options::setAutoRange(bool hPositive,
297+
bool vPositive,
298+
bool isSplit)
297299
{
298300
auto &v = getChannels().at(AxisId::y);
299301
auto &h = getChannels().at(AxisId::x);
@@ -302,7 +304,7 @@ void Options::setAutoRange(bool hPositive, bool vPositive)
302304
auto &&cart = coordSystem.get() == CoordSystem::cartesian;
303305
auto &&nrect = geometry != ShapeType::rectangle;
304306

305-
if (cart && hHasMeasure && (!vHasMeasure || nrect))
307+
if ((cart || isSplit) && hHasMeasure && (!vHasMeasure || nrect))
306308
setMeasureRange(h, hPositive);
307309
else if (!cart && hHasMeasure && !vHasMeasure && v.hasDimension())
308310
setRange(h, 0.0_perc, 133.0_perc);

src/chart/options/options.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ class Options : public OptionProperties
168168
static MarkerInfoId generateMarkerInfoId();
169169

170170
void setAutoParameters();
171-
void setAutoRange(bool hPositive, bool vPositive);
171+
void setAutoRange(bool hPositive,
172+
bool vPositive,
173+
bool isSplit = false);
172174

173175
[[nodiscard]] bool labelsShownFor(
174176
const Data::SeriesIndex &series) const;

src/chart/rendering/drawaxes.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,19 @@ const DrawAxes &&DrawAxes::init() &&
176176
if (measEnabled == 0.0) continue;
177177
auto step = axis.measure.step.combine();
178178

179+
using Math::Floating::less;
180+
179181
auto &&[min, max] = std::minmax(
180182
axis.measure.step.get_or_first(::Anim::first).value,
181183
axis.measure.step.get_or_first(::Anim::second).value,
182-
Math::Floating::less);
184+
less);
183185

184186
auto stepHigh =
185-
std::clamp(Math::Renard::R5().ceil(step), min, max);
186-
auto stepLow =
187-
std::clamp(Math::Renard::R5().floor(step), min, max);
187+
std::clamp(Math::Renard::R5().ceil(step), min, max, less);
188+
auto stepLow = std::clamp(Math::Renard::R5().floor(step),
189+
min,
190+
max,
191+
less);
188192

189193
if (Math::Floating::is_zero(axis.measure.range.size()))
190194
step = stepHigh = stepLow = 1.0;

0 commit comments

Comments
 (0)