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

Flowchart: Apply nodeSpacing/rankSpacing config to subgraphs #5183

Conversation

rowanfr
Copy link
Contributor

@rowanfr rowanfr commented Jan 7, 2024

📑 Summary

This commit resolves the issues with subgraph configuration, specifically for nodeSpacing and rankSpacing. This commit additionally adds an example graph to the flowchart.html to demonstrate this resolution.

Resolves #3258

📏 Design Decisions

This is a fairly simple modification that applies the configuration held in the label for the overall graph to the configuration for the cluster/subgraph in order to ensure they have matching configurations. This is done right before recursiveRender begins to render each cluster. The reason this needs to be done is that the label for the subgraphs do not contain the correct nodeSpacing and rankSpacing based on the mermaid configuration. Therefore if one overwrites the graph label right before rendering it resolves the mismatch of configurations.

Some potential improvements for this commit would be to allow subgraphs to have there own customization labels. This would be fairly trivial (presumably) by just replacing graph.graph() with whatever settings you want from whatever configurations you want.

📋 Tasks

Make sure you

  • 📖 have read the contribution guidelines
    💻 have added necessary unit/e2e tests. (Not necessary to my knowledge though I'm open to alternative opinions)
    📓 have added documentation. Make sure MERMAID_RELEASE_VERSION is used for all new features. (Not necessary to my knowledge as this is a bugfix)
  • 🔖 targeted develop branch

This commit resolves the issues with subgraph configuration, specifically for nodeSpacing and rankSpacing. This commit additionally adds an example graph to the `flowchart.html` to demonstrate this resolution. This commit resolves mermaid-js#3258
Copy link

netlify bot commented Jan 7, 2024

Deploy Preview for mermaid-js ready!

Name Link
🔨 Latest commit dbb69ad
🔍 Latest deploy log https://app.netlify.com/sites/mermaid-js/deploys/65fec65592a8220008dc6866
😎 Deploy Preview https://deploy-preview-5183--mermaid-js.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Jan 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 5.74%. Comparing base (223f339) to head (b78f16e).

❗ Current head b78f16e differs from pull request most recent head dbb69ad. Consider uploading reports for the commit dbb69ad to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           develop   #5183      +/-   ##
==========================================
- Coverage     5.74%   5.74%   -0.01%     
==========================================
  Files          277     277              
  Lines        41743   41751       +8     
  Branches        27      27              
==========================================
  Hits          2400    2400              
- Misses       39342   39350       +8     
  Partials         1       1              
Flag Coverage Δ
unit 5.74% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/mermaid/src/dagre-wrapper/index.js 0.00% <0.00%> (ø)

Copy link
Contributor

@nirname nirname left a comment

Choose a reason for hiding this comment

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

Hi! Thanks for addressing the issue! Deployment failed, we will have to investigate why, but regardless of this there are some minor comments.

demos/flowchart.html Outdated Show resolved Hide resolved
Co-authored-by: Nikolay Rozhkov <nironame@gmail.com>
@rowanfr
Copy link
Contributor Author

rowanfr commented Jan 14, 2024

@nirname Thanks for the suggested change in syntax, I didn't even know that was available

@rowanfr rowanfr requested a review from nirname January 14, 2024 23:20
@rowanfr rowanfr marked this pull request as draft January 16, 2024 01:27
There was an issue with overriding the subgraphs with the main graphs direction which this commit fixes. It only overrides `rankdir` on the `setGraph` function so that the subgraph preserves it's `rankdir`. There is likely a better way of doing this by modifying the initialization of subgraph configuration to match the main graph when it comes to other elements in the JSON object which composes the graph label.

As we modify the codebase this added line can be deprecated once we add more modular control to subgraphs such as allowing custom spacing or configurations for them. As `rankdir` is the only thing one can set with the `direction` keyword that is the only variable being overwritten for now.
@rowanfr rowanfr marked this pull request as ready for review January 16, 2024 02:50
@sidharthv96

This comment was marked as resolved.

@rowanfr
Copy link
Contributor Author

rowanfr commented Jan 20, 2024

@sidharthv96 Could you tell me how or where you encountered the errors that your showing? I'm using the dev server to get output data and they all seem to be resolving as expected. I'm unfortunately unfamiliar with cypress so I don't know how to run it locally.
image

@sidharthv96
Copy link
Member

It was observed after the run of the E2E test that was triggered by the pull request event (not the push event).

@rowanfr
Copy link
Contributor Author

rowanfr commented Jan 20, 2024

After some research the e2e test failing doesn't seem to occur locally outside of randomly when changing the window or running other applications (and even this doesn't align with the CI tests which fail), however Cypress errors for rendering/flowchart-v2.spec.js and rendering/flowchart.spec.js don't occur locally on Firefox Nightly or Electron after testing. I think this means that the tests are configured to take snapshots too early, but I'm still investigating it.

@rowanfr
Copy link
Contributor Author

rowanfr commented Jan 20, 2024

For the examples above all seem to have the links and graphs shift position slightly. This seems to be an browser dependent issue as I can test locally on electron it repeatedly produce successful graphs for Cypress, firefox nightly seems to randomly produce successful graphs while edge and chrome do not. As I've stated earlier I'll look into this a bit further but I think this has to do with browser rendering diff, which I don't have the ability to address

@sidharthv96
Copy link
Member

Hmm, The E2E tests are working fine on other PRs, so it means some change in this one is triggering the browser inconsistency, and it's failing consistently as well, not flaky.

Maybe your change has some other effects downstream that's causing the issue. We'll have to investigate further.

@aloisklink @nirname @Yokozuna59 do you folks have any pointers?

Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

I think I've spotted the issue that was causing the E2E tests to fail, we just need to slightly modify the code so that it doesn't copy the parent graph's margin.

It would also be nice to have a very basic E2E test in the cypress/integration/rendering/flowchart-v2.spec.js file (e.g. your demo diagram), just so we get automated tests so we know not to break your feature!

Other than that, this PR looks good to me. Awesome work in finding the place to update in the first place, the packages/mermaid/src/dagre-wrapper/index.js file is pretty difficult to understand!

packages/mermaid/src/dagre-wrapper/index.js Outdated Show resolved Hide resolved
demos/flowchart.html Show resolved Hide resolved
The code setting the `ranksep` and `nodesep` to subgraphs was made cleaner and more legible while maintaining the intended functionality of subgraph spacing

Co-authored-by: Alois Klink <alois@aloisklink.com>
This adds E2E testing for spacing and provides more appropriate comments for the changes made to `index.js`
@rowanfr
Copy link
Contributor Author

rowanfr commented Feb 29, 2024

@aloisklink Thanks for spotting the issue that was causing the E2E tests to fail. That problem genuinely had me completely stumped for months. I've added the E2E testing for subgraph configuration as you suggested

@aloisklink aloisklink changed the title Resolved issue with subgraph configuration Flowchart: Apply nodeSpacing/rankSpacing config to subgraphs Feb 29, 2024
Copy link
Member

@aloisklink aloisklink left a comment

Choose a reason for hiding this comment

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

Looks awesome to me now! Btw, I've slightly adjusted the PR title, let me know if you don't like it and want to change it back (or to something else).

Thanks for spotting the issue that was causing the E2E tests to fail. That problem genuinely had me completely stumped for months.

Yep, the dagre-wrapper/index.js file is really really hard to read. I really want to look into converting it to TypeScript and adding at least some documentation to it, but I think we might also need to fix some types in a third-party library (and that library is also very undocumented), so it would be a lot of work :(

@aloisklink aloisklink added Type: Bug / Error Something isn't working or is incorrect Graph: Flow labels Feb 29, 2024
@rowanfr
Copy link
Contributor Author

rowanfr commented Feb 29, 2024

The new title looks great and is more accurate to the solution, the earlier title was generally what was desired so the change to it makes sense.

As for dagre-wrapper/index.js I agree that unraveling that back to third party libraries that eventually rely on graphlib graph labels for rendering logic was fairly difficult and TypeScript alongside further documentation of the third party libraries would go a long way to help

@rowanfr
Copy link
Contributor Author

rowanfr commented Feb 29, 2024

The E2E tests are failing due to some separate git graph tests that were failing due to randomized commit IDs as detailed in the issue #5343 and the subsequent PR #5344. If we merge those minor changes the E2E testing for this PR should be resolved.

@rowanfr
Copy link
Contributor Author

rowanfr commented Mar 1, 2024

@nirname could you check over the changes you've requested to see if they've been completed and then approve the PR if you feel confident?

@Stevio54
Copy link

Is there an update to this pull request, I am having the same issues and would love a solution :)

@rowanfr
Copy link
Contributor Author

rowanfr commented Mar 12, 2024

@Stevio54 It's feature complete, it just needs to be merged

@sidharthv96 sidharthv96 merged commit 12bf139 into mermaid-js:develop Mar 23, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Graph: Flow Type: Bug / Error Something isn't working or is incorrect
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Flowchart node spacing doesn't apply when using subgraph
5 participants