Skip to content

Axis refactor v12 13 review changes #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/docker-vizzu-dev-desktop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Docker publish vizzu-dev-desktop

on:
push:
pull_request:
branches-ignore:
- main
paths:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-vizzu-dev-wasm.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Docker publish vizzu-dev-wasm

on:
push:
pull_request:
branches-ignore:
- main
paths:
Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- Waterfall chart preset not aligned.
- Split chart count negative values too.
- Split chart handled when same dimension on main and sub axis.
- Add record didn't handle when a measure got an empty string.
- Fix no fontparent set bug.

### Changed

Expand All @@ -20,8 +22,8 @@

### Added

- Separate Channel properties to AxisChannel properties at config.
- Move split align sort and reverse to AxisChannel
- Separate AxisChannel properties from Channel properties at config.
- Move split align sort and reverse from config to AxisChannel config.
- Add new sorting strategy: 'byLabel'.
- Enable split and align on mainAxis.

Expand Down
9 changes: 3 additions & 6 deletions src/apps/weblib/typeschema-api/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ definitions:
- { type: string, enum: [auto] }

AxisChannel:
$extends: Channel
description: |
AxisChannels are special channel settings for the positional channels.
type: object
Expand Down Expand Up @@ -138,18 +139,14 @@ definitions:
type: object
properties:
x:
allOf:
- $ref: Channel
- $ref: AxisChannel
$ref: AxisChannel
description: |
Parameters for the X-axis, determining the position of the markers on the
x-axis - or their angle when using polar coordinates.
Note: leaving x and y channels empty will result in a
chart "without coordinates" like a Treemap or a Bubble Chart.
y:
allOf:
- $ref: Channel
- $ref: AxisChannel
$ref: AxisChannel
description: |
Parameters for the Y-axis, determining the position of the markers on the
y-axis - or their radius when using polar coordinates) .
Expand Down
2 changes: 2 additions & 0 deletions src/chart/animator/keyframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void Keyframe::prepareActual()
prepareActualMarkersInfo();

actual = std::make_shared<Gen::Plot>(*source);
actual->getStyle().setup();
actual->detachOptions();
}

Expand All @@ -92,6 +93,7 @@ void Keyframe::copyTarget()
if (!targetCopy) {
targetCopy = target;
target = std::make_shared<Gen::Plot>(*targetCopy);
target->getStyle().setup();
target->detachOptions();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ Plot::Plot(PlotOptionsPtr opts, Styles::Chart style) :
guides(*opts),
options(std::move(opts)),
style(std::move(style))
{}
{
this->style.setup();
}

void Plot::detachOptions()
{
Expand Down
2 changes: 1 addition & 1 deletion src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ std::vector<PlotBuilder::BucketSortInfo> PlotBuilder::sortedBuckets(
break;
case Sort::byLabel:
std::ranges::stable_sort(sorted,
[](const BucketInfo &lhs, const BucketInfo &rhs)
[](const BucketSortInfo &lhs, const BucketSortInfo &rhs)
{
if (rhs.label == nullptr || lhs.label == nullptr)
return lhs.label != nullptr;
Expand Down
5 changes: 4 additions & 1 deletion src/chart/main/chart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Chart::Chart() :
*events.animation.begin,
*events.animation.complete)
{
computedStyles.setup();
animator.onDraw.attach(
[this](const Gen::PlotPtr &actPlot)
{
Expand Down Expand Up @@ -72,8 +73,9 @@ void Chart::animate(Anim::Animation::OnComplete &&onComplete)
}
else {
*nextOptions = prevOptions;
actStyles = prevStyles;
setStyles(prevStyles);
computedStyles = plot->getStyle();
computedStyles.setup();
}
});

Expand Down Expand Up @@ -132,6 +134,7 @@ Gen::PlotPtr Chart::plot(const Gen::PlotOptionsPtr &options)
Styles::Sheet::setAfterStyles(*res, layout.boundary.size);

computedStyles = res->getStyle();
computedStyles.setup();

return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/chart/main/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ struct FontParentSetter
{}
};

void Chart::setup()
void Chart::setup() &
{
Refl::visit(FontParentSetter{this}, *this);
fontParent = &getDefaultFont();
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 @@ -401,7 +401,7 @@ struct Chart : Padding, Box, Font, ChartParams
static const Gfx::ColorPalette &getDefaultColorPalette();
static Chart def();

void setup();
void setup() &;
};

}
Expand Down
2 changes: 1 addition & 1 deletion src/chart/main/stylesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Chart Sheet::getFullParams(const Gen::PlotOptionsPtr &options,
void Sheet::calcDefaults(const Geom::Size &size)
{
defaultParams = Chart::def();
defaultParams.setup();

defaultParams.fontSize = Gfx::Length{baseFontSize(size, true)};

Expand Down Expand Up @@ -219,7 +220,6 @@ void Sheet::setData()
void Sheet::setAfterStyles(Gen::Plot &plot, const Geom::Size &size)
{
auto &style = plot.getStyle();
style.setup();

if (auto &xLabel =
style.plot
Expand Down
7 changes: 6 additions & 1 deletion src/chart/main/stylesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class Sheet : public Style::Sheet<Chart>
{
public:
using Base = Style::Sheet<Chart>;
using Base::Sheet;

Sheet(Chart &&defaultParams, Chart &activeParams) :
Base(std::move(defaultParams), activeParams)
{
this->defaultParams.setup();
}

Chart getFullParams(const Gen::PlotOptionsPtr &options,
const Geom::Size &size);
Expand Down
24 changes: 12 additions & 12 deletions src/chart/options/channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool Channels::anyAxisSet() const

bool Channels::isEmpty() const
{
return std::ranges::all_of(*this,
return std::ranges::all_of(genProps,
[](const auto &channel)
{
return channel.isEmpty();
Expand All @@ -28,7 +28,7 @@ Channels::IndexSet Channels::getDimensions() const
{
IndexSet dimensions;

for (const auto &channel : *this)
for (const auto &channel : genProps)
channel.collectDimensions(dimensions);

return dimensions;
Expand All @@ -38,7 +38,7 @@ Channels::IndexSet Channels::getMeasures() const
{
IndexSet series;

for (const auto &channel : *this)
for (const auto &channel : genProps)
if (auto &&mid = channel.measure()) series.insert(*mid);

return series;
Expand All @@ -57,12 +57,12 @@ Channels::IndexSet Channels::getDimensions(

void Channels::removeSeries(const Data::SeriesIndex &index)
{
for (auto &channel : *this) channel.removeSeries(index);
for (auto &channel : genProps) channel.removeSeries(index);
}

bool Channels::isSeriesUsed(const Data::SeriesIndex &index) const
{
return std::ranges::any_of(*this,
return std::ranges::any_of(genProps,
[&](const auto &channel)
{
return channel.isSeriesUsed(index);
Expand All @@ -71,23 +71,23 @@ bool Channels::isSeriesUsed(const Data::SeriesIndex &index) const

void Channels::reset()
{
for (auto &channel : *this) channel.reset();
for (auto &channel : genProps) channel.reset();
}

Channels Channels::shadow() const
{
Channels shadow = *this;
Channels shadow{*this};

shadow[ChannelId::color].reset();
shadow[ChannelId::lightness].reset();
shadow[ChannelId::label].reset();
shadow[ChannelId::noop].reset();
shadow.genProps[ChannelId::color].reset();
shadow.genProps[ChannelId::lightness].reset();
shadow.genProps[ChannelId::label].reset();
shadow.genProps[ChannelId::noop].reset();

for (auto &&attr : getDimensions({{ChannelId::color,
ChannelId::lightness,
ChannelId::label,
ChannelId::noop}}))
shadow[ChannelId::noop].addSeries(attr);
shadow.genProps[ChannelId::noop].addSeries(attr);

return shadow;
}
Expand Down
15 changes: 12 additions & 3 deletions src/chart/options/channels.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
namespace Vizzu::Gen
{

struct Channels : Refl::EnumArray<ChannelId, Channel>
struct Channels
{
using IndexSet = std::set<Data::SeriesIndex>;
EnumArray<AxisId, AxisChannelProperties> axisProps;
Refl::EnumArray<ChannelId, Channel> genProps;
Refl::EnumArray<AxisId, AxisChannelProperties> axisProps;

[[nodiscard]] bool anyAxisSet() const;
[[nodiscard]] bool isEmpty() const;
Expand All @@ -25,7 +26,15 @@ struct Channels : Refl::EnumArray<ChannelId, Channel>
[[nodiscard]] IndexSet getDimensions(
const std::span<const ChannelId> &channelTypes) const;

using EnumArray::at;
[[nodiscard]] constexpr Channel &at(ChannelId value)
{
return genProps.at(value);
}

[[nodiscard]] constexpr const Channel &at(ChannelId value) const
{
return genProps.at(value);
}

template <ChannelIdLike T>
[[nodiscard]] const Channel &at(const T &id) const
Expand Down
4 changes: 2 additions & 2 deletions src/chart/options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ class Options : public OptionProperties
{{Channel::makeChannel(
static_cast<ChannelId>(Ix))...}},
{}};
}(std::make_index_sequence<
std::tuple_size_v<decltype(channels)::base_array>>{})};
}(std::make_index_sequence<std::size(
Refl::enum_values<ChannelId>())>())};

[[nodiscard]] Geom::Orientation getAutoOrientation() const;
[[nodiscard]] std::optional<LegendId> getAutoLegend() const;
Expand Down
9 changes: 6 additions & 3 deletions src/dataframe/impl/dataframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,8 @@ void dataframe::add_record(std::span<const char *const> values) &
auto &s = *unsafe_get<source_type::owning>(source);
s.normalize_sizes();

std::vector<double> measures(s.measure_names.size());
std::vector measures(s.measure_names.size(),
std::numeric_limits<double>::quiet_NaN());
std::vector<std::string_view> dimensions(
s.dimension_names.size());
for (const auto *it = values.data(); const auto &col : *vec) {
Expand All @@ -407,8 +408,10 @@ void dataframe::add_record(std::span<const char *const> values) &
break;
case measure:
char *eof{};
measures[&unsafe_get<measure>(ser).second
- s.measures.data()] = std::strtod(*it, &eof);
if (**it != '\0')
measures[&unsafe_get<measure>(ser).second
- s.measures.data()] =
std::strtod(*it, &eof);
if (eof == *it) error(error_type::nan, *it);
break;
}
Expand Down