Skip to content
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

On split charts the first range was not part of the separation calculation. #532

Merged
merged 4 commits into from
May 30, 2024
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- Do not calculate disabled markers to the color normalization.
- More precise TS type for transform matrix in event handlers.
- On split charts the first range was not part of the separation calculation.
- When the first marker was disabled it was calculated as an enabled marker on the XY normalization.

## [0.11.0] - 2024-05-23

Expand Down
4 changes: 0 additions & 4 deletions src/chart/generator/axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,13 @@ MeasureAxis interpolate(const MeasureAxis &op0,
bool DimensionAxis::add(const Data::SliceIndex &index,
double value,
const Math::Range<double> &range,
double enabled,
bool merge)
{
if (enabled <= 0) return false;

this->enabled = true;

if (merge) {
if (auto it = values.find(index); it != values.end()) {
it->second.range.include(range);
it->second.weight = std::max(it->second.weight, enabled);
return false;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/chart/generator/axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ struct DimensionAxis
bool add(const Data::SliceIndex &index,
double value,
const Math::Range<double> &range,
double enabled,
bool merge);
bool operator==(const DimensionAxis &other) const;

Expand Down
34 changes: 19 additions & 15 deletions src/chart/generator/plotbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,22 @@ void PlotBuilder::normalizeXY()
plot->getOptions()->getHorizontalAxis().range;
const auto &yrange = plot->getOptions()->getVeritalAxis().range;

if (plot->markers.empty()) {
auto markerIt = plot->markers.begin();
while (markerIt != plot->markers.end()
&& !static_cast<bool>(markerIt->enabled))
++markerIt;

if (markerIt == plot->markers.end()) {
getMeasTrackRange(ChannelId::x) = xrange.getRange({0.0, 0.0});
getMeasTrackRange(ChannelId::y) = yrange.getRange({0.0, 0.0});
return;
}

auto boundRect = plot->markers.front().toRectangle();
auto boundRect = markerIt->toRectangle();

for (auto &marker : plot->markers) {
if (!marker.enabled) continue;
boundRect = boundRect.boundary(marker.toRectangle());
while (++markerIt != plot->markers.end()) {
if (!markerIt->enabled) continue;
boundRect = boundRect.boundary(markerIt->toRectangle());
}

plot->getOptions()->setAutoRange(
Expand Down Expand Up @@ -329,6 +334,8 @@ void PlotBuilder::calcDimensionAxis(ChannelId type)
auto &&isTypeAxis = isAxis(type);
if (auto merge = scale.labelLevel == 0; isTypeAxis) {
for (const auto &marker : plot->markers) {
if (!marker.enabled) continue;

const auto &id =
(type == ChannelId::x)
== plot->getOptions()->isHorizontal()
Expand All @@ -339,7 +346,6 @@ void PlotBuilder::calcDimensionAxis(ChannelId type)
axis.add(*slice,
static_cast<double>(id.itemId),
marker.getSizeBy(type == ChannelId::x),
static_cast<double>(marker.enabled),
merge);
}
}
Expand All @@ -351,11 +357,7 @@ void PlotBuilder::calcDimensionAxis(ChannelId type)
for (auto i = 0U; i < indices.size(); ++i)
if (const auto &sliceIndex = indices[i];
sliceIndex
&& axis.add(*sliceIndex,
i,
{count, count},
true,
merge))
&& axis.add(*sliceIndex, i, {count, count}, merge))
count += 1;
}
auto hasLabel =
Expand Down Expand Up @@ -401,7 +403,7 @@ void PlotBuilder::addAlignment(const Buckets &subBuckets) const
void PlotBuilder::addSeparation(const Buckets &subBuckets,
const std::size_t &mainBucketSize) const
{
if (static_cast<bool>(plot->getOptions()->split)) {
if (plot->getOptions()->split) {
auto align =
plot->getOptions()->align == Base::Align::Type::none
? Base::Align::Type::min
Expand All @@ -414,14 +416,16 @@ void PlotBuilder::addSeparation(const Buckets &subBuckets,
auto &&vertical = !plot->getOptions()->isHorizontal();
for (auto &&bucket : subBuckets)
for (auto i = 0U; auto &&marker : bucket) {
ranges[i].include(marker->getSizeBy(vertical).size());
if (static_cast<double>(marker->enabled) > 0)
if (marker->enabled) {
ranges[i].include(
marker->getSizeBy(vertical).size());
anyEnabled[i] = true;
}
++i %= ranges.size();
}

auto max = Math::Range(0.0, 0.0);
for (auto i = 1U; i < ranges.size(); ++i)
for (auto i = 0U; i < ranges.size(); ++i)
if (anyEnabled[i]) max = max + ranges[i];

for (auto i = 1U; i < ranges.size(); ++i)
Expand Down
Loading