-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat: Add mermaid output to show_graph
#20631
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20631 +/- ##
==========================================
- Coverage 79.03% 78.97% -0.07%
==========================================
Files 1557 1560 +3
Lines 220528 221296 +768
Branches 2510 2537 +27
==========================================
+ Hits 174303 174761 +458
- Misses 45651 45954 +303
- Partials 574 581 +7 ☔ View full report in Codecov by Sentry. |
Any way to set it to fixed-width font like Consolas? Reading code in variable-width font is just hard on the eyes. |
@mcrumiller Yes, it is possible to specify a monospace font family in the initialization. If we were to do that, I think it would make sense to generate the raw output without any special settings, but we could insert it prior to displaying to users. As an example, here is the same chart as above with an initialization of |
It seems to me that
then it's not clear to me what I should expect (the current behavior would be to ignore Since
|
@etiennebacher thanks for these comments. Initially, I assumed that anyone needing to output a file would use Graphviz, but you're correct that it is confusing if I have also incorporated @mcrumiller's suggestion, and the mermaid graph now uses monospace font when showing or outputting. My goal with this PR was to add mermaid support without changing the existing API. I have no issue with dedicated functions to access the dot or mermaid raw outputs, but to maintain backwards compatibility we would need to keep logic in One small change to note: previously, calls to |
I can open a dedicated issue based on my first comment so that this PR is only on the mermaid implementation. |
mermaid `show_graph` now displays instead of returning the markdown object. It is now possible to export mermaid charts to file with `mmdc`. The user can now force polars to use graphviz or mermaid when showing the graph or outputting the files.
… raw_output (mypy will not allow the function to return only None)
ef18cab
to
1b87720
Compare
This pull request would close #12075 and supersedes #20607. Thanks again to @ritchie46, @eitsupi, and @alexander-beedie for their feedback.
This PR adds support for mermaid string generation to polars. In #12075 it was suggested that mermaid output be added to
explain
, but I believe that it makes more sense to have mermaid output come from theshow_graph
method instead ofexplain
becauseexplain
appears to be for generating printable representations of the query plan wherasshow_graph
is for generating strings that can be fed to a visualization engine (currently just graphviz).In addition to being able to output mermaid strings this PR will output a mermaid diagram if the user is in a notebook and graphviz is not installed when calling
show_graph
. I think at some point it may be a better user experience to always export mermaid instead of the SVG in notebooks, but for now I did not want to change the behavior. I also considered adding functionality that would change the behavior of_repr_html_
to show a mermaid diagram if graphviz is not installed, but if without a way to check if the user can render mermaid this could be a worse user experience than the current behavior which callsexplain
.Compared with #20607 this PR generates the mermaid string in rust instead of in python.
Here is a sample output:
Note that the mermaid renderer in Jupyter Lab and VS Code (with extension) is theme aware, so the graph changes color with the user theme.