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

Size issues on large diagrams #12

Open
johankson opened this issue Apr 12, 2022 · 0 comments
Open

Size issues on large diagrams #12

johankson opened this issue Apr 12, 2022 · 0 comments

Comments

@johankson
Copy link

I created a quick and dirty fix for setting the height to 100% (instead of the calculated height).
The issue was that large diagrams got a large height set to a specific number that made the rendering of the element to be pushed down a lot.

Did it on server side, but it could easily be moved to javascript if needed.

I reused my earlier hack :) with the SVG hook and simply applied a regex to replace the calculated height with 100%.

The questions are:

  • Do you know of a better way to do this?
  • If not, should it be imported somehow into the component or handled in a different way?

And since I suck at naming things, the attribute name is quite large. :)

<MermaidDiagram Definition="@diagramDefinition" 
                          SvgTransform="SvgTransform" 
                          OnClick="Click"
                          ForceHeightTo100Percent="true"/>

And the naive, hacky implementation.

[JSInvokable]
public async Task<string> OnSvgCreated(string svg)
{
    if (ForceHeightTo100Percent)
    {
        var regex = new Regex("<svg[^>]*?height=([\"\'])?((?:.(?!\\1|>))*.?)\\1?");
        var match = regex.Match(svg);
        var g = match.Groups[2];
        svg = svg.Substring(0, g.Index) + "100%" + svg.Substring(g.Index + g.Length);
    }

    if (SvgTransform != null)
    {
       
        
        svg = SvgTransform(svg);
    }

    return svg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant