Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix-nan-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed May 16, 2024
2 parents e5aa3f3 + 573e50b commit 4c78ab5
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 65 deletions.
9 changes: 3 additions & 6 deletions src/base/anim/interpolated.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ template <typename Type> class Weighted
[[nodiscard]] bool hasValue() const { return weight > 0.0; }
};

enum class InterpolateIndex : bool {
first = false,
secondIfExists = true
};
enum class InterpolateIndex : bool { first = false, second = true };

using enum InterpolateIndex;

Expand Down Expand Up @@ -125,7 +122,7 @@ template <typename Type> class Interpolated
throw std::logic_error("Invalid Weigthed Pair");
}

[[nodiscard]] const Weighted<Type> &get(
[[nodiscard]] const Weighted<Type> &get_or_first(
InterpolateIndex index) const
{
return values[has_second && static_cast<bool>(index)];
Expand Down Expand Up @@ -175,7 +172,7 @@ template <typename Type> class Interpolated
{
if (values[0].hasValue()) branch(first, values[0]);
if (has_second && values[1].hasValue())
branch(secondIfExists, values[1]);
branch(second, values[1]);
}

template <class T, class Fun> T combine(Fun &&branch) const
Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct DimensionAxis
::Anim::InterpolateIndex index) const
{
return (index == ::Anim::first && start)
|| (index == ::Anim::secondIfExists && end);
|| (index == ::Anim::second && end);
}
};
using Values = std::multimap<Data::SliceIndex, Item>;
Expand Down
3 changes: 2 additions & 1 deletion src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ void Plot::clearEmptyBuckets(const Buckets &buckets, bool main) const

void Plot::addSpecLayout(Buckets &buckets)
{
auto geometry = getOptions()->geometry.get(::Anim::first).value;
auto geometry =
getOptions()->geometry.get_or_first(::Anim::first).value;
if (auto &markers = getMarkers();
geometry == ShapeType::line || geometry == ShapeType::area) {
Charts::TableChart::setupVector(markers, true);
Expand Down
3 changes: 2 additions & 1 deletion src/chart/main/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ struct Font
[[nodiscard]] std::string calculatedFamily() const
{
if (fontFamily.has_value())
if (auto &&ff = fontFamily->get(::Anim::first).value;
if (auto &&ff =
fontFamily->get_or_first(::Anim::first).value;
!ff.empty())
return ff;

Expand Down
4 changes: 2 additions & 2 deletions src/chart/rendering/colorbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ ColorBuilder::ColorBuilder(const LighnessRange &lighnessRange,
Gfx::Color ColorBuilder::render(
const Anim::Interpolated<Gen::ColorBase> &colorBase) const
{
if (!colorBase.get(::Anim::first).value.isDiscrete()
&& !colorBase.get(::Anim::secondIfExists)
if (!colorBase.get_or_first(::Anim::first).value.isDiscrete()
&& !colorBase.get_or_first(::Anim::second)
.value.isDiscrete()) {
auto pos = colorBase.combine<double>(
[](const Gen::ColorBase &base)
Expand Down
61 changes: 32 additions & 29 deletions src/chart/rendering/drawaxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Geom::Point DrawAxes::getTitleBasePos(Gen::ChannelId axisIndex,

double orthogonal{0.0};

switch (titleStyle.position->get(index).value) {
switch (titleStyle.position->get_or_first(index).value) {
default:
case Pos::min_edge: break;
case Pos::max_edge: orthogonal = 1.0; break;
Expand All @@ -101,7 +101,7 @@ Geom::Point DrawAxes::getTitleBasePos(Gen::ChannelId axisIndex,

double parallel{0.0};

switch (titleStyle.vposition->get(index).value) {
switch (titleStyle.vposition->get_or_first(index).value) {
default:
case VPos::end: parallel = 1.0; break;
case VPos::middle: parallel = 0.5; break;
Expand Down Expand Up @@ -130,9 +130,9 @@ Geom::Point DrawAxes::getTitleOffset(Gen::ChannelId axisIndex,
}
};

auto orthogonal = fades
? calcSide(titleStyle.side->get(index).value)
: titleStyle.side->combine<double>(calcSide);
auto orthogonal =
fades ? calcSide(titleStyle.side->get_or_first(index).value)
: titleStyle.side->combine<double>(calcSide);

auto calcVSide = [](const auto &side)
{
Expand All @@ -145,9 +145,9 @@ Geom::Point DrawAxes::getTitleOffset(Gen::ChannelId axisIndex,
}
};

auto parallel = fades
? calcVSide(titleStyle.vside->get(index).value)
: titleStyle.vside->combine<double>(calcVSide);
auto parallel =
fades ? calcVSide(titleStyle.vside->get_or_first(index).value)
: titleStyle.vside->combine<double>(calcVSide);

return axisIndex == Gen::ChannelId::x
? Geom::Point{parallel, -orthogonal}
Expand All @@ -165,12 +165,13 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const
|| titleString.maxIndex();

for (auto &&index : Type::Bools{fades}) {
auto title = titleString.get(index);
auto title = titleString.get_or_first(index);
if (title.value.empty()) continue;

auto weight = title.weight
* titleStyle.position->get(index).weight
* titleStyle.vposition->get(index).weight;
auto weight =
title.weight
* titleStyle.position->get_or_first(index).weight
* titleStyle.vposition->get_or_first(index).weight;

const Gfx::Font font(titleStyle);
canvas.setFont(font);
Expand All @@ -182,9 +183,8 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const

auto normal = Geom::Point::Ident(true);

auto offset = getTitleOffset(axisIndex,
index,
fades == ::Anim::secondIfExists);
auto offset =
getTitleOffset(axisIndex, index, fades == ::Anim::second);

auto posDir = coordSys.convertDirectionAt(
{relCenter, relCenter + normal});
Expand All @@ -207,16 +207,17 @@ void DrawAxes::drawTitle(Gen::ChannelId axisIndex) const

auto angle =
-M_PI / 2.0
* (fades == ::Anim::secondIfExists
? titleStyle.orientation->get(index).value
* (fades == ::Anim::second
? titleStyle.orientation->get_or_first(index)
.value
== Styles::AxisTitle::Orientation::vertical
: titleStyle.orientation->factor<double>(
Styles::AxisTitle::Orientation::vertical));

auto orientedSize =
fades == ::Anim::secondIfExists
fades == ::Anim::second
? calcOrientation(
titleStyle.orientation->get(index).value)
titleStyle.orientation->get_or_first(index).value)
: titleStyle.orientation->combine<Geom::Size>(
calcOrientation);

Expand Down Expand Up @@ -315,11 +316,12 @@ void DrawAxes::drawDimensionLabel(bool horizontal,
auto relCenter =
refPos + ident * it->second.range.middle();

auto under = labelStyle.position->interpolates()
? labelStyle.side->get(index).value
== Styles::AxisLabel::Side::negative
: labelStyle.side->factor<double>(
Styles::AxisLabel::Side::negative);
auto under =
labelStyle.position->interpolates()
? labelStyle.side->get_or_first(index).value
== Styles::AxisLabel::Side::negative
: labelStyle.side->factor<double>(
Styles::AxisLabel::Side::negative);

auto sign = 1 - 2 * under;

Expand Down Expand Up @@ -347,15 +349,16 @@ void DrawAxes::drawDimensionLabel(bool horizontal,

if (labelStyle.position->interpolates()
&& text.interpolates())
draw(text.get(index), position.weight);
draw(text.get_or_first(index), position.weight);
if (!labelStyle.position->interpolates()
&& !text.interpolates())
draw(text.get(::Anim::first));
draw(text.get_or_first(::Anim::first));
else if (labelStyle.position->interpolates())
draw(text.get(::Anim::first), position.weight);
draw(text.get_or_first(::Anim::first),
position.weight);
else if (text.interpolates()) {
draw(text.get(::Anim::first));
draw(text.get(::Anim::secondIfExists));
draw(text.get_or_first(::Anim::first));
draw(text.get_or_first(::Anim::second));
}
});
}
Expand Down
8 changes: 4 additions & 4 deletions src/chart/rendering/drawinterlacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ void DrawInterlacing::drawDataLabel(
auto &&normal = Geom::Point::Ident(horizontal);
for (auto &&index : Type::Bools{interpolates}) {
if (labelStyle.position->interpolates()
&& !axisEnabled.get(index).value)
&& !axisEnabled.get_or_first(index).value)
continue;
auto &&position = labelStyle.position->get(index);
auto &&position = labelStyle.position->get_or_first(index);

Geom::Point refPos = tickPos;

Expand All @@ -253,7 +253,7 @@ void DrawInterlacing::drawDataLabel(
}

auto under = labelStyle.position->interpolates()
? labelStyle.side->get(index).value
? labelStyle.side->get_or_first(index).value
== Styles::AxisLabel::Side::negative
: labelStyle.side->factor<double>(
Styles::AxisLabel::Side::negative);
Expand All @@ -262,7 +262,7 @@ void DrawInterlacing::drawDataLabel(
coordSys.convertDirectionAt({refPos, refPos + normal})
.extend(1 - 2 * under);

auto &&wUnit = unit.get(index);
auto &&wUnit = unit.get_or_first(index);
auto str = Text::SmartString::fromPhysicalValue(value,
*labelStyle.numberFormat,
static_cast<size_t>(*labelStyle.maxFractionDigits),
Expand Down
5 changes: 3 additions & 2 deletions src/chart/rendering/drawmarkerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,15 @@ void DrawMarkerInfo::draw(Gfx::ICanvas &canvas,
const Geom::Rect &boundary) const
{
for (const auto &info : plot->getMarkersInfo()) {
auto &&[cnt1, weight1] = info.second.get(::Anim::first);
auto &&[cnt1, weight1] =
info.second.get_or_first(::Anim::first);
if (!info.second.interpolates() && cnt1) {
MarkerDC dc(*this, canvas, boundary, cnt1);
dc.draw(weight1);
}
else if (info.second.interpolates()) {
auto &&[cnt2, weight2] =
info.second.get(::Anim::secondIfExists);
info.second.get_or_first(::Anim::second);
if (!cnt1 && cnt2)
fadeInMarkerInfo(canvas, boundary, cnt2, weight2);
else if (cnt1 && !cnt2)
Expand Down
25 changes: 12 additions & 13 deletions src/chart/rendering/markerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,14 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
&value = ::Anim::Weighted(
Gen::Options::MarkerIndex{}))
{
if (index == ::Anim::secondIfExists && !other) {
if (index == ::Anim::second && !other) {
other.emplace(
AbstractMarker::createInterpolated(ctx(),
blended.marker,
::Anim::secondIfExists));
::Anim::second));
}
const auto &blended0 = index == ::Anim::secondIfExists
? *other
: blended;
const auto &blended0 =
index == ::Anim::second ? *other : blended;

auto lineFactor =
getOptions().geometry.factor<double>(
Expand Down Expand Up @@ -160,10 +159,10 @@ void MarkerRenderer::drawMarkers(Gfx::ICanvas &canvas,
auto lineIndex =
Gen::isConnecting(
getOptions()
.geometry.get(::Anim::first)
.geometry.get_or_first(::Anim::first)
.value)
? ::Anim::first
: ::Anim::secondIfExists;
: ::Anim::second;

drawMarker(lineIndex);
}
Expand All @@ -185,14 +184,14 @@ void MarkerRenderer::drawLabels(Gfx::ICanvas &canvas) const
if (blended.marker.enabled == false) continue;
drawLabel(canvas,
blended,
axis.unit.get(::Anim::first).value,
axis.unit.get_or_first(::Anim::first).value,
keepMeasure,
::Anim::first);
drawLabel(canvas,
blended,
axis.unit.get(::Anim::secondIfExists).value,
axis.unit.get_or_first(::Anim::second).value,
keepMeasure,
::Anim::secondIfExists);
::Anim::second);
}
}

Expand All @@ -211,7 +210,7 @@ bool MarkerRenderer::shouldDrawMarkerBody(
enabled |= prev0->enabled != false;
if (const auto *prev1 = ConnectingMarker::getPrev(marker,
plot->getMarkers(),
::Anim::secondIfExists))
::Anim::second))
enabled |= prev1->enabled != false;
}
return enabled;
Expand Down Expand Up @@ -302,7 +301,7 @@ void MarkerRenderer::drawLabel(Gfx::ICanvas &canvas,

auto weight =
marker.label.interpolates() || index == ::Anim::first
? marker.label.get(index).weight
? marker.label.get_or_first(index).weight
: 0.0;
if (weight == 0.0) return;

Expand Down Expand Up @@ -342,7 +341,7 @@ std::string MarkerRenderer::getLabelText(
::Anim::InterpolateIndex index) const
{
const auto &labelStyle = rootStyle.plot.marker.label;
const auto &labelValue = label.get(index).value;
const auto &labelValue = label.get_or_first(index).value;

auto needsInterpolation = label.interpolates() && keepMeasure;

Expand Down
5 changes: 3 additions & 2 deletions src/chart/rendering/markers/abstractmarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ AbstractMarker AbstractMarker::createInterpolated(
{
const auto &options = ctx.getOptions();

auto fromShapeType = options.geometry.get(::Anim::first).value;
auto fromShapeType =
options.geometry.get_or_first(::Anim::first).value;

auto fromMarker = create(ctx, marker, fromShapeType, lineIndex);

auto toShapeType =
options.geometry.get(::Anim::secondIfExists).value;
options.geometry.get_or_first(::Anim::second).value;

if (fromShapeType == toShapeType) return fromMarker;

Expand Down
11 changes: 7 additions & 4 deletions src/chart/rendering/markers/connectingmarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,

labelEnabled = enabled && marker.enabled;

auto weight = marker.prevMainMarkerIdx.get(lineIndex).weight;
auto weight =
marker.prevMainMarkerIdx.get_or_first(lineIndex).weight;

connected = enabled && Math::FuzzyBool(weight);

Expand All @@ -42,8 +43,9 @@ ConnectingMarker::ConnectingMarker(const DrawingContext &ctx,
enabled && (marker.enabled || prev->enabled);
connected =
connected && (prev->enabled || marker.enabled);
if (prev->mainId.get(lineIndex).value.itemId
> marker.mainId.get(lineIndex).value.itemId) {
if (prev->mainId.get_or_first(lineIndex).value.itemId
> marker.mainId.get_or_first(lineIndex)
.value.itemId) {
linear = linear || polar.more();
connected = connected && polar.more() && horizontal;
enabled = enabled && polar && horizontal;
Expand Down Expand Up @@ -127,7 +129,8 @@ const Gen::Marker *ConnectingMarker::getPrev(
const Gen::Plot::Markers &markers,
::Anim::InterpolateIndex lineIndex)
{
const auto &prevId = marker.prevMainMarkerIdx.get(lineIndex);
const auto &prevId =
marker.prevMainMarkerIdx.get_or_first(lineIndex);
return (prevId.weight > 0.0) ? &markers[prevId.value] : nullptr;
}

Expand Down

0 comments on commit 4c78ab5

Please sign in to comment.