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

Fix treemap negatives #514

Merged
merged 6 commits into from
Mar 25, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- next() can be called multiple times from Plugin hooks
- Line and circle chats with only dimensions on x, and y axes the markers were off the axis labels.
- Crash on TreeMap only with negative values

### Added

Expand Down
5 changes: 3 additions & 2 deletions src/chart/generator/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ void Plot::generateMarkers(const Data::DataTable &table)
}
clearEmptyBuckets(mainBuckets, true);
clearEmptyBuckets(subBuckets, false);
auto conn = linkMarkers(mainBuckets, true);
auto hasMarkerConnection = linkMarkers(mainBuckets, true);
linkMarkers(subBuckets, false);

if (conn && options->geometry.get() == ShapeType::line
if (hasMarkerConnection
&& options->geometry.get() == ShapeType::line
&& options->getChannels().at(ChannelId::x).isDimension()
&& options->getChannels().at(ChannelId::y).isDimension()) {
markerConnectionOrientation.emplace(
Expand Down
12 changes: 9 additions & 3 deletions src/chart/speclayout/treemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ TreeMap::TreeMap(const std::vector<double> &sizes,
for (auto j = 0U; j < sizes.size(); ++j)
markers.emplace_back(j, sizes[j]);

std::sort(markers.begin(), markers.end(), SpecMarker::sizeOrder);
std::ranges::sort(markers, SpecMarker::sizeOrder);

divide(markers.begin(), markers.end(), p0, p1);
auto it = std::ranges::upper_bound(markers,
SpecMarker{0, 0.0},
SpecMarker::sizeOrder);

std::sort(markers.begin(), markers.end(), SpecMarker::indexOrder);
divide(markers.begin(), it, p0, p1);

while (it != markers.end()) it++->emplaceRect({0, 0}, {0, 0});

std::ranges::sort(markers, SpecMarker::indexOrder);
}

void TreeMap::divide(It begin,
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/tests/fixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
},
"53978116": {
"refs": ["d0d0298"]
},
"55278793": {
"refs": ["6825f33"]
}
}
}
22 changes: 22 additions & 0 deletions test/e2e/tests/fixes/55278793.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const testSteps = [
(chart) =>
chart.animate({
data: {
series: [
{
name: 'D1',
values: ['v1', 'v2']
},
{
name: 'M1',
values: [-1, -2]
}
]
},
config: {
size: ['D1', 'M1']
}
})
]

export default testSteps
2 changes: 2 additions & 0 deletions tools/ci/run/init-py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ if ! python3 -c 'import sys; assert sys.version_info >= (3,10)' > /dev/null; the
exit 1
fi

test -f ~/.netrc && chmod u+rw,u-x,go-rwx ~/.netrc

python3.10 -m venv --copies ".venv" || python3 -m venv --copies ".venv"
source .venv/bin/activate
pip install pdm==2.10.3
Expand Down