Skip to content

Commit

Permalink
Merge pull request #588 from vizzuhq/remove_anyaxisset_from_plot
Browse files Browse the repository at this point in the history
Remove anyAxisSet from plot
  • Loading branch information
schaumb authored Oct 17, 2024
2 parents 747b769 + e3a89a0 commit 156a8e0
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Removed 'min' align property from the API which equivalent with the 'none'.
- Markers are the same even if new record added.
- Axis line hide/show at same time with axis labels/ticks/title.
- Do not draw invisible axis line.


### Changed

Expand Down
3 changes: 0 additions & 3 deletions src/chart/animator/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ void Horizontal::transform(const Gen::Plot &source,
target.keepAspectRatio,
factor);

actual.anyAxisSet =
interpolate(source.anyAxisSet, target.anyAxisSet, factor);

actual.guides.x =
interpolate(source.guides.x, target.guides.x, factor);
}
Expand Down
2 changes: 0 additions & 2 deletions src/chart/animator/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ bool Planner::needVertical() const
|| source->axises.at(Gen::ChannelId::size).dimension
!= target->axises.at(Gen::ChannelId::size)
.dimension))
|| source->anyAxisSet != target->anyAxisSet
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
&& (source->markerConnectionOrientation.value_or(
Expand Down Expand Up @@ -474,7 +473,6 @@ bool Planner::needHorizontal() const
!= target->axises.at(Gen::ChannelId::x).dimension
|| source->guides.at(Gen::AxisId::x)
!= target->guides.at(Gen::AxisId::x)
|| source->anyAxisSet != target->anyAxisSet
|| source->keepAspectRatio != target->keepAspectRatio
|| (source->markerConnectionOrientation
!= target->markerConnectionOrientation
Expand Down
6 changes: 4 additions & 2 deletions src/chart/generator/guides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ bool GuidesByAxis::operator==(const GuidesByAxis &other) const

Guides::Guides(const Options &options)
{
auto isCircle = options.geometry.get() == ShapeType::circle;
auto isHorizontal = options.isHorizontal();
const auto &channelX = options.getChannels().at(ChannelId::x);
const auto &channelY = options.getChannels().at(ChannelId::y);
if (channelX.isEmpty() && channelY.isEmpty()) return;

auto xIsMeasure = channelX.isMeasure();
auto yIsMeasure = channelY.isMeasure();
auto isPolar = options.coordSystem.get() == CoordSystem::polar;
auto isCircle = options.geometry.get() == ShapeType::circle;
auto isHorizontal = options.isHorizontal();

const auto &xOpt = options.getChannels().at(ChannelId::x);
const auto &yOpt = options.getChannels().at(ChannelId::y);
Expand Down
1 change: 0 additions & 1 deletion src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ bool Plot::MarkerInfoContent::operator==(
}

Plot::Plot(PlotOptionsPtr opts, Styles::Chart style) :
anyAxisSet(opts->getChannels().anyAxisSet()),
guides(*opts),
options(std::move(opts)),
style(std::move(style))
Expand Down
1 change: 0 additions & 1 deletion src/chart/generator/plot.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class Plot
using MarkerInfo = ::Anim::Interpolated<MarkerInfoContent>;
using MarkersInfo = std::map<MarkerInfoId, MarkerInfo>;

Math::FuzzyBool anyAxisSet;
Axises axises;
Guides guides;
Math::FuzzyBool keepAspectRatio;
Expand Down
30 changes: 14 additions & 16 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ PlotBuilder::PlotBuilder(const Data::DataTable &dataTable,
if (!plot->options->getChannels().anyAxisSet()) {
addSpecLayout(subBuckets);
calcDimensionAxises();
calcMeasureAxises(dataTable);
normalizeColors();
if (plot->options->geometry != ShapeType::circle)
normalizeSizes();
calcMeasureAxises(dataTable);
}
else {
addSeparation(subBuckets, mainBucketSize);
normalizeXY();
calcDimensionAxises();
calcMeasureAxises(dataTable);
normalizeSizes();
normalizeColors();
calcMeasureAxises(dataTable);
addAlignment(subBuckets);
}

Expand Down Expand Up @@ -93,14 +93,12 @@ Buckets PlotBuilder::generateMarkers(std::size_t &mainBucketSize)
{
const auto &mainIds(plot->getOptions()->mainAxis().dimensions());
auto subIds(plot->getOptions()->subAxis().dimensions());

auto all_marker = dataCube.df->get_record_count();
if (!dataCube.empty()) {
if (plot->getOptions()->geometry == ShapeType::area)
subIds.split_by(mainIds);

mainBucketSize = dataCube.combinedSizeOf(mainIds).first;
plot->markers.reserve(all_marker);
plot->markers.reserve(dataCube.df->get_record_count());
}

std::multimap<Marker::MarkerIndex, Options::MarkerInfoId> map;
Expand Down Expand Up @@ -186,18 +184,16 @@ PlotBuilder::sortedBuckets(const Buckets &buckets, bool main) const
void PlotBuilder::addSpecLayout(Buckets &buckets)
{
auto geometry = plot->getOptions()->geometry.values[0].value;
if (auto &markers = plot->markers; isConnecting(geometry)) {
if (auto &markers = plot->markers; isConnecting(geometry))
Charts::TableChart::setupVector(markers, true);
}
else if (auto &&size = plot->getOptions()->getChannels().at(
ChannelId::size);
size.isDimension()) {
else if (plot->getOptions()
->getChannels()
.at(ChannelId::size)
.isDimension())
Charts::TableChart::setupVector(markers);
}
else if (!dataCube.empty()) {
buckets.sort(&Marker::sizeId);

if (geometry == ShapeType::circle) {
if (buckets.sort(&Marker::sizeId);
geometry == ShapeType::circle) {
Charts::BubbleChartBuilder::setupVector(
*plot->getStyle().plot.marker.circleMaxRadius,
buckets);
Expand Down Expand Up @@ -616,8 +612,10 @@ void PlotBuilder::normalizeColors()
cbase.setPos(color.rescale(cbase.getPos()));
}

getMeasTrackRange(ChannelId::color) = color;
getMeasTrackRange(ChannelId::lightness) = lightness;
plot->axises.at(ChannelId::color).measure.range =
getMeasTrackRange(ChannelId::color) = color;
plot->axises.at(ChannelId::lightness).measure.range =
getMeasTrackRange(ChannelId::lightness) = lightness;

for (auto &value : plot->axises.at(ChannelId::color).dimension)
value.second.colorBase =
Expand Down
23 changes: 9 additions & 14 deletions src/chart/rendering/drawaxes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,22 @@ Geom::Line DrawAxes::getAxis(Gen::AxisId axisIndex) const

void DrawAxes::drawAxis(Gen::AxisId axisIndex) const
{
auto eventTarget =
Events::Targets::axis(axisIndex == Gen::AxisId::x);

auto lineBaseColor = *rootStyle.plot.getAxis(axisIndex).color;

if (lineBaseColor.alpha <= 0 || plot->anyAxisSet == false) return;

auto line = getAxis(axisIndex);

if (!line.isPoint()) {
if (auto line = getAxis(axisIndex); !line.isPoint()) {
auto lineColor =
lineBaseColor
* Math::FuzzyBool::And<double>(plot->anyAxisSet,
plot->guides.at(axisIndex).axis);
*rootStyle.plot.getAxis(axisIndex).color
* static_cast<double>(plot->guides.at(axisIndex).axis);

if (lineColor.isTransparent()) return;

canvas.save();

canvas.setLineColor(lineColor);
canvas.setLineWidth(1.0);

if (rootEvents.draw.plot.axis.base->invoke(
if (auto &&eventTarget =
Events::Targets::axis(axisIndex == Gen::AxisId::x);

rootEvents.draw.plot.axis.base->invoke(
Events::OnLineDrawEvent(*eventTarget,
{line, true}))) {
painter.drawLine(line);
Expand Down
26 changes: 16 additions & 10 deletions src/chart/rendering/markerrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,32 @@ void MarkerRenderer::drawLines(Gfx::ICanvas &canvas,
const auto &style = rootStyle.plot.marker.guides;

if (style.color->isTransparent() || *style.lineWidth <= 0
|| plot->anyAxisSet == false || !plot->guides.hasAnyGuides())
|| !plot->guides.hasAnyGuides())
return;

auto xLineColor =
*style.color
* static_cast<double>(plot->guides.x.markerGuides);

auto yLineColor =
*style.color
* static_cast<double>(plot->guides.y.markerGuides);

auto xLineInvisible = xLineColor.isTransparent();
auto yLineInvisible = yLineColor.isTransparent();

if (xLineInvisible && yLineInvisible) return;

canvas.setLineWidth(*style.lineWidth);

auto origo = plot->axises.origo();

auto xLineColor = *style.color
* Math::FuzzyBool::And<double>(plot->anyAxisSet,
plot->guides.x.markerGuides);
auto yLineColor = *style.color
* Math::FuzzyBool::And<double>(plot->anyAxisSet,
plot->guides.y.markerGuides);

for (const auto &blended : markers) {
if (blended.marker.enabled == false
|| blended.enabled == false)
continue;

if (plot->guides.x.markerGuides != false) {
if (!xLineInvisible) {
canvas.setLineColor(xLineColor);
auto axisPoint = blended.center.xComp() + origo.yComp();
const Geom::Line line(axisPoint, blended.center);
Expand All @@ -71,7 +77,7 @@ void MarkerRenderer::drawLines(Gfx::ICanvas &canvas,
std::move(guideElement));
}
}
if (plot->guides.y.markerGuides != false) {
if (!yLineInvisible) {
auto center = Geom::Point{blended.center};
center.x = Math::interpolate(center.x,
1.0,
Expand Down
30 changes: 15 additions & 15 deletions test/e2e/test_cases/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"refs": ["c5c0df5"]
},
"basic_animations/anim_order/rectangle_without_2_carte_bar": {
"refs": ["929dbd0"]
"refs": ["2a487b0"]
},
"basic_animations/anim_order/rectangle_without_2_carte_column": {
"refs": ["e88e517"]
Expand Down Expand Up @@ -1340,28 +1340,28 @@
"refs": ["4d42242"]
},
"ww_animTiming/without-descartes_orientation/01_w-d_o_r-r-r": {
"refs": ["dd2956b"]
"refs": ["5b50b91"]
},
"ww_animTiming/without-descartes_orientation/02_w-d_o_c-r-c": {
"refs": ["d1f7bc4"]
"refs": ["be7a91f"]
},
"ww_animTiming/without-descartes_orientation/05_w-d_o_r-c-r": {
"refs": ["c1148ec"]
"refs": ["88424cf"]
},
"ww_animTiming/without-descartes_orientation/06_w-d_o_c-c-c": {
"refs": ["2068c64"]
"refs": ["2e3894f"]
},
"ww_animTiming/without-descartes_orientation/09_w-d_o_r-a-r": {
"refs": ["1764f6a"]
"refs": ["cd724c7"]
},
"ww_animTiming/without-descartes_orientation/10_w-d_o_c-a-c": {
"refs": ["a5256c7"]
"refs": ["7165dfa"]
},
"ww_animTiming/without-descartes_orientation/13_w-d_o_r-l-r": {
"refs": ["12843e9"]
"refs": ["750bd0f"]
},
"ww_animTiming/without-descartes_orientation/14_w-d_o_c-l-c": {
"refs": ["37b2c36"]
"refs": ["b86538c"]
},
"ww_animTiming/without-polar/01_w-p_r-r-r": {
"refs": ["0093ba5"]
Expand Down Expand Up @@ -1673,7 +1673,7 @@
"refs": ["e955812"]
},
"ww_animTiming_TESTS/without-descartes_orientation/01_w-d_o_r-r-r": {
"refs": ["cdf5fa6"]
"refs": ["037dda9"]
},
"ww_animTiming_TESTS/without-descartes_orientation/02_w-d_o_c-r-c": {
"refs": ["4568887"]
Expand All @@ -1685,13 +1685,13 @@
"refs": ["4210956"]
},
"ww_animTiming_TESTS/without-descartes_orientation/09_w-d_o_r-a-r": {
"refs": ["f45ac5b"]
"refs": ["5867a1b"]
},
"ww_animTiming_TESTS/without-descartes_orientation/10_w-d_o_c-a-c": {
"refs": ["aa0fb41"]
},
"ww_animTiming_TESTS/without-descartes_orientation/13_w-d_o_r-l-r": {
"refs": ["42f1324"]
"refs": ["17c98c5"]
},
"ww_animTiming_TESTS/without-descartes_orientation/14_w-d_o_c-l-c": {
"refs": ["fa9e4f7"]
Expand Down Expand Up @@ -2891,7 +2891,7 @@
"refs": ["d05bc27"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_V1/04a_d-w_rec_Ve1_2c_V1": {
"refs": ["4597f5f"]
"refs": ["b8b060e"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_V1/04b_d-w_rec_1c_V1": {
"refs": ["3711f84"]
Expand All @@ -2903,10 +2903,10 @@
"refs": ["6aa98f4"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_V1/07a_d-w_rec_Ve1_2c_V1": {
"refs": ["7d74510"]
"refs": ["8d00b71"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_V1/08a_d-w_rec_Ve1_2c_V1": {
"refs": ["715db19"]
"refs": ["44c0c9e"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_Ve1/04a_d-w_rec_Ve1_1c": {
"refs": ["e8b9827"]
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"refs": ["ba17dad"]
},
"events/drawing_events": {
"refs": ["6496e1d"]
"refs": ["33e0e4d"]
},
"subtitle_caption": {
"refs": ["f6dabf0"]
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/tests/features/events/drawing_events.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function setupEvents(chart) {
})
})
chart.on('draw-complete', (e) => {
const reference = 764260241
const reference = -476544255
receivedEvents.push(e)
const result = JSON.stringify(receivedEvents, null, 2)
const hash = (str) =>
Expand Down Expand Up @@ -144,8 +144,8 @@ const testSteps = [
data,
config: {
color: 'Foo',
x: { set: 'Foo', guides: true, ticks: true },
y: { set: 'Bar', guides: true, ticks: true },
x: { set: 'Foo', guides: true, ticks: true, axis: true },
y: { set: 'Bar', guides: true, ticks: true, axis: true },
size: 'Baz',
label: 'Baz',
title: 'My Chart',
Expand Down
Loading

0 comments on commit 156a8e0

Please sign in to comment.