ouhammmourachid / mermaid-py Goto Github PK
View Code? Open in Web Editor NEWPython Interface for the Popular mermaid-js Library, Simplified for Diagram Creation
Home Page: https://mermaidpy.vercel.app
License: MIT License
Python Interface for the Popular mermaid-js Library, Simplified for Diagram Creation
Home Page: https://mermaidpy.vercel.app
License: MIT License
We need to enhance the "mermaid-py" library by updating the supported file format for saving scripts. Currently, it only supports saving scripts as .txt files. The goal is to extend the functionality to support saving scripts in both .mmd and .mermaid formats.
This update will improve user flexibility and allow for more versatile script management within the library. The primary tasks for this update include:
Please note that this change will require updates to the library's core functionality, documentation, and possibly tests to ensure the new file formats work seamlessly. Let's work together to implement this improvement.
to be done:
add documentation for the diagram that allready writen.
list of models:
you should change the type id to be of type str
instead of int
becouse is may be 1.1.1
remove the print statment from the code in this two line of code so that when you create a diagram we don't get any mesage
https://github.com/ouhammmourachid/mermaid-py/blob/main/mermaid/piechart.py#L16
https://github.com/ouhammmourachid/mermaid-py/blob/main/mermaid/piechart.py#L17
here is helpful screen shots
to add the user Joerney diagram refer to the official docs on mermaid user Journey
folow this steps
actor
classs .Task
class.section
class.UserJourny
class.add bgcolor
like this
Background colors
Images are generated with a transparent background by default.
As mermaid diagram with light themes are barely readable on dark backgrounds (and vice-versa), it is possible to force a background color by appending the following query parameter to any /svg or /img URL: ?bgColor=. The color value is interpreted as an hexadecimal color code by default, but you can also use named colors by prefixing the value with !.
Examples:
add >>
operation for fast creation of flow chart diagrams with simple:
>>
for Node .in order to consider this item do you should:
mkdocs
and mkdocstrings[python]
annd mkdocs-material
as dev dependecy.Works flawlessly :-)
add support for the requirement diagram with mermaid-py
use the official mermaid-docs to add the necessary class
Requirement Diagram
here is the steps to folows :
requiremet
class with its propre unittest.element
class with its propre unittest.Link
classs with its propre unittest.RequirementDigram
class with its propre unittest.Whenever creating an instance of a flowchart Node
, the id provided by the user is forced to be snake case, which this can prevent many issues, but some others may arise. For example, I'm trying to make a tree, which has some constraints that the variables must satisfy. This is the desired output:
---
title: Constraint Satisfaction Problem
---
flowchart TB
.F_(("F"))
.F_0.x3_(("x3"))
valid("Valid State")
.F_0.x3.err_-1754910954858582633("Constraint failed: F == x3")
.F_(("F"))
.F_1.x3_(("x3"))
.F_1.x3.err_-1754910954858582633("Constraint failed: F == x3")
valid("Valid State")
.F_1.x3_ -->|3| .F_1.x3.err_-1754910954858582633
.F_1.x3_ -->|2| .F_1.x3.err_-1754910954858582633
.F_1.x3_ -->|1| valid
.F_1.x3_ -->|0| .F_1.x3.err_-1754910954858582633
.F_ -->|1| .F_1.x3_
.F_0.x3_ -->|3| .F_0.x3.err_-1754910954858582633
.F_0.x3_ -->|2| .F_0.x3.err_-1754910954858582633
.F_0.x3_ -->|1| .F_0.x3.err_-1754910954858582633
.F_0.x3_ -->|0| valid
.F_ -->|0| .F_0.x3_
Here's a link to the mermaid live editor which contains the previous code. This is the generated diagram from the previous code, as you can see we can make us of dots (.
) and dashes (-
) in the node identifiers.
But instead I get this by using the library:
---
title: Constraint Satisfaction Problem
---
flowchart TB
_f_(("F"))
_f_0_x3_(("x3"))
valid("Valid State")
_f_0_x3_err__1754910954858582633("Constraint failed: F == x3")
_f_(("F"))
_f_1_x3_(("x3"))
_f_1_x3_err__1754910954858582633("Constraint failed: F == x3")
valid("Valid State")
_f_1_x3_ -->|3| _f_1_x3_err__1754910954858582633
_f_1_x3_ -->|2| _f_1_x3_err__1754910954858582633
_f_1_x3_ -->|1| valid
_f_1_x3_ -->|0| _f_1_x3_err__1754910954858582633
_f_ -->|1| _f_1_x3_
_f_0_x3_ -->|3| _f_0_x3_err__1754910954858582633
_f_0_x3_ -->|2| _f_0_x3_err__1754910954858582633
_f_0_x3_ -->|1| _f_0_x3_err__1754910954858582633
_f_0_x3_ -->|0| valid
_f_ -->|0| _f_0_x3_
So, I need to preserve the dots because of how I'm traversing the search space, the dots (.
) allow me to detect how deep in the tree I am and the underscores (_
) allow me to know the value of the branch itself which I'm currently on, but I lose all of that information because of the resulting code:
mermaid-py/mermaid/flowchart/node.py
Line 75 in 9914ed1
One way could be creating an optional boolean argument for the constructor (this way could be backwards compatible which is much preferred), or another is to modify the regex to allow dots (.
) and dashes (-
). This regex is found here:
Lines 44 to 45 in 9914ed1
This regex could be modified to allow .
and -
, like so:
# Remove non-alphanumeric characters except underscores, dots and dashes and replace everything else with underscores
out: str = re.sub(r'[^a-zA-Z0-9_\.-]', '_', text)
I could open a PR, by allowing users to opt-out from the conversion made by text_to_snake_case
in the constructor Node
, just so the user can override this behavior (at their own risk). Or just modify the regular expression, this wouldn't be backwards compatible, but it'd work too.
Let me know what you think and what would work best for this project, I fixed it locally, but still, I think this could improve the usability of this library. Thank you for creating this library, it has helped me a lot!
Hope to hear back from you @ouhammmourachid ๐
change the workflow for bumping version using bumpversion
library :
If it is possible to use commitizen
to bumpversion .
add style to support the diagrams in mermaid-py.
fill
and stroke
to flowchart
.fill
and stroke
to erDiagram
.A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.