Skip to content

Commit

Permalink
Merge branch 'axis_refactor_v12' into axis_refactor_v12b
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed Nov 27, 2024
2 parents ed974b8 + d3ce44d commit 0263d8b
Show file tree
Hide file tree
Showing 25 changed files with 148 additions and 121 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

### Added

- Add split property for plot axis style structure. Only supported the percentage value.
- Add spacing property for plot axis style structure.

### Changed

Expand Down
5 changes: 3 additions & 2 deletions src/apps/weblib/typeschema-api/styles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,9 @@ definitions:
interlacing:
$ref: Interlacing
nullable: true
split:
$ref: Length
spacing:
type: string
mask: /:number:%/
nullable: true

Plot:
Expand Down
1 change: 1 addition & 0 deletions src/base/refl/auto_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ template <class E> consteval auto enum_values()
constexpr auto n = std::size(enum_names<E>);
std::array<E, n> res{};
for (std::size_t i = 0; i < n; ++i)
// NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange)
res[i] = static_cast<E>(i + first);
return res;
}
Expand Down
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
1 change: 0 additions & 1 deletion src/chart/generator/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <iterator>
#include <limits>
#include <optional>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
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
7 changes: 4 additions & 3 deletions src/chart/generator/marker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "marker.h"

#include <cmath>
#include <cstdint>
#include <optional>
#include <utility>
Expand Down Expand Up @@ -225,14 +226,14 @@ void Marker::fromRectangle(const Geom::Rect &rect)

Math::Range<> Marker::getSizeBy(AxisId axisId) const
{
return isHorizontal(++axisId) ? toRectangle().hSize()
: toRectangle().vSize();
return isHorizontal(orientation(axisId)) ? toRectangle().hSize()
: toRectangle().vSize();
}

void Marker::setSizeBy(AxisId axisId, const Math::Range<> range)
{
auto rect = toRectangle();
if (isHorizontal(++axisId))
if (isHorizontal(orientation(axisId)))
rect.setHSize(range);
else
rect.setVSize(range);
Expand Down
8 changes: 5 additions & 3 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "base/anim/interpolated.h"
#include "base/math/floating.h"
#include "base/math/range.h"
#include "base/refl/auto_enum.h"
#include "chart/main/style.h"
#include "chart/options/align.h"
#include "chart/options/channel.h"
Expand Down Expand Up @@ -233,7 +234,7 @@ bool PlotBuilder::linkMarkers(const Buckets &buckets,
auto &marker = **it.base().base().base();
if (!marker.enabled) continue;
o = std::max(o,
marker.size.getCoord(++axisIndex),
marker.size.getCoord(orientation(axisIndex)),
Math::Floating::less);
}
if (o == std::numeric_limits<double>::lowest()) o = 0.0;
Expand Down Expand Up @@ -279,7 +280,8 @@ bool PlotBuilder::linkMarkers(const Buckets &buckets,
: *it.base().base().base();

if (act)
prevPos = act->position.getCoord(++axisIndex) +=
prevPos =
act->position.getCoord(orientation(axisIndex)) +=
isAggregatable ? dimOffset[i] : prevPos;

hasConnection |=
Expand Down Expand Up @@ -542,7 +544,7 @@ void PlotBuilder::addSeparation(const Buckets &subBuckets,
auto splitSpace =
plot->getStyle()
.plot.getAxis(plot->getOptions()->subAxisType())
.split->get(max.getMax(),
.spacing->get(max.getMax(),
plot->getStyle().calculatedSize());

for (auto i = 1U; i < ranges.size(); ++i)
Expand Down
4 changes: 2 additions & 2 deletions src/chart/main/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ Chart Chart::def()
.interlacing = {
.color = Gfx::Color::Gray(0.97)
},
.split = Gfx::Length::Relative(1 / 15.)
.spacing = Gfx::Length::Relative(1 / 15.)
},
.yAxis = {
.color = Gfx::Color::Gray(0.8),
Expand Down Expand Up @@ -372,7 +372,7 @@ Chart Chart::def()
.interlacing = {
.color = Gfx::Color::Gray(0.97)
},
.split = Gfx::Length::Relative(1 / 15.)
.spacing = Gfx::Length::Relative(1 / 15.)
},
.areaColor = Gfx::Color::Transparent(),
.overflow = ::Anim::Interpolated<Overflow>(Overflow::hidden)
Expand Down
2 changes: 1 addition & 1 deletion src/chart/main/style.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ struct Axis
Tick ticks;
Guide guides;
Interlacing interlacing;
Param<Gfx::Length> split;
Param<Gfx::Length> spacing;
};

struct MarkerLabelParams
Expand Down
3 changes: 0 additions & 3 deletions src/chart/options/channel.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "channel.h"

#include <cmath>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <optional>
#include <stdexcept>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/chart/options/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static_assert(std::ranges::all_of(Refl::enum_names<LegendId>,
Refl::get_enum<ChannelId>(name));
}));

[[nodiscard]] constexpr Geom::Orientation operator++(
[[nodiscard]] constexpr Geom::Orientation orientation(
const AxisId &axis)
{
return axis == AxisId::x ? Geom::Orientation::horizontal
Expand Down
5 changes: 0 additions & 5 deletions src/chart/options/channelrange.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#include "channelrange.h"

#include <string>

#include "base/conv/parse.h"
#include "base/conv/tostring.h"
#include "base/math/range.h"
#include "base/text/valueunit.h"

namespace Vizzu::Gen
{
Expand Down
17 changes: 12 additions & 5 deletions src/chart/rendering/drawaxes.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "drawaxes.h"

#include <algorithm>
#include <cmath>
#include <numbers>
#include <ranges>
#include <string>
#include <utility>

Expand All @@ -12,8 +15,12 @@
#include "base/geom/transformedrect.h"
#include "base/gfx/colortransform.h"
#include "base/gfx/font.h"
#include "base/math/floating.h"
#include "base/math/fuzzybool.h"
#include "base/math/interpolation.h"
#include "base/math/range.h"
#include "base/math/renard.h"
#include "base/refl/auto_enum.h"
#include "base/type/booliter.h"
#include "chart/generator/plot.h" // NOLINT(misc-include-cleaner)
#include "chart/main/events.h"
Expand Down Expand Up @@ -145,7 +152,7 @@ void DrawAxes::generateMeasure(Gen::AxisId axisIndex,
double stepSize,
double weight)
{
auto orientation = !++axisIndex;
auto orientation = !Gen::orientation(axisIndex);
const auto &meas = getAxis(axisIndex).measure;
auto rangeSize = meas.range.size();
auto singleLabelRange = Math::Floating::is_zero(rangeSize);
Expand Down Expand Up @@ -213,9 +220,9 @@ void DrawAxes::generateMeasure(Gen::AxisId axisIndex,

Geom::Line DrawAxes::getAxisLine(Gen::AxisId axisIndex) const
{
auto offset = this->origo().getCoord(!++axisIndex);
auto offset = this->origo().getCoord(!orientation(axisIndex));

auto direction = Geom::Point::Ident(++axisIndex);
auto direction = Geom::Point::Ident(orientation(axisIndex));

auto p0 = direction.flip() * offset;
auto p1 = p0 + direction;
Expand Down Expand Up @@ -267,7 +274,7 @@ Geom::Point DrawAxes::getTitleBasePos(Gen::AxisId axisIndex,
case Pos::min_edge: break;
case Pos::max_edge: orthogonal = 1.0; break;
case Pos::axis:
orthogonal = origo().getCoord(!++axisIndex);
orthogonal = origo().getCoord(!orientation(axisIndex));
break;
}

Expand Down Expand Up @@ -442,7 +449,7 @@ void DrawAxes::drawDimensionLabel(Gen::AxisId axisIndex,
double weight) const
{
if (weight == 0) return;
auto orientation = ++axisIndex;
auto orientation = Gen::orientation(axisIndex);

const auto &labelStyle = rootStyle.plot.getAxis(axisIndex).label;

Expand Down
5 changes: 2 additions & 3 deletions src/chart/rendering/drawguides.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "drawguides.h"

#include <iterator>
#include <utility>

#include "base/geom/line.h"
Expand Down Expand Up @@ -42,8 +41,8 @@ void DrawGuides::drawGuide(Gen::AxisId axisId,
{
auto eventTarget = Events::Targets::axisGuide(axisId);

auto ident = Geom::Point::Ident(++axisId);
auto normal = Geom::Point::Ident(!++axisId);
auto ident = Geom::Point::Ident(orientation(axisId));
auto normal = Geom::Point::Ident(!orientation(axisId));
auto relMax = ident * val;

parent.canvas.setLineColor(color);
Expand Down
Loading

0 comments on commit 0263d8b

Please sign in to comment.