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

Adding mermaidJS for mermaid graphs #518

Merged
merged 5 commits into from
Oct 19, 2024

Conversation

ImtiazKhanDS
Copy link
Contributor

name: Pull Request for adding Mermaid Graphs

about: Propose changes to the codebase
title: 'Add Mermaid graphs in fasthtml websites.'
labels: 'graphs'
assignees: 'Jeremy'


Related Issue
Please link to the issue that this pull request addresses. If there isn't one, please create an issue first.

Proposed Changes
Describe the big picture of your changes here. If it fixes a bug or resolves a feature request, be sure to link to that issue.
mermaid_graph

Types of changes
What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist
Go over all the following points, and put an x in all the boxes that apply:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I am aware that this is an nbdev project, and I have edited, cleaned, and synced the source notebooks instead of editing .py or .md files directly.

Additional Information
Any additional information, configuration or data that might be necessary to reproduce the issue.

Copy link

gitnotebooks bot commented Oct 13, 2024

Found 1 changed notebook. Review the changes at https://app.gitnotebooks.com/AnswerDotAI/fasthtml/pull/518

@pydanny
Copy link
Collaborator

pydanny commented Oct 14, 2024

@ImtiazKhanDS Thanks for submitting this PR, I've added to my blog and given you credit:

Copy link
Collaborator

@pydanny pydanny left a comment

Choose a reason for hiding this comment

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

@ImtiazKhanDS Thanks so much for this PR! This is something I think a lot of people will enjoy having. I do have a change request and a few comment.

Imtiaz's code can be seen in action here: https://daniel.feldroy.com/posts/mermaid-charts

delay=500 # Delay in milliseconds before rendering
):
"Implements browser-based Mermaid diagram rendering."
src = """
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be in a stand-alone JS file rather than a Python string template called with something like Script(rel='/mermaid.js').

Copy link
Contributor

Choose a reason for hiding this comment

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

If you have a look at our other examples Danny we normally use ScriptX or python strings. Otherwise you have to deal with more complex file inclusion during deployment

Copy link
Collaborator

Choose a reason for hiding this comment

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

Apologies, I thought we had moved to a JS-file approach. Based on your response I just looked at https://github.com/AnswerDotAI/fasthtml-js and it wasn't what I thought it was.

fasthtml/js.py Outdated
proc_htmx('%s', () => {
setTimeout(renderMermaidDiagrams, %d);
});
""" % (theme, sel, sel, delay)
Copy link
Collaborator

Choose a reason for hiding this comment

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

While the JS in this file should be in its own file, I will recommend that 99% of the time f-strings are better than this kind of string variable injection. The reason is clarity, which makes debugging easier. The 1% edge case would be to increase performance, however in web dev strings are rarely the bottleneck.

Copy link
Contributor

Choose a reason for hiding this comment

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

the benefit of py2 style formatting here is that you don't have to deal with doubling the curly brackets. it's a minor thing but can be more readable

fasthtml/js.py Outdated
}

proc_htmx('%s', () => {
setTimeout(renderMermaidDiagrams, %d);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the delay? I removed it from the code you submitted for my site, and it appears to work fine. I could be in error, if so we'll keep it in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kept it to say to see the change happening , removed it now, should be working fine without that as well, thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

Afaict this isn't using proc_htmx correctly (although I might be missing something) - have a look at the proc_htmx source and make sure you understand its purpose and use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback @jph00 , proc_htmx already iterates with a selector and a js function. Changed it , code looks much more compact now.

@jph00
Copy link
Contributor

jph00 commented Oct 15, 2024

JupyUvi doesn't work in the docs unfortunately. So you might just need to use markdown to describe how to use it. Also don't forget to nbdev_export.

@ImtiazKhanDS
Copy link
Contributor Author

JupyUvi doesn't work in the docs unfortunately. So you might just need to use markdown to describe how to use it. Also don't forget to nbdev_export.

JupyUvi doesn't work in the docs unfortunately. So you might just need to use markdown to describe how to use it. Also don't forget to nbdev_export.

Got it , did the changes.

@jph00
Copy link
Contributor

jph00 commented Oct 16, 2024

@ImtiazKhanDS there's no change to the .py file in your PR. I think you forgot to add #| export to the cells you want to export?

@ImtiazKhanDS
Copy link
Contributor Author

@ImtiazKhanDS there's no change to the .py file in your PR. I think you forgot to add #| export to the cells you want to export?

Sorry for the trouble, now added.

@jph00 jph00 added the enhancement New feature or request label Oct 19, 2024
@jph00
Copy link
Contributor

jph00 commented Oct 19, 2024

Good job! :D

@jph00 jph00 merged commit 23c134f into AnswerDotAI:main Oct 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants