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!
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.).
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.
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.
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.
Its quite easy to use.
npm i mermaid
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With