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

stable color rendering #501

Merged
merged 6 commits into from Aug 19, 2022
Merged

stable color rendering #501

merged 6 commits into from Aug 19, 2022

Conversation

CreativeTechGuy
Copy link
Contributor

Fixes #500

There's a ton of variance in how users may configure their chunk names. To ensure stable colors, we need to dynamically identify which (if any) part of the file name is the unique "name" part and use that to determine the colors. If that cannot be identified or if a file doesn't follow the pattern of the rest, the entire file name will be used.

Given that the behavior before was random rainbow colors all the time (colors would even change when zooming/hiding) this is better even in the case where nothing can be uniquely identified. So I'd argue that while this is an imperfect solution, it's better in all cases than what was there by default.


This is best visualized with photos of the different cases:

Before this PR:

old

After this PR (when unique name can be identified):

new-before-change

After this PR (when unique name can be identified - with chunk contents changed but colors are still stable with above):

new-with-change

After this PR (with no identifiable parts of the filename - deterministic but effectively random colors):

no-names

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 27, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: CreativeTechGuy / name: Jason O'Neill (66841ea)

@valscion
Copy link
Member

Thanks for opening a PR! This is indeed an interesting approach.

The loops look a tad scary to me, as I don't know how they would perform with large graphs. I also am not sure if there is no way an infinite loop could happen there.

Is there a way to get some data to the graph data object itself that could be used for this purpose with less likelihood for a performance hit?

@CreativeTechGuy
Copy link
Contributor Author

Thanks for taking the time to review @valscion!

Quick time complexity analysis just to make sure we are on the same page. I assume you are talking about findChunkNamePartIndex.

It is almost entirely bounded by the number of chunks, secondarily the number of parts of the most complex file name.

So if there are 100 chunks and the most complex file name is a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.js (27 parts) then it'd be:

O(100 * 27) = O(2700)

The only thing I really see as performance impacting is if a user has a ton of chunks, realistically that's the only variable that affects time complexity in a realistic way here. But if someone has a few hundred chunks, the canvas rendering will also be impacted by having to compute the layout of all of those chunks too. I'd suspect this function's additional performance hit wouldn't be noticeable in comparison.


The only place I can see an infinite loop being possible is in getGroupRoot, but that tree traversal is very similar to the one just a few lines below in zoomToGroup which seems to be working fine. Assuming that an infinite loop isn't possible here, I believe the number of nested groups in the graph is based on the folder structure, so I'd be surprised if there's any node that is more than a dozen folders deep in the project.


Let me know if we are on the same page here and if you want me to make any edits or run any tests to make sure this is working correctly at scale.

@valscion
Copy link
Member

Thanks for the additional information 😊 good point about the count of chunks impacting the layout calculation anyway.

I have been able to only glance at the code on mobile so far so I haven't yet been able to do a more thorough review.

@CreativeTechGuy
Copy link
Contributor Author

@valscion have you been able to take a look? This seems like a valuable improvement that would be great to get merged! :)

@valscion
Copy link
Member

Sorry, this is still pending. I'm currently on paternal leave so I have little time to spend on computer 😊

@valscion
Copy link
Member

valscion commented Jun 17, 2022

Hi @CreativeTechGuy! I'm still on parental leave, so I haven't yet had a chance on checking this out. I haven't forgotten about this PR, though, and will get back to this once I have more time ☺️. Thank you for your patience

@valscion
Copy link
Member

OK I now took a look here. This indeed makes figuring out which chunks changed in size much easier than before! I ran a simple test with our application where I added a lot of extra strings to a single module to make it grow in size and then looked at the differences before and after:

Without this PR

Before

Screenshot_2022-08-17_at_10-41-28_venuu_17_Aug_2022_at_10_37_comparison

After

Screenshot_2022-08-17_at_10-41-28_venuu_17_Aug_2022_at_10_37

Notes

It's quite difficult to see that the chunk containing packages/edit/index.js shifted and grew in size. Rather, it's quite easy to miss that as the chunks indeed shift around the treemap a lot.

With this PR

Before

Screenshot_2022-08-17_at_10-24-06_venuu_17_Aug_2022_at_10_23_comparison

After

Screenshot_2022-08-17_at_10-41-05_venuu_17_Aug_2022_at_10_40

Notes

I can now spot which chunks changed place and can spot that the packages/edit/index.js shifted, allowing me to see that the chunk sizes differ. Other colors remained stable and allows me to see that the chunk 7928 also changed place.

@valscion
Copy link
Member

The only consideration I have in here is that the choice of colors now is quite bright and hides some details in some places that the FoamTree built-in color algorithm was able to discover:

Screenshot_2022-08-17_at_10-24-06_venuu_17_Aug_2022_at_10_23

Compare that to the original version (the chunk contents are the same) and you can see that there are more details immediately visible before this PR:

Screenshot_2022-08-17_at_10-24-00_venuu_17_Aug_2022_at_10_21

So I wonder is there a way to tweak the color deciding algorithm to get a bit more muted colors so that they'd be easier on the eye and also be able to see the count of sub-modules more easily?

@CreativeTechGuy
Copy link
Contributor Author

I'd argue that the colors in the original version are just as similar (see the huge cluster of similar teals in the bottom right) but it is just more noticeable now that the colors are more vibrant. I'm not sure there's simply enough colors which are visually distinct enough to avoid this problem.

I'll work on making the colors more muted. Although I think that the more muted the colors are, the more that will start to look visually similar.

In my testing, as we reduce the saturation on the colors, it starts to look "disabled" so I don't want to mute them too much that it starts to communicate some functional state which would be misleading.

@CreativeTechGuy
Copy link
Contributor Author

I toned down the saturation a bit. I think this is a good middle ground. It looks like this
image

Hopefully you like it!

@valscion
Copy link
Member

I toned down the saturation a bit. I think this is a good middle ground. It looks like this

Oh wow this looks much nicer!

I see no reason why we would not be able to ship this soon. Do you think this feature warrants a small mention in the README.md or is it OK to leave undocumented?

Adding a changelog entry at least would be nice ☺️. Make sure to update your branch (merge commit is OK to me) with the master branch in this repository before tweaking the changelog as otherwise there's likely gonna be conflicts.

@CreativeTechGuy
Copy link
Contributor Author

Got it! Rebased with master and added a line to the Changelog!

I'm not sure about documenting this. It's not configurable and shouldn't break anything. Also, if someone doesn't understand it and just thinks they are random, then there's no harm. Worst case it's the same as it was previously, best case it's an improvement. :)

Copy link
Member

@valscion valscion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks great to me! 👍

@valscion valscion merged commit 3ce0d21 into webpack-contrib:master Aug 19, 2022
@valscion
Copy link
Member

This has now been released in v4.6.0 ☺️

crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Aug 23, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) | devDependencies | minor | [`4.5.0` -> `4.6.0`](https://renovatebot.com/diffs/npm/webpack-bundle-analyzer/4.5.0/4.6.0) |

---

### Release Notes

<details>
<summary>webpack-contrib/webpack-bundle-analyzer</summary>

### [`v4.6.0`](https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/HEAD/CHANGELOG.md#&#8203;460)

[Compare Source](webpack-contrib/webpack-bundle-analyzer@v4.5.0...v4.6.0)

-   **New Feature**
    -   Support outputting different URL in server mode ([#&#8203;520](webpack-contrib/webpack-bundle-analyzer#520) by [@&#8203;southorange1228](https://github.com/southorange1228))
    -   Use deterministic chunk colors (#[501](webpack-contrib/webpack-bundle-analyzer#501) by [@&#8203;CreativeTechGuy](https://github.com/CreativeTechGuy))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xNjUuMSIsInVwZGF0ZWRJblZlciI6IjMyLjE2NS4xIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1513
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
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.

FoamTree color stability
2 participants