diff --git a/playground/index.html b/playground/index.html index 782b30d1..63c6effa 100644 --- a/playground/index.html +++ b/playground/index.html @@ -48,11 +48,17 @@

Custom Test

id="diagram-loading-spinner" width="50" /> -

Flowchart

+

Flowchart Diagrams

Flowchart Examples
+ +

Sequence Diagrams

+
+ Sequence Diagram Examples +
+

Unsupported diagrams

Unsupported Examples diff --git a/playground/index.ts b/playground/index.ts index 407113e8..e95d1fcd 100644 --- a/playground/index.ts +++ b/playground/index.ts @@ -9,28 +9,46 @@ mermaid.initialize({ startOnLoad: false }); import "./initCustomTest"; import { renderExcalidraw } from "./initExcalidraw.js"; +import { SEQUENCE_DIAGRAM_TESTCASES } from "./testcases/sequence.js"; +let indexOffset = 0; (async () => { // Render flowchart diagrams const flowchartContainer = document.getElementById("flowchart-container")!; await Promise.all( - FLOWCHART_DIAGRAM_TESTCASES.map((diagramDefinition, i) => { - return renderDiagram(flowchartContainer, diagramDefinition, i); + FLOWCHART_DIAGRAM_TESTCASES.map((defination, index) => { + const name = `Test ${index + 1}`; + return renderDiagram(flowchartContainer, name, defination, index); }) ); - + indexOffset += FLOWCHART_DIAGRAM_TESTCASES.length; + // Render Sequence diagrams + const sequenceContainer = document.getElementById("sequence-container")!; + await Promise.all( + SEQUENCE_DIAGRAM_TESTCASES.map(({ name, defination }, index) => { + return renderDiagram( + sequenceContainer, + name, + defination, + index + indexOffset + ); + }) + ); + indexOffset += SEQUENCE_DIAGRAM_TESTCASES.length; // Render unsupported diagrams const unsupportedContainer = document.getElementById("unsupported")!; unsupportedContainer.innerHTML = `

Unsupported diagram will be rendered as SVG image.

`; - const indexOffset = FLOWCHART_DIAGRAM_TESTCASES.length; await Promise.all( - UNSUPPORTED_DIAGRAM_TESTCASES.map((diagramDefinition, i) => { + UNSUPPORTED_DIAGRAM_TESTCASES.map((diagramDefinition, index) => { + const name = `Test ${index + 1}`; + return renderDiagram( unsupportedContainer, + name, diagramDefinition, - i + indexOffset + index + indexOffset ); }) ); @@ -41,12 +59,13 @@ import { renderExcalidraw } from "./initExcalidraw.js"; async function renderDiagram( containerEl: HTMLElement, + name: string, diagramDefinition: string, i: number ) { const diagramContainerEl = document.createElement("div"); diagramContainerEl.id = `diagram-container-${i}`; - diagramContainerEl.innerHTML = `

Test #${i + 1} + diagramContainerEl.innerHTML = `

${name}

@@ -64,6 +83,7 @@ async function renderDiagram( btn.addEventListener("click", async () => { const data = btn.getAttribute("data"); const pd = document.getElementById(`parsed-${data}`)!; + console.log(pd.innerHTML, "HEYYY", data); renderExcalidraw(pd.innerHTML); }); diff --git a/src/converter/types/sequence.ts b/src/converter/types/sequence.ts index 6253bf49..544e590e 100644 --- a/src/converter/types/sequence.ts +++ b/src/converter/types/sequence.ts @@ -9,6 +9,7 @@ const EXCALIDRAW_STROKE_STYLE_FOR_ARROW: { [key: string]: StrokeStyle } = { DOTTED: "dotted", SOLID_CROSS: "solid", DOTTED_CROSS: "dotted", + SOLID_OPEN: "solid", DOTTED_OPEN: "dotted", SOLID_POINT: "solid", DOTTED_POINT: "dotted", @@ -17,7 +18,6 @@ export const SequenceToExcalidrawSkeletonConvertor = new GraphConverter({ converter: (chart: Sequence, options: any) => { const elements: ExcalidrawElementSkeleton[] = []; const fontSize = options.fontSize; - console.log(chart, "CHART"); Object.values(chart.nodes).forEach((vertex) => { if (!vertex) { return; @@ -60,6 +60,7 @@ export const SequenceToExcalidrawSkeletonConvertor = new GraphConverter({ return; } const strokeStyle = EXCALIDRAW_STROKE_STYLE_FOR_ARROW[arrow.strokeStyle]; + console.log(arrow.strokeStyle, "HEYYYY"); const arrowElement: ExcalidrawElementSkeleton = { type: "arrow", x: arrow.startX, @@ -72,8 +73,8 @@ export const SequenceToExcalidrawSkeletonConvertor = new GraphConverter({ height: arrow.endY - arrow.startY, strokeStyle, endArrowhead: - strokeStyle === EXCALIDRAW_STROKE_STYLE_FOR_ARROW.SOLID || - strokeStyle === EXCALIDRAW_STROKE_STYLE_FOR_ARROW.DOTTED + arrow.strokeStyle === "SOLID_OPEN" || + arrow.strokeStyle === "DOTTED_OPEN" ? null : "arrow", label: { diff --git a/src/parser/sequence.ts b/src/parser/sequence.ts index 52dbc939..cdb9ab19 100644 --- a/src/parser/sequence.ts +++ b/src/parser/sequence.ts @@ -40,6 +40,7 @@ const SUPPORTED_SEQUENCE_ARROW_TYPES = { 1: "DOTTED", 3: "SOLID_CROSS", 4: "DOTTED_CROSS", + 5: "SOLID_OPEN", 6: "DOTTED_OPEN", 24: "SOLID_POINT", 25: "DOTTED_POINT", @@ -133,6 +134,6 @@ export const parseMermaidSequenceDiagram = ( const { nodes, lines } = parseActor(actorData, containerEl); const messages = mermaidParser.getMessages(); const arrows = parseMessages(messages, containerEl); - console.log("parsing", nodes, actorData.containerEl); + console.log("parsing", mermaidParser.LINETYPE, messages); return { type: "sequence", lines, arrows, nodes }; };