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

core(mermaid): allow greater customization #29939

Merged
merged 4 commits into from
Mar 21, 2025
Merged

Conversation

ianchi
Copy link
Contributor

@ianchi ianchi commented Feb 23, 2025

Adds greater style customization by allowing a custom frontmatter config. This allows to set a theme and look or to adjust theme by setting themeVariables

Example:

node_colors = NodeStyles(
    default="fill:#e2e2e2,line-height:1.2,stroke:#616161",
    first="fill:#cfeab8,fill-opacity:0",
    last="fill:#eac3b8",
)

frontmatter_config = {
    "config": {
        "theme": "neutral",
        "look": "handDrawn"
    }
}

graph.get_graph().draw_mermaid_png(node_colors=node_colors, frontmatter_config=frontmatter_config)

image

Copy link

vercel bot commented Feb 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2025 10:18pm

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. Ɑ: core Related to langchain-core labels Feb 23, 2025
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Feb 23, 2025
@vbarda
Copy link
Contributor

vbarda commented Feb 24, 2025

@ianchi thanks for the contribution! could you please separate the subgraph fix into a separate PR and add a test for it in libs/core/tests/runnables/test_graph.py?

@ianchi
Copy link
Contributor Author

ianchi commented Feb 24, 2025

Done.
The fix has been moved to PR #29970

Just a warning. Doing it in two separate PR brings a problem. If both were merged tests would fail.
This PR changes single quotes to double quotes in INIT directive (as that is what is generated by json.dumps, and is a valid directive). All tests are adjusted in this PR, but the new test in PR #29970 doesn't exist yet for this PR so it cannot be changed.

One of the PR should be ammended after the other is merged.

@vbarda
Copy link
Contributor

vbarda commented Mar 4, 2025

thanks! I merged the fix PR - feel free to update

@ianchi
Copy link
Contributor Author

ianchi commented Mar 5, 2025

hi @vbarda the PR has conflicts resolved

@ianchi
Copy link
Contributor Author

ianchi commented Mar 11, 2025

Hi @vbarda, I believe this is ready to be merged.
If you find anything else is needed please let me know.

@vbarda
Copy link
Contributor

vbarda commented Mar 17, 2025

@ianchi thanks! i might actually do a slightly different refactor, since looks like directives are actually deprecated now so might as well go w/ the new recommended format https://mermaid.js.org/config/directives.html

By allowing an init directive most styles can be customized.
By setting a `theme` and `look` or by setting `themeVariables`
@ianchi
Copy link
Contributor Author

ianchi commented Mar 17, 2025

Hi @vbarda I've updated to use frontmatter.
Tests need to be rewritten, but first I wanted to check with you.

@vbarda
Copy link
Contributor

vbarda commented Mar 17, 2025

@ianchi i was looking more at mermaid docs and it looks like frontmatter is really poorly documented. i think we can keep your original change! sorry for the false alarm

@ianchi
Copy link
Contributor Author

ianchi commented Mar 17, 2025

It is not well documented, but basically in the config property of the front matter you include the same as in directives.
The documentation for directive is valid for "config".

It is not a bad idea to use front matter, if you use the live playground it is what is generated, so it is easy to copy from there.

@vbarda
Copy link
Contributor

vbarda commented Mar 18, 2025

@ianchi fair point - i didn't have any other concerns besides that, so you can go ahead w/ updating tests :) thanks!

@ianchi
Copy link
Contributor Author

ianchi commented Mar 20, 2025

Hi @vbarda, updated tests.

@vbarda
Copy link
Contributor

vbarda commented Mar 21, 2025

Thank you @ianchi - made a few small changes and will merge!

@vbarda vbarda merged commit 3933a4a into langchain-ai:master Mar 21, 2025
71 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants