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 -> tablemap #540

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Unreleased]

### Fixed

- Only dimension on size (+ color) wrongly displayed as treemap, not tablechart.
- When markers size is factorisable to 2 numbers product on a tablechart, and the multipliers ratio is less than 16/9,
the area fully filled with equal marker rectangles.


## [0.11.1] - 2024-05-31

### Fixed
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 @@ -184,7 +184,7 @@ void PlotBuilder::addSpecLayout(Buckets &buckets)
}
else if (auto &&size = plot->getOptions()->getChannels().at(
ChannelId::size);
size.isEmpty()) {
size.isDimension()) {
Charts::TableChart::setupVector(markers);
}
else if (!dataCube.empty()) {
Expand Down
21 changes: 16 additions & 5 deletions src/chart/speclayout/tablechart.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ template <typename Item>
void TableChart::setupVector(std::vector<Item> &items,
bool singleColumn)
{
if (items.empty()) return;

auto size = 0;
for (auto &item : items)
if (item.enabled) ++size;

auto rowsize =
singleColumn ? 1 : static_cast<ssize_t>(ceil(sqrt(size)));
if (size == 0) return;

ssize_t rowsize{1};
if (!singleColumn) {
rowsize = static_cast<ssize_t>(ceil(sqrt(size)));
auto sq = static_cast<ssize_t>(ceil(sqrt(
16.0 * static_cast<double>(rowsize * rowsize) / 9.0)));
schaumb marked this conversation as resolved.
Show resolved Hide resolved

auto rem = rowsize - 1 - (size - 1) % rowsize;
simzer marked this conversation as resolved.
Show resolved Hide resolved
schaumb marked this conversation as resolved.
Show resolved Hide resolved
for (auto i = rowsize + 1; rem > 0 && i < sq; ++i)
if (auto newRem = i - 1 - (size - 1) % i; newRem < rem) {
rowsize = i;
rem = newRem;
}
}
auto colsize = ceil(
static_cast<double>(size) / static_cast<double>(rowsize));

Expand All @@ -37,7 +48,7 @@ void TableChart::setupVector(std::vector<Item> &items,
if (item.enabled) {
item.spacing = {1, 1};
auto div = std::div(cnt++, rowsize);
item.position = {(1.0 + static_cast<double>(div.rem))
item.position = {static_cast<double>(div.rem + 1)
/ static_cast<double>(rowsize),
1.0 - static_cast<double>(div.quot) / colsize};
item.size = markerSize;
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test_cases/test_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -2930,7 +2930,7 @@
"refs": ["ad12fd0"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_Ve1/07a_d-w_rec_Ve2_1c": {
"refs": ["0b50210"]
"refs": ["1fb2de3"]
},
"ww_noFade/wNoFade_cases/2_des_pol-without/rectangle_Ve1/07a_d-w_rec_Ve2_2c": {
"refs": ["fe75086"]
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 @@ -34,6 +34,9 @@
"536": {
"refs": ["05d387c"]
},
"540": {
"refs": ["108b737"]
},
"32303048": {
"refs": ["b5d95ea"]
},
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/tests/fixes/540.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const testSteps = [
(chart) =>
chart.animate({
data: {
series: [
{ name: 'Foo', type: 'dimension' },
{ name: 'Bar', type: 'dimension' }
]
},
config: {
size: ['Foo']
},
style: {
plot: {
marker: {
rectangleSpacing: 0
}
}
}
})
]

testSteps.push(
...[...Array(36).keys()].map(
(i) => (chart) =>
chart.animate(
{
data: {
records: [[`Foo${i}`, `${i}`]]
}
},
0.1
)
)
)

testSteps.push((chart) => chart.animate({ config: { color: 'Bar', legend: null } }, 0.5))

testSteps.push(
...[...Array(36).keys()].map(
(i) => (chart) =>
chart.animate(
{
data: {
filter: (record) => parseInt(record.Bar) > i
}
},
0.1
)
)
)

export default testSteps