GithubHelp home page GithubHelp logo

ouhammmourachid / mermaid-py Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 3.0 1.38 MB

Python Interface for the Popular mermaid-js Library, Simplified for Diagram Creation

Home Page: https://mermaidpy.vercel.app

License: MIT License

Python 99.60% Makefile 0.40%
mermaid-diagrams open-source poetry pypi-package python3

mermaid-py's Issues

Update supported file format for script saving to `.mmd` or `.mermaid`

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:

  • Enabling the library to save scripts in .mmd format.
  • Enabling the library to save scripts in .mermaid format.

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:

  • Update the library to support saving scripts in .mmd format.
  • Update the library to support saving scripts in .mermaid format.
  • Update the documentation to reflect the new supported file formats.
  • Add tests to ensure the new file formats work correctly.
  • Update any relevant examples or usage instructions.

add `bgcolor` attribute to the Mermaid 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 a red background using hexadecimal color: ?bgColor=FF0000
  • Add a white background using named color: ?bgColor=!white

managinng documentation using `mkdocs` .

in order to consider this item do you should:

  • add mkdocs and mkdocstrings[python] annd mkdocs-material as dev dependecy.
  • create the started for the docs .
  • chnage the name .
  • generate html in the site folder .
  • using Github pages deploy the docs .

add `pie` diagram .

add the pie digram to list of supported digrams:

  • add piechart diagram.
  • add unit test for this diagram.
  • create a new realease.

use this a refrence

Image

add support of `requirements diagram` to mermaid-py.

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 :

  • add requiremet class with its propre unittest.
  • add element class with its propre unittest.
  • add Link classs with its propre unittest.
  • add RequirementDigram class with its propre unittest.

Allow `text_to_snake_case` to be opt-out on `id_` creation

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:

self.id_: str = text_to_snake_case(id_)

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:

# Remove non-alphanumeric characters except underscores and replace spaces with underscores
out: str = re.sub(r'[^a-zA-Z0-9_]', '_', text)

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 ๐Ÿ˜„

add support for style and `style classes`

add style to support the diagrams in mermaid-py.

  • add style fill and stroke to flowchart.
  • add style fill and stroke to erDiagram.
  • add the ability to create style classes and use them on different diagrams.
  • add a predefined style class ready to be used.
  • add the theme support dark light.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.