Skip to content

Commit

Permalink
Fix treemap->tablemap
Browse files Browse the repository at this point in the history
  • Loading branch information
schaumb committed Jun 12, 2024
1 parent ced87df commit aeef0ed
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 7 deletions.
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)));

auto rem = rowsize - 1 - (size - 1) % rowsize;
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

0 comments on commit aeef0ed

Please sign in to comment.