Skip to content

Conversation

@4cyc
Copy link
Contributor

@4cyc 4cyc commented Jun 10, 2022

Add Mermaid diagrams for better visualization of the examples and to make use of version control. It will be also easier to edit the diagram if the examples change.

@harshil21 harshil21 added enhancement 📋 pending-review work status: pending-review ⚙️ examples affected functionality: examples labels Jun 11, 2022
@harshil21 harshil21 added this to the v20.0a2 milestone Jun 11, 2022
@Bibo-Joshi
Copy link
Member

Bibo-Joshi commented Jun 19, 2022

Hi. Thanks for the PR! Having the state diagram in a text-like format would indeed be nice. Can you explain how one would generate pictures with mermaid and/or how one could embedd those diagrams into the respective examples pages (e.g. here)?
So far I haven't worked much with diagram-generation-software, although one of our emeritus maintainers suggested graphviz on a few occasions …

@4cyc
Copy link
Contributor Author

4cyc commented Jun 19, 2022

Hi @Bibo-Joshi, I've used Mermaid since it is supported and rendered in Github in the Markdown view. To include it is as easy as having a code block like ```mermaid ---- mermaid code here ---- ``` You can read more about it in the Github Blog Post. Mermaid is based on JavaScript, I hope that is fine.

@Poolitzer
Copy link
Member

The sphinx plugin should be enough, no need to self host an API.

Copy link
Member

@harshil21 harshil21 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for the PR.

Can you explain how one would generate pictures

I can see that we can download it as svg/png at https://mermaid.live

The sphinx plugin should be enough

Agreed. Other options would be to use svg/png, but that would mean updating those files too after changing the mermaid code -- double work.


Can you also apply similar changes by integrating the sphinxcontrib-mermaid sphinx extension?

You'll have to add it to the conf.py and requirements-docs.txt. I guess we can just use these files as the reference by doing: .. mermaid:: examples/conversationbot.md in the docs/examples.conversationbot.rst file, and then build the docs locally by following our contribution guide.

@harshil21 harshil21 removed the 📋 pending-review work status: pending-review label Jun 20, 2022
@Bibo-Joshi
Copy link
Member

If we can integrate the diagrams into sphinx directly, then we should do that and ditch images completely, I agree. Just for completeness: I see that sphinx has built-in support for graphivz, i.e. we wouldn't need a plugin. I'm fine with using a plugin, though.

4cyc and others added 5 commits June 21, 2022 19:26
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com>
@4cyc
Copy link
Contributor Author

4cyc commented Jun 22, 2022

I've installed the sphinx mermaid extension and embedded it successfully in the docs. However, there are a few things to be aware of:

  • The dark mode makes the lines hard to read. This is a known issue at Mermeid and I can only change the color of the lines, not the arrowheads (see here). A quick workaround could be to style Mermaid diagram backgrounds (div with class mermaid) to a lighter grey. Together with some border-radius this can look well integrated within the documentation.
  • It would be good to add height: auto to the SVG inside the mermaid div, especially for the nested conversation which seems too wide for the column

@Bibo-Joshi
Copy link
Member

Hi, thanks for the updates!

Personally I don't see a problem with darkmode - IMO the lines are rather well visible. I'm attaching screenshots below so that the others can see without having to build the docs :)

Having the nestedconversationbot chart a bit wider would be nice, I agree. Don't recall exactly how one would modify the css here. If it's a small additional snippet for the sphinx config, we can do that. if it's a bigger effort, I'm also okay with user having to zoom in :D

I have some other comments on the layout:

  • in the nested conv. diagram, go directly to termination instead of listing "End" as state
  • the diagram for conversationbot2.py is missing some sort of exit.
  • IMHO the legend is not really necessary. I'm okay with keeping it, but would suggest to do the following (if possible)
    • rename First State to Entry Point & Termination to End
    • adjust the size of entry point & end to be no bigger than State
    • make the "input -> state" left to right instead of top to bottom and list enrty point & end below that - saves some space
  • the bright background of the legend and the nested conversation seems off in both bright & dark mode. If possible, please remove.
  • in the nested example, it would be nice to have the nested conversation and the main conversation more vertically aligned. I guess that mermaid computes this automatically and that it's hard to fine tune that - just listing for completeness :)
Screenshots

image
image

@4cyc
Copy link
Contributor Author

4cyc commented Jun 23, 2022

I've included most of the things that you've mentioned plus did some additional improvements. Like you've already guessed, some things are automatically created by Mermaid and I sadly cannot change e.g. the alginment of the nested conversation. A few things to note:

  • The background of the nested conversation is grey now which aligns more with the rest of the diagram, fill: none would make it very hard to read the title.
  • I have added a small css file to remove the unecessary whitespace of the nested conversation diagram (style_mermaid_diagrams.css)

@Bibo-Joshi
Copy link
Member

Thanks for the new updates! I built the docs from your branch locally and everything looks fine to me now :) If I get a LGTM from pool or harshil, we can merge :)

@harshil21
Copy link
Member

can we remove the old .png diagrams in the examples folder then?

Copy link
Member

@harshil21 yes 👍

@Bibo-Joshi Bibo-Joshi merged commit 76bfe8c into python-telegram-bot:master Jun 24, 2022
@Bibo-Joshi
Copy link
Member

Thank you for the nice cnotribution! :)

@4cyc 4cyc deleted the mermaid-example-diagrams branch June 24, 2022 16:29
@github-actions github-actions bot locked and limited conversation to collaborators Jul 1, 2022
@harshil21 harshil21 modified the milestones: v20.0a3, v20.0a2 Jul 23, 2022
@Bibo-Joshi Bibo-Joshi added 🔌 enhancement pr description: enhancement and removed enhancement labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

🔌 enhancement pr description: enhancement ⚙️ examples affected functionality: examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants