Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 4 compatible with Mermaid js? [closed]

I am looking for diagram Javascript library to create some kind of top level dynamic block diagram for my angular project. Can anyone pls tell me if mermaid is compatible to work with Angular 4? Also pls let me know if there are any other good diagram libraries to work on. Thanks!

like image 890
Vasudev Deshpande Avatar asked Sep 27 '17 19:09

Vasudev Deshpande


People also ask

Are mermaids open source?

MERMAID is free (as in both speech and beer) and its code is open source, and is based on a core set of open-source components, which are themselves based on open and standardized languages and platforms (Python, R, Debian, nginx, gunicorn, JavaScript, etc.).

What is mermaid software?

Mermaid is a flowchart and diagram visualization tool based on JavaScript and uses syntax inspired by Markdown in order to create and dynamically modify flowcharts.

What is Mermaid github?

Mermaid is a Markdown-inspired tool that renders text into diagrams. For example, Mermaid can render flow charts, sequence diagrams, pie charts and more. For more information, see the Mermaid documentation. To create a Mermaid diagram, add Mermaid syntax inside a fenced code block with the mermaid language identifier.

How do you use a mermaid diagram?

Insert a Mermaid diagramClick Arrange > Insert > Advanced > Mermaid. Alternatively, click the + icon in the toolbar, then select Advanced > Mermaid. Paste your text into the text box, then click Insert.


1 Answers

Its quite easy to use.

  1. Add mermaid to your project: npm i mermaid
  2. In the view you want to use mermaid, import mermaid and call the init method

Example:

import { Component, OnInit } from "@angular/core";
import * as mermaid from "mermaid";

@Component({
    selector: "MermaidTest",
    template: `
        <div class="mermaid">
            graph LR
            A-->B
        </div>`
})
export class MermaidTest implements OnInit {    

    public ngOnInit(): void {
        mermaid.initialize({
            theme: "forest"
        });
    }
}

In this case, you have to escape characters like {. If you happen to have the graph content as string anyway, you can use the mermaidAPI instead:

import { AfterContentInit, Component, ViewChild } from "@angular/core";
import * as mermaid from "mermaid";

@Component({
    selector: "MermaidTest",
    template: `<div #mermaid></div>`
})
export class MermaidTest implements AfterContentInit {

    @ViewChild("mermaid")
    public mermaidDiv;

    public ngAfterContentInit(): void {
        mermaid.initialize({
            theme: "dark"
        });

        const element: any = this.mermaidDiv.nativeElement;
        const graphDefinition = "graph TB\na-->b";
        mermaid.render("graphDiv", graphDefinition, (svgCode, bindFunctions) => {
            element.innerHTML = svgCode;
        });
    }
}

For more details see https://mermaidjs.github.io/#/mermaidAPI

like image 142
Maximilian Friedmann Avatar answered Oct 13 '22 03:10

Maximilian Friedmann