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

Request validation & custom diagram config #2

Merged
merged 10 commits into from
Apr 11, 2024
Merged

Conversation

coma007
Copy link
Owner

@coma007 coma007 commented Apr 9, 2024

I added custom configuration of diagram which can be added as additional parameter by calling MermaidScope.transform function or in constructor of MermaidScope.

Also, this time request is verified with parse function from repos\kaleido\js\parse.js.


I encountered following problems that I may resolve in some future PRs:

  • Handling different versions of Mermaid API: I am not sure how can I extract the current version from the mermaid object, which makes limitations in implementing different render flow for different versions.
  • Adding different image formats: For now, svg is supported only. While trying to add other image formats, unexpected behavior happened during conversions using this code (probably because the script is run in headless mode, so the image never loads):
function convertSVGToImageBytes(svg, format = 'image/png') {
    return new Promise((resolve, reject) => {
       
        const image = document.createElement("img")
        image.onload = () => {
            const canvas = document.createElement('canvas');
            canvas.width = image.width;
            canvas.height = image.height;
            const ctx = canvas.getContext('2d');
            ctx.drawImage(image, 0, 0);
            const imageData = canvas.toDataURL(format);
            resolve(imageData);
      };
     
      image.onerror = (e) => reject(e);
     
      image.src = 'data:image/svg+xml;base64,' + btoa(svg);
    });
  }

@coma007 coma007 added the enhancement New feature or request label Apr 9, 2024
@coma007 coma007 self-assigned this Apr 9, 2024
repos/kaleido/js/src/mermaid/constants.js Outdated Show resolved Hide resolved
repos/kaleido/js/src/mermaid/parse.js Outdated Show resolved Hide resolved
repos/kaleido/js/src/mermaid/has-all-propperties.js Outdated Show resolved Hide resolved
repos/kaleido/py/kaleido/scopes/mermaid.py Outdated Show resolved Hide resolved
repos/kaleido/js/src/mermaid/is-positive-numeric.js Outdated Show resolved Hide resolved
@coma007 coma007 requested a review from mandic-bojana April 10, 2024 16:17
@coma007 coma007 changed the title Request Validation & Custom Diagram Config Request validation & custom diagram config Apr 10, 2024
Copy link

@mandic-bojana mandic-bojana left a comment

Choose a reason for hiding this comment

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

Left only one comment :)

repos/kaleido/py/kaleido/scopes/mermaid.py Outdated Show resolved Hide resolved
@coma007 coma007 merged commit 15aaa67 into dev Apr 11, 2024
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.

2 participants