Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into axis_refactor_v11c2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/chart/rendering/drawinterlacing.cpp
  • Loading branch information
schaumb committed Nov 26, 2024
2 parents 2fa09cd + 3c6b916 commit 0b09de3
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/base/type/uniquelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ template <class T> class UniqueList
struct CommonIterateVal
{
const T &value;
const std::size_t *othIx;
const std::size_t *otherIx;
};

struct common_iterator
Expand Down
5 changes: 3 additions & 2 deletions src/chart/generator/buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ struct Buckets
});
}

[[nodiscard]] bool operator!=(const const_iterator &oth) const
[[nodiscard]] bool operator!=(
const const_iterator &other) const
{
return data.data() != oth.data.data();
return data.data() != other.data.data();
}

const_iterator &operator++();
Expand Down
139 changes: 73 additions & 66 deletions src/chart/rendering/drawinterlacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,9 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const
|| guides.interlacings == false)
return;

std::map<double, double> othWeights{{0.0, 0.0}, {1.0, 0.0}};

const auto &othGuides = parent.plot->guides.at(!axisIndex);
const auto &othAxisStyle =
parent.rootStyle.plot.getAxis(!axisIndex);
if (!othAxisStyle.interlacing.color->isTransparent()
&& othGuides.interlacings != false)
for (const auto &othInterval :
parent.getIntervals(!axisIndex)) {
if (Math::Floating::is_zero(othInterval.isSecond))
continue;
auto min = std::max(othInterval.range.getMin(), 0.0);
auto max = std::min(othInterval.range.getMax(), 1.0);
auto mprev = std::prev(othWeights.upper_bound(min));
auto mnext = othWeights.lower_bound(max);

if (mprev->first < min)
mprev =
othWeights.try_emplace(mprev, min, mprev->second);
if (mnext->first > max)
mnext = othWeights.try_emplace(mnext,
max,
std::prev(mnext)->second);

while (mprev != mnext)
mprev++->second +=
Math::FuzzyBool::And<double>(othInterval.weight,
othInterval.isSecond,
othGuides.interlacings);
}

auto orientation = !Gen::orientation(axisIndex);
auto otherWeights = getInterlacingWeights(!axisIndex);
auto &&otherInterlacingColor =
*parent.rootStyle.plot.getAxis(!axisIndex).interlacing.color;

parent.painter.setPolygonToCircleFactor(0);
parent.painter.setPolygonStraightFactor(0);
Expand All @@ -81,60 +52,39 @@ void DrawInterlacing::drawGeometries(Gen::AxisId axisIndex) const
Math::Floating::less)
- clippedBottom;

auto rect = [&](const double &from, const double &to)
auto rect = [&, orientation = orientation(axisIndex)](
const double &from,
const double &to)
{
return Geom::Rect{
Geom::Point::Coord(orientation, from, clippedBottom),
Geom::Point::Coord(orientation, clippedBottom, from),
{Geom::Size::Coord(orientation,
to - from,
clippedSize)}};
clippedSize,
to - from)}};
};

auto weight = Math::FuzzyBool::And<double>(interval.weight,
interval.isSecond,
guides.interlacings);
auto interlacingColor = *axisStyle.interlacing.color * weight;

for (auto first = othWeights.begin(),
for (auto first = otherWeights.begin(),
next = std::next(first),
last = othWeights.end();
last = otherWeights.end();
next != last;
++next, ++first) {
if (Math::Floating::is_zero(first->second))
drawInterlacing(axisIndex,
interlacingColor,
rect(first->first, next->first));
else if (axisIndex == Gen::AxisId::y) {
auto color =
interlacingColor
+ *othAxisStyle.interlacing.color * first->second;

color.alpha =
1
- (1
- axisStyle.interlacing.color->alpha
* weight)
* (1
- othAxisStyle.interlacing.color->alpha
* first->second);

if (weight + first->second > 1.0)
color = Math::Niebloid::interpolate(
color
* std::max({std::abs(axisStyle.interlacing
.color->red
- color.red),
std::abs(
axisStyle.interlacing.color->green
- color.green),
std::abs(
axisStyle.interlacing.color->blue
- color.blue)}),
color,
2.0 - (weight + first->second));
drawInterlacing(first->second > weight ? !axisIndex
: axisIndex,
color,
getCrossingInterlacingColor(
*axisStyle.interlacing.color,
weight,
otherInterlacingColor,
first->second),
rect(first->first, next->first));
}
}
Expand Down Expand Up @@ -313,4 +263,61 @@ void DrawInterlacing::drawSticks(double tickLength,
canvas.restore();
}

std::map<double, double> DrawInterlacing::getInterlacingWeights(
Gen::AxisId axisIndex) const
{
std::map<double, double> weights{{0.0, 0.0}, {1.0, 0.0}};

auto &&guides = parent.plot->guides.at(axisIndex);
auto &&axisStyle = parent.rootStyle.plot.getAxis(axisIndex);
if (axisStyle.interlacing.color->isTransparent()
|| guides.interlacings == false)
return weights;

for (auto &&interval : parent.getIntervals(axisIndex)) {
if (Math::Floating::is_zero(interval.isSecond)) continue;
auto min = std::max(interval.range.getMin(), 0.0);
auto max = std::min(interval.range.getMax(), 1.0);
auto mprev = std::prev(weights.upper_bound(min));
auto mnext = weights.lower_bound(max);

if (mprev->first < min)
mprev = weights.try_emplace(mprev, min, mprev->second);
if (mnext->first > max)
mnext = weights.try_emplace(mnext,
max,
std::prev(mnext)->second);

while (mprev != mnext)
mprev++->second +=
Math::FuzzyBool::And<double>(interval.weight,
interval.isSecond,
guides.interlacings);
}
return weights;
}

Gfx::Color DrawInterlacing::getCrossingInterlacingColor(
const Gfx::Color &mainColor,
double mainWeight,
const Gfx::Color &otherColor,
double otherWeight)
{
auto color = mainColor * mainWeight + otherColor * otherWeight;

color.alpha = 1
- (1 - mainColor.alpha * mainWeight)
* (1 - otherColor.alpha * otherWeight);

if (mainWeight + otherWeight > 1.0)
color = Math::Niebloid::interpolate(color,
color
* std::max({std::abs(mainColor.red - otherColor.red),
std::abs(mainColor.green - otherColor.green),
std::abs(mainColor.blue - otherColor.blue)}),
mainWeight + otherWeight - 1.0);

return color;
}

}
9 changes: 9 additions & 0 deletions src/chart/rendering/drawinterlacing.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ class DrawInterlacing
const Gfx::Color &tickColor,
Gen::AxisId axisIndex,
const Geom::Point &tickPos) const;

[[nodiscard]] std::map<double, double> getInterlacingWeights(
Gen::AxisId axisIndex) const;

[[nodiscard]] static Gfx::Color getCrossingInterlacingColor(
const Gfx::Color &mainColor,
double mainWeight,
const Gfx::Color &otherColor,
double otherWeight);
};

}
Expand Down
2 changes: 1 addition & 1 deletion src/dataframe/impl/dataframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void dataframe::add_series_by_other(std::string_view,
const std::function<cell_value(record_type, cell_reference)> &,
std::span<const std::pair<const char *, const char *>>) &
{
if (as_if()) error(error_type::unimplemented, "by oth");
if (as_if()) error(error_type::unimplemented, "by other");
}

void dataframe::remove_series(
Expand Down
8 changes: 4 additions & 4 deletions src/dataframe/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ struct custom_aggregator
id_type (*create)();
double (*add)(id_type &, cell_reference const &);

auto operator<=>(const custom_aggregator &oth) const
auto operator<=>(const custom_aggregator &other) const
{
return name <=> oth.name;
return name <=> other.name;
}

auto operator==(const custom_aggregator &oth) const
auto operator==(const custom_aggregator &other) const
{
return name == oth.name;
return name == other.name;
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/dataframe/old/datatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ void DataTable::pushRow(const std::span<const char *const> &cells)

std::string DataTable::getInfos() const { return df.as_string(); }

bool DataCube::iterator_t::operator!=(const iterator_t &oth) const
bool DataCube::iterator_t::operator!=(const iterator_t &other) const
{
return parent != oth.parent;
return parent != other.parent;
}

void DataCube::iterator_t::operator++() { parent->incr(*this); }
Expand Down
2 changes: 1 addition & 1 deletion src/dataframe/old/datatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DataCube
const DataCube *parent{};
MultiIndex index;

[[nodiscard]] bool operator!=(const iterator_t &oth) const;
[[nodiscard]] bool operator!=(const iterator_t &other) const;

void operator++();

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/style_tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"refs": ["5a62ac8"]
},
"plot/interlacing": {
"refs": ["82e891d"]
"refs": ["f14b366"]
},
"plot/paddingBottom/animated_150-350": {
"refs": ["e618e56"]
Expand Down

0 comments on commit 0b09de3

Please sign in to comment.