Skip to content

Treemap Improvements #225

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

Closed
wants to merge 3 commits into from
Closed

Conversation

Lithopsian
Copy link
Contributor

Changes for issues #223 and #224.

createSquarifiedChildren() is modified to support full squarification, laying out each row along the shorter dimension of the remaining rectangle instead of the longer one. squarify() is largely rewritten to compile a row of tiles in the appropriate direction, choosing the row that makes the first and last tiles as close as possible to square. layoutRow() is modified to lay out and scale along the shorter side of the remaining rectangle. Rounding is controlled better to reduce tearing between tiles and ensure filling of each row. With minTileSize=0, children are scaled to exactly fit the parent tile, ignoring the allocated size of the parent, just for neatness (symlinks are still shown, or not, with zero size).

The first call to addRidge() in layoutRow() is changed to be made against a new rectangle encompassing just that row instead of the whole remaining space. This avoids the highlights being excessively pulled towards the bottom or right of the parent; they are now pulled modestly towards the centre of each row and somewhat towards the centre of their parents.

renderCushion() is modified to more closely match the algorithm in the published paper. The initial color values are scaled to avoid ambient light overflow instead of being reduced by an absolute value (ie. dark colours are darkened less). The signs of the X and Y coefficients are changed (I'm fairly sure this is how they are in the paper, but struggle to see much difference in the final cushions). Some values are pre-calculated for speed (Ia, Is, and the adjusted lightX, lightY, and lightZ could all be calculated once and stored on the parent view, but that's for another day).

Update the squarification algorithm, fix the associated aspect ratio comparison, and fix the shading.
Update member declarations for squarification changes.
Tweak so that the scaling with minTileSize>0 generally leaves visible blank tiles.
@shundhammer
Copy link
Owner

shundhammer commented Nov 23, 2023

First Impressions

I like it; the treemap tiles are much more square than before.

But there is a caveat: The shading is too pronounced in some cases, up to a point where the largest tiles all drown out in a dark mush; see screenshots below.

Comparison Old and New

/usr on my OpenSUSE Leap 15.5

treemap-usr-01-old
Old

treemap-usr-02-new
New

My Home Directory

treemap-home-sh-01-old
Old

Notice how you can see the treemap tile boundaries in the top left corner; which is important to compare them against each other.

treemap-home-sh-02-new
New

Notice how the boundaries between the tiles became invisible in the top left corner with all that dark shading.

treemap-home-sh-03-new-tile-selected

With a click into that area, the boundary of that one tile becomes visible.

@shundhammer
Copy link
Owner

shundhammer commented Nov 23, 2023

If I understood you correctly, the new algorithm adds more ridges; one for each subdivision. Correct?

If that is indeed the case, the "height" of the ridge (i.e. the light falloff) could probably be tweaked to make each ridge less pronounced so there is less contrast for each one. Could you try that?

Maybe also changing the direction where the light comes from might help; top left instead of (how it looks to me) bottom right. That might put more light on the important tiles, the largest ones which are on the top left.

@Lithopsian
Copy link
Contributor Author

There aren't any more ridges than before, but the row ridges are much smaller and it produces more contrast and hence darker darks. I agree the general appearance is darker, possibly too dark. That can be tweaked with one of three settings:

  1. CushionHeight, currently hard-coded to 1.0, but lower values will brighten the dark areas. A value of 0.5 or 0.6 might work as a default setting, it should probably be configurable because this is perhaps the most important and useful setting. You can also try above 1.0 but probably not useful in practice.
  2. HeightScaleFactor, already configurable. It is the amount by which the cushion height is decreased at each tree level. Currently defaults to 0.8 which is good. Lower values will tend to wash out the cushions although that does brighten the darker areas. 0.9 or 1.0 will produce more definition on the leaf tiles but may be too dark without adjusting other settings.
  3. AmbientLight, also configurable. It sets a lower limit on the darkest shadows and brightens everything else proportionally. It obviously brightens the darker areas but again tends to reduce the contrast.

The original papers fixes ambient light at 40, and considers the other two to be configurable to taste, although it suggest a cushion height of 0.5 and height factor of between 0.5 and 1.0. The examples they show are of white cushions (I think, the paper is in black and white), so not quite as dark as using colours.

@Lithopsian
Copy link
Contributor Author

About the "extra" row cushion. It doesn't really exist! Squarified tile cushions are deformed in both the x and y directions. In a single row, the coefficients along the short axis are identical for every tile in the row, so they can all be created at once and then that cushion surface (its coefficients and height) inherited down to the individual tiles. The row cushion is then forgotten and it isn't rendered separately. Or you can think of it as a row cushion with bumps along it if you like, but the row cushion isn't there in the final treemap.

The height scale factor is only ever applied at the creation of new tiles inside a parent directory. This should probably be done in the constructor and the ability to change the height manually could be removed, but that would make it tricky to factor down the height for the dummy row cushion, because it needs its height reduced by the scale factor to match the child tiles that haven't yet been created.

Anyway, I think the calculation is correct in this code, although like a lot of things it could be tidied up and speeded up.

@shundhammer shundhammer changed the title Treemap Treemap Improvements Nov 25, 2023
@shundhammer
Copy link
Owner

shundhammer commented Nov 25, 2023

I just merged this into a new feature branch better-treemap for parameter tweaking before merging that branch into master.

Thank you for your contributions!

@shundhammer
Copy link
Owner

I finally found time to tune those treemap shading parameters a bit. This is the preliminary outcome:

Treemap-dynamic-factors-root

Treemap-dynamic-factors-home

Treemap-dynamic-factors-src

That old factor of a constant 4.0 in the addSquareRidge() and addLinearRidge() functions has now become a somewhat dynamic one; it's now degressive the more ridges are added, so deeply nested treemaps don't look so dark anymore, yet shallow trees don't just become washed out with very light colors.

I think we can live with that result. I'll still play around a bit with it, and then I will probably merge the branch to master.

@Lithopsian
Copy link
Contributor Author

That's pretty much what the height scale factor does, although it doesn't stop at a depth of five tiles. The 4.0 is a holdover from the illumination calculations. Really you're working with a height of 4.0 times the nominal height. The equivalent figures for the official algorithm with a height of 0.6 (4*height=2.4) and a scale factor of 0.8 are:
2.4
1.9
1.5
1.2
1.0
Note that the scale factor calculation in my code is applied once per tile, not one per ridge. If you still have the scale factor code in (and configured to be less than 1.0) then the height will be changing in addition to your factor.

I experimented quickly with capping the height scale factor at a height of 1.0 (starting from 4*0.6) . Less effect than I expected. Very slightly darker than the equivalent uncapped configuration. In theory, it should give very slightly darker shadows on the leaf-level tiles, but not on the larger top-level tiles.

@Lithopsian Lithopsian deleted the Treemap branch December 22, 2023 16:03
@shundhammer shundhammer mentioned this pull request Dec 24, 2023
@shundhammer
Copy link
Owner

See also the summary in #236.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants