mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-23 02:06:45 +02:00
Compare commits
24 Commits
2139-handl
...
v10.3.1
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a0b80f5490 | ||
![]() |
493023118f | ||
![]() |
c5e7e6040c | ||
![]() |
c938c7a438 | ||
![]() |
c7bcf72c69 | ||
![]() |
da602add5d | ||
![]() |
9049a99c8d | ||
![]() |
60957519c8 | ||
![]() |
9b9ad1da7d | ||
![]() |
0d380bb2c7 | ||
![]() |
9ab048c7e9 | ||
![]() |
1078b1c8f6 | ||
![]() |
980a5ac8b5 | ||
![]() |
46de343785 | ||
![]() |
66b579cd89 | ||
![]() |
0b9f6d1ff9 | ||
![]() |
7742a6c485 | ||
![]() |
da8112afa5 | ||
![]() |
bae9a7c1b8 | ||
![]() |
776b219c03 | ||
![]() |
4471001ef2 | ||
![]() |
646f7662d0 | ||
![]() |
95efc1786f | ||
![]() |
10d5b5d1d6 |
@@ -449,7 +449,7 @@ flowchart TD
|
|||||||
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('65: text-color from classes', () => {
|
it('65-1: text-color from classes', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
flowchart LR
|
flowchart LR
|
||||||
@@ -460,6 +460,31 @@ flowchart TD
|
|||||||
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('65-2: bold text from classes', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
flowchart
|
||||||
|
classDef cat fill:#f9d5e5, stroke:#233d4d,stroke-width:2px, font-weight:bold;
|
||||||
|
CS(A long bold text to be viewed):::cat
|
||||||
|
`,
|
||||||
|
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('65-3: bigger font from classes', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`
|
||||||
|
flowchart
|
||||||
|
Node1:::class1 --> Node2:::class2
|
||||||
|
Node1:::class1 --> Node3:::class2
|
||||||
|
Node3 --> Node4((I am a circle)):::larger
|
||||||
|
|
||||||
|
classDef class1 fill:lightblue
|
||||||
|
classDef class2 fill:pink
|
||||||
|
classDef larger font-size:30px,fill:yellow
|
||||||
|
`,
|
||||||
|
{ htmlLabels: true, flowchart: { htmlLabels: true }, securityLevel: 'loose' }
|
||||||
|
);
|
||||||
|
});
|
||||||
it('66: More nested subgraph cases (TB)', () => {
|
it('66: More nested subgraph cases (TB)', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`
|
`
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#### Grammar
|
#### Grammar
|
||||||
|
|
||||||
This would be to define a jison grammar for the new diagram type. That should start with a way to identify that the text in the mermaid tag is a diagram of that type. Create a new folder under diagrams for your new diagram type and a parser folder in it. This leads us to step 2.
|
This would be to define a JISON grammar for the new diagram type. That should start with a way to identify that the text in the mermaid tag is a diagram of that type. Create a new folder under diagrams for your new diagram type and a parser folder in it. This leads us to step 2.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ Place the renderer in the diagram folder.
|
|||||||
|
|
||||||
### Step 3: Detection of the new diagram type
|
### Step 3: Detection of the new diagram type
|
||||||
|
|
||||||
The second thing to do is to add the capability to detect the new diagram to type to the detectType in utils.js. The detection should return a key for the new diagram type.
|
The second thing to do is to add the capability to detect the new diagram to type to the detectType in `diagram-api/detectType.ts`. The detection should return a key for the new diagram type.
|
||||||
[This key will be used to as the aria roledescription](#aria-roledescription), so it should be a word that clearly describes the diagram type.
|
[This key will be used to as the aria roledescription](#aria-roledescription), so it should be a word that clearly describes the diagram type.
|
||||||
For example, if your new diagram use a UML deployment diagram, a good key would be "UMLDeploymentDiagram" because assistive technologies such as a screen reader
|
For example, if your new diagram use a UML deployment diagram, a good key would be "UMLDeploymentDiagram" because assistive technologies such as a screen reader
|
||||||
would voice that as "U-M-L Deployment diagram." Another good key would be "deploymentDiagram" because that would be voiced as "Deployment Diagram." A bad key would be "deployment" because that would not sufficiently describe the diagram.
|
would voice that as "U-M-L Deployment diagram." Another good key would be "deploymentDiagram" because that would be voiced as "Deployment Diagram." A bad key would be "deployment" because that would not sufficiently describe the diagram.
|
||||||
|
@@ -96,7 +96,7 @@ mermaid.initialize(config);
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:669](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L669)
|
[mermaidAPI.ts:668](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L668)
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ Return the last node appended
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:310](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L310)
|
[mermaidAPI.ts:309](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L309)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -153,7 +153,7 @@ the cleaned up svgCode
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:256](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L256)
|
[mermaidAPI.ts:255](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L255)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ the string with all the user styles
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:185](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L185)
|
[mermaidAPI.ts:184](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L184)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ the string with all the user styles
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:233](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L233)
|
[mermaidAPI.ts:232](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L232)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:169](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L169)
|
[mermaidAPI.ts:168](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L168)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:155](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L155)
|
[mermaidAPI.ts:154](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L154)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ with an enclosing block that has each of the cssClasses followed by !important;
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:126](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L126)
|
[mermaidAPI.ts:125](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L125)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -295,7 +295,7 @@ Put the svgCode into an iFrame. Return the iFrame code
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:287](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L287)
|
[mermaidAPI.ts:286](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L286)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -320,4 +320,4 @@ Remove any existing elements from the given document
|
|||||||
|
|
||||||
#### Defined in
|
#### Defined in
|
||||||
|
|
||||||
[mermaidAPI.ts:360](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L360)
|
[mermaidAPI.ts:359](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L359)
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mermaid",
|
"name": "mermaid",
|
||||||
"version": "10.3.0",
|
"version": "10.3.1",
|
||||||
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdown-ish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"module": "./dist/mermaid.core.mjs",
|
"module": "./dist/mermaid.core.mjs",
|
||||||
|
@@ -18,6 +18,7 @@ import { promisify } from 'node:util';
|
|||||||
|
|
||||||
import { load, JSON_SCHEMA } from 'js-yaml';
|
import { load, JSON_SCHEMA } from 'js-yaml';
|
||||||
import { compile, type JSONSchema } from 'json-schema-to-typescript';
|
import { compile, type JSONSchema } from 'json-schema-to-typescript';
|
||||||
|
import prettier from 'prettier';
|
||||||
|
|
||||||
import _Ajv2019, { type JSONSchemaType } from 'ajv/dist/2019.js';
|
import _Ajv2019, { type JSONSchemaType } from 'ajv/dist/2019.js';
|
||||||
|
|
||||||
@@ -207,6 +208,7 @@ async function generateTypescript(mermaidConfigSchema: JSONSchemaType<MermaidCon
|
|||||||
{
|
{
|
||||||
additionalProperties: false, // in JSON Schema 2019-09, these are called `unevaluatedProperties`
|
additionalProperties: false, // in JSON Schema 2019-09, these are called `unevaluatedProperties`
|
||||||
unreachableDefinitions: true, // definition for FontConfig is unreachable
|
unreachableDefinitions: true, // definition for FontConfig is unreachable
|
||||||
|
style: (await prettier.resolveConfig('.')) ?? {},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@@ -4,8 +4,9 @@ import { getDiagram, registerDiagram } from './diagram-api/diagramAPI.js';
|
|||||||
import { detectType, getDiagramLoader } from './diagram-api/detectType.js';
|
import { detectType, getDiagramLoader } from './diagram-api/detectType.js';
|
||||||
import { extractFrontMatter } from './diagram-api/frontmatter.js';
|
import { extractFrontMatter } from './diagram-api/frontmatter.js';
|
||||||
import { UnknownDiagramError } from './errors.js';
|
import { UnknownDiagramError } from './errors.js';
|
||||||
import { DetailedError } from './utils.js';
|
|
||||||
import { cleanupComments } from './diagram-api/comments.js';
|
import { cleanupComments } from './diagram-api/comments.js';
|
||||||
|
import type { DetailedError } from './utils.js';
|
||||||
|
import type { DiagramDefinition } from './diagram-api/types.js';
|
||||||
|
|
||||||
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
|
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
|
||||||
|
|
||||||
@@ -15,9 +16,11 @@ export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?:
|
|||||||
*/
|
*/
|
||||||
export class Diagram {
|
export class Diagram {
|
||||||
type = 'graph';
|
type = 'graph';
|
||||||
parser;
|
parser: DiagramDefinition['parser'];
|
||||||
renderer;
|
renderer: DiagramDefinition['renderer'];
|
||||||
db;
|
db: DiagramDefinition['db'];
|
||||||
|
private init?: DiagramDefinition['init'];
|
||||||
|
|
||||||
private detectError?: UnknownDiagramError;
|
private detectError?: UnknownDiagramError;
|
||||||
constructor(public text: string) {
|
constructor(public text: string) {
|
||||||
this.text += '\n';
|
this.text += '\n';
|
||||||
@@ -32,7 +35,6 @@ export class Diagram {
|
|||||||
log.debug('Type ' + this.type);
|
log.debug('Type ' + this.type);
|
||||||
// Setup diagram
|
// Setup diagram
|
||||||
this.db = diagram.db;
|
this.db = diagram.db;
|
||||||
this.db.clear?.();
|
|
||||||
this.renderer = diagram.renderer;
|
this.renderer = diagram.renderer;
|
||||||
this.parser = diagram.parser;
|
this.parser = diagram.parser;
|
||||||
const originalParse = this.parser.parse.bind(this.parser);
|
const originalParse = this.parser.parse.bind(this.parser);
|
||||||
@@ -49,10 +51,7 @@ export class Diagram {
|
|||||||
originalParse(cleanupComments(extractFrontMatter(text, this.db)));
|
originalParse(cleanupComments(extractFrontMatter(text, this.db)));
|
||||||
|
|
||||||
this.parser.parser.yy = this.db;
|
this.parser.parser.yy = this.db;
|
||||||
if (diagram.init) {
|
this.init = diagram.init;
|
||||||
diagram.init(cnf);
|
|
||||||
log.info('Initialized diagram ' + this.type, cnf);
|
|
||||||
}
|
|
||||||
this.parse();
|
this.parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +60,7 @@ export class Diagram {
|
|||||||
throw this.detectError;
|
throw this.detectError;
|
||||||
}
|
}
|
||||||
this.db.clear?.();
|
this.db.clear?.();
|
||||||
|
this.init?.(configApi.getConfig());
|
||||||
this.parser.parse(this.text);
|
this.parser.parse(this.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
/**
|
/**
|
||||||
* Configuration options to pass to the `dompurify` library.
|
* Configuration options to pass to the `dompurify` library.
|
||||||
*/
|
*/
|
||||||
export type DOMPurifyConfiguration = import("dompurify").Config;
|
export type DOMPurifyConfiguration = import('dompurify').Config;
|
||||||
/**
|
/**
|
||||||
* JavaScript function that returns a `FontConfig`.
|
* JavaScript function that returns a `FontConfig`.
|
||||||
*
|
*
|
||||||
@@ -39,7 +39,7 @@ export type FontCalculator = () => Partial<FontConfig>;
|
|||||||
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
||||||
* via the `definition` "SankeyLinkColor".
|
* via the `definition` "SankeyLinkColor".
|
||||||
*/
|
*/
|
||||||
export type SankeyLinkColor = "source" | "target" | "gradient";
|
export type SankeyLinkColor = 'source' | 'target' | 'gradient';
|
||||||
/**
|
/**
|
||||||
* Controls the alignment of the Sankey diagrams.
|
* Controls the alignment of the Sankey diagrams.
|
||||||
*
|
*
|
||||||
@@ -49,7 +49,7 @@ export type SankeyLinkColor = "source" | "target" | "gradient";
|
|||||||
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
||||||
* via the `definition` "SankeyNodeAlignment".
|
* via the `definition` "SankeyNodeAlignment".
|
||||||
*/
|
*/
|
||||||
export type SankeyNodeAlignment = "left" | "right" | "center" | "justify";
|
export type SankeyNodeAlignment = 'left' | 'right' | 'center' | 'justify';
|
||||||
/**
|
/**
|
||||||
* The font size to use
|
* The font size to use
|
||||||
*/
|
*/
|
||||||
@@ -61,7 +61,7 @@ export interface MermaidConfig {
|
|||||||
* You may also use `themeCSS` to override this value.
|
* You may also use `themeCSS` to override this value.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
theme?: string | "default" | "forest" | "dark" | "neutral" | "null";
|
theme?: string | 'default' | 'forest' | 'dark' | 'neutral' | 'null';
|
||||||
themeVariables?: any;
|
themeVariables?: any;
|
||||||
themeCSS?: string;
|
themeCSS?: string;
|
||||||
/**
|
/**
|
||||||
@@ -88,12 +88,12 @@ export interface MermaidConfig {
|
|||||||
| 0
|
| 0
|
||||||
| 2
|
| 2
|
||||||
| 1
|
| 1
|
||||||
| "trace"
|
| 'trace'
|
||||||
| "debug"
|
| 'debug'
|
||||||
| "info"
|
| 'info'
|
||||||
| "warn"
|
| 'warn'
|
||||||
| "error"
|
| 'error'
|
||||||
| "fatal"
|
| 'fatal'
|
||||||
| 3
|
| 3
|
||||||
| 4
|
| 4
|
||||||
| 5
|
| 5
|
||||||
@@ -101,7 +101,7 @@ export interface MermaidConfig {
|
|||||||
/**
|
/**
|
||||||
* Level of trust for parsed diagram
|
* Level of trust for parsed diagram
|
||||||
*/
|
*/
|
||||||
securityLevel?: string | "strict" | "loose" | "antiscript" | "sandbox" | undefined;
|
securityLevel?: string | 'strict' | 'loose' | 'antiscript' | 'sandbox' | undefined;
|
||||||
/**
|
/**
|
||||||
* Dictates whether mermaid starts on Page load
|
* Dictates whether mermaid starts on Page load
|
||||||
*/
|
*/
|
||||||
@@ -689,11 +689,11 @@ export interface QuadrantChartConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* position of x-axis labels
|
* position of x-axis labels
|
||||||
*/
|
*/
|
||||||
xAxisPosition?: "top" | "bottom";
|
xAxisPosition?: 'top' | 'bottom';
|
||||||
/**
|
/**
|
||||||
* position of y-axis labels
|
* position of y-axis labels
|
||||||
*/
|
*/
|
||||||
yAxisPosition?: "left" | "right";
|
yAxisPosition?: 'left' | 'right';
|
||||||
/**
|
/**
|
||||||
* stroke width of edges of the box that are inside the quadrant
|
* stroke width of edges of the box that are inside the quadrant
|
||||||
*/
|
*/
|
||||||
@@ -723,7 +723,7 @@ export interface ErDiagramConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* Directional bias for layout of entities
|
* Directional bias for layout of entities
|
||||||
*/
|
*/
|
||||||
layoutDirection?: string | "TB" | "BT" | "LR" | "RL";
|
layoutDirection?: string | 'TB' | 'BT' | 'LR' | 'RL';
|
||||||
/**
|
/**
|
||||||
* The minimum width of an entity box. Expressed in pixels.
|
* The minimum width of an entity box. Expressed in pixels.
|
||||||
*/
|
*/
|
||||||
@@ -788,7 +788,7 @@ export interface StateDiagramConfig extends BaseDiagramConfig {
|
|||||||
* Decides which rendering engine that is to be used for the rendering.
|
* Decides which rendering engine that is to be used for the rendering.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
defaultRenderer?: string | "dagre-d3" | "dagre-wrapper" | "elk";
|
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
* This interface was referenced by `MermaidConfig`'s JSON-Schema
|
||||||
@@ -812,7 +812,7 @@ export interface ClassDiagramConfig extends BaseDiagramConfig {
|
|||||||
* Decides which rendering engine that is to be used for the rendering.
|
* Decides which rendering engine that is to be used for the rendering.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
defaultRenderer?: string | "dagre-d3" | "dagre-wrapper" | "elk";
|
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
|
||||||
nodeSpacing?: number;
|
nodeSpacing?: number;
|
||||||
rankSpacing?: number;
|
rankSpacing?: number;
|
||||||
/**
|
/**
|
||||||
@@ -872,7 +872,7 @@ export interface JourneyDiagramConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* Multiline message alignment
|
* Multiline message alignment
|
||||||
*/
|
*/
|
||||||
messageAlign?: string | "left" | "center" | "right";
|
messageAlign?: string | 'left' | 'center' | 'right';
|
||||||
/**
|
/**
|
||||||
* Prolongs the edge of the diagram downwards.
|
* Prolongs the edge of the diagram downwards.
|
||||||
*
|
*
|
||||||
@@ -951,7 +951,7 @@ export interface TimelineDiagramConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* Multiline message alignment
|
* Multiline message alignment
|
||||||
*/
|
*/
|
||||||
messageAlign?: string | "left" | "center" | "right";
|
messageAlign?: string | 'left' | 'center' | 'right';
|
||||||
/**
|
/**
|
||||||
* Prolongs the edge of the diagram downwards.
|
* Prolongs the edge of the diagram downwards.
|
||||||
*
|
*
|
||||||
@@ -1062,12 +1062,12 @@ export interface GanttDiagramConfig extends BaseDiagramConfig {
|
|||||||
* Controls the display mode.
|
* Controls the display mode.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
displayMode?: string | "compact";
|
displayMode?: string | 'compact';
|
||||||
/**
|
/**
|
||||||
* On which day a week-based interval should start
|
* On which day a week-based interval should start
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
weekday?: "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday" | "sunday";
|
weekday?: 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday' | 'sunday';
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* The object containing configurations specific for sequence diagrams
|
* The object containing configurations specific for sequence diagrams
|
||||||
@@ -1121,7 +1121,7 @@ export interface SequenceDiagramConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* Multiline message alignment
|
* Multiline message alignment
|
||||||
*/
|
*/
|
||||||
messageAlign?: string | "left" | "center" | "right";
|
messageAlign?: string | 'left' | 'center' | 'right';
|
||||||
/**
|
/**
|
||||||
* Mirror actors under diagram
|
* Mirror actors under diagram
|
||||||
*
|
*
|
||||||
@@ -1178,7 +1178,7 @@ export interface SequenceDiagramConfig extends BaseDiagramConfig {
|
|||||||
/**
|
/**
|
||||||
* This sets the text alignment of actor-attached notes
|
* This sets the text alignment of actor-attached notes
|
||||||
*/
|
*/
|
||||||
noteAlign?: string | "left" | "center" | "right";
|
noteAlign?: string | 'left' | 'center' | 'right';
|
||||||
/**
|
/**
|
||||||
* This sets the font size of actor messages
|
* This sets the font size of actor messages
|
||||||
*/
|
*/
|
||||||
@@ -1254,7 +1254,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
|
|||||||
* Defines how mermaid renders curves for flowcharts.
|
* Defines how mermaid renders curves for flowcharts.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
curve?: string | "basis" | "linear" | "cardinal";
|
curve?: string | 'basis' | 'linear' | 'cardinal';
|
||||||
/**
|
/**
|
||||||
* Represents the padding between the labels and the shape
|
* Represents the padding between the labels and the shape
|
||||||
*
|
*
|
||||||
@@ -1266,7 +1266,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
|
|||||||
* Decides which rendering engine that is to be used for the rendering.
|
* Decides which rendering engine that is to be used for the rendering.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
defaultRenderer?: string | "dagre-d3" | "dagre-wrapper" | "elk";
|
defaultRenderer?: string | 'dagre-d3' | 'dagre-wrapper' | 'elk';
|
||||||
/**
|
/**
|
||||||
* Width of nodes where text is wrapped.
|
* Width of nodes where text is wrapped.
|
||||||
*
|
*
|
||||||
@@ -1296,7 +1296,7 @@ export interface SankeyDiagramConfig extends BaseDiagramConfig {
|
|||||||
* See <https://github.com/d3/d3-sankey#alignments>.
|
* See <https://github.com/d3/d3-sankey#alignments>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
nodeAlignment?: "left" | "right" | "center" | "justify";
|
nodeAlignment?: 'left' | 'right' | 'center' | 'justify';
|
||||||
useMaxWidth?: boolean;
|
useMaxWidth?: boolean;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@@ -35,7 +35,12 @@ describe('DiagramAPI', () => {
|
|||||||
'loki',
|
'loki',
|
||||||
{
|
{
|
||||||
db: {},
|
db: {},
|
||||||
parser: {},
|
parser: {
|
||||||
|
parse: (_text) => {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
parser: { yy: {} },
|
||||||
|
},
|
||||||
renderer: {},
|
renderer: {},
|
||||||
styles: {},
|
styles: {},
|
||||||
},
|
},
|
||||||
|
@@ -69,11 +69,11 @@ export const getDiagram = (name: string): DiagramDefinition => {
|
|||||||
if (name in diagrams) {
|
if (name in diagrams) {
|
||||||
return diagrams[name];
|
return diagrams[name];
|
||||||
}
|
}
|
||||||
throw new Error(`Diagram ${name} not found.`);
|
throw new DiagramNotFoundError(name);
|
||||||
};
|
};
|
||||||
|
|
||||||
export class DiagramNotFoundError extends Error {
|
export class DiagramNotFoundError extends Error {
|
||||||
constructor(message: string) {
|
constructor(name: string) {
|
||||||
super(`Diagram ${message} not found.`);
|
super(`Diagram ${name} not found.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { Diagram } from '../Diagram.js';
|
import { Diagram } from '../Diagram.js';
|
||||||
import { MermaidConfig } from '../config.type.js';
|
import type { MermaidConfig } from '../config.type.js';
|
||||||
import type * as d3 from 'd3';
|
import type * as d3 from 'd3';
|
||||||
|
|
||||||
export interface InjectUtils {
|
export interface InjectUtils {
|
||||||
@@ -27,7 +27,7 @@ export interface DiagramDB {
|
|||||||
export interface DiagramDefinition {
|
export interface DiagramDefinition {
|
||||||
db: DiagramDB;
|
db: DiagramDB;
|
||||||
renderer: any;
|
renderer: any;
|
||||||
parser: any;
|
parser: ParserDefinition;
|
||||||
styles?: any;
|
styles?: any;
|
||||||
init?: (config: MermaidConfig) => void;
|
init?: (config: MermaidConfig) => void;
|
||||||
injectUtils?: (
|
injectUtils?: (
|
||||||
@@ -70,6 +70,11 @@ export type DrawDefinition = (
|
|||||||
diagramObject: Diagram
|
diagramObject: Diagram
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
|
export interface ParserDefinition {
|
||||||
|
parse: (text: string) => void;
|
||||||
|
parser: { yy: DiagramDB };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type for function parse directive from diagram code.
|
* Type for function parse directive from diagram code.
|
||||||
*
|
*
|
||||||
|
@@ -555,7 +555,6 @@ const drawRelationshipFromLayout = function (svg, rel, g, insert, diagObj) {
|
|||||||
export const draw = function (text, id, _version, diagObj) {
|
export const draw = function (text, id, _version, diagObj) {
|
||||||
conf = getConfig().er;
|
conf = getConfig().er;
|
||||||
log.info('Drawing ER diagram');
|
log.info('Drawing ER diagram');
|
||||||
// diag.db.clear();
|
|
||||||
const securityLevel = getConfig().securityLevel;
|
const securityLevel = getConfig().securityLevel;
|
||||||
// Handle root and Document for when rendering in sandbox mode
|
// Handle root and Document for when rendering in sandbox mode
|
||||||
let sandboxElement;
|
let sandboxElement;
|
||||||
|
@@ -1,23 +1,15 @@
|
|||||||
import { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
import styles from './styles.js';
|
import { renderer } from './errorRenderer.js';
|
||||||
import renderer from './errorRenderer.js';
|
|
||||||
export const diagram: DiagramDefinition = {
|
const diagram: DiagramDefinition = {
|
||||||
db: {
|
db: {},
|
||||||
clear: () => {
|
|
||||||
// Quite ok, clear needs to be there for error to work as a regular diagram
|
|
||||||
},
|
|
||||||
},
|
|
||||||
styles,
|
|
||||||
renderer,
|
renderer,
|
||||||
parser: {
|
parser: {
|
||||||
parser: { yy: {} },
|
parser: { yy: {} },
|
||||||
parse: () => {
|
parse: (): void => {
|
||||||
// no op
|
return;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
init: () => {
|
|
||||||
// no op
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default diagram;
|
export default diagram;
|
||||||
|
@@ -1,33 +1,23 @@
|
|||||||
/** Created by knut on 14-12-11. */
|
|
||||||
// @ts-ignore TODO: Investigate D3 issue
|
|
||||||
import { select } from 'd3';
|
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
import { getErrorMessage } from '../../utils.js';
|
import type { Group, SVG } from '../../diagram-api/types.js';
|
||||||
|
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||||
/**
|
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
||||||
* Merges the value of `conf` with the passed `cnf`
|
|
||||||
*
|
|
||||||
* @param cnf - Config to merge
|
|
||||||
*/
|
|
||||||
export const setConf = function () {
|
|
||||||
// no-op
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a an info picture in the tag with id: id based on the graph definition in text.
|
* Draws a an info picture in the tag with id: id based on the graph definition in text.
|
||||||
*
|
*
|
||||||
* @param _text - Mermaid graph definition.
|
* @param _text - Mermaid graph definition.
|
||||||
* @param id - The text for the error
|
* @param id - The text for the error
|
||||||
* @param mermaidVersion - The version
|
* @param version - The version
|
||||||
*/
|
*/
|
||||||
export const draw = (_text: string, id: string, mermaidVersion: string) => {
|
export const draw = (_text: string, id: string, version: string) => {
|
||||||
try {
|
log.debug('renering svg for syntax error\n');
|
||||||
log.debug('Renering svg for syntax error\n');
|
|
||||||
|
|
||||||
const svg = select('#' + id);
|
const svg: SVG = selectSvgElement(id);
|
||||||
|
svg.attr('viewBox', '0 0 2412 512');
|
||||||
const g = svg.append('g');
|
configureSvgSize(svg, 100, 512, true);
|
||||||
|
|
||||||
|
const g: Group = svg.append('g');
|
||||||
g.append('path')
|
g.append('path')
|
||||||
.attr('class', 'error-icon')
|
.attr('class', 'error-icon')
|
||||||
.attr(
|
.attr(
|
||||||
@@ -83,18 +73,9 @@ export const draw = (_text: string, id: string, mermaidVersion: string) => {
|
|||||||
.attr('y', 400)
|
.attr('y', 400)
|
||||||
.attr('font-size', '100px')
|
.attr('font-size', '100px')
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.text('mermaid version ' + mermaidVersion);
|
.text(`mermaid version ${version}`);
|
||||||
|
|
||||||
svg.attr('height', 100);
|
|
||||||
svg.attr('width', 500);
|
|
||||||
svg.attr('viewBox', '768 0 912 512');
|
|
||||||
} catch (e) {
|
|
||||||
log.error('Error while rendering info diagram');
|
|
||||||
log.error(getErrorMessage(e));
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export const renderer = { draw };
|
||||||
setConf,
|
|
||||||
draw,
|
export default renderer;
|
||||||
};
|
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
const getStyles = () => ``;
|
|
||||||
|
|
||||||
export default getStyles;
|
|
@@ -655,14 +655,7 @@ const addMarkersToEdge = function (svgPath, edgeData, diagramType, arrowMarkerAb
|
|||||||
*/
|
*/
|
||||||
export const getClasses = function (text, diagObj) {
|
export const getClasses = function (text, diagObj) {
|
||||||
log.info('Extracting classes');
|
log.info('Extracting classes');
|
||||||
diagObj.db.clear('ver-2');
|
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
return diagObj.db.getClasses();
|
return diagObj.db.getClasses();
|
||||||
} catch (e) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const addSubGraphs = function (db) {
|
const addSubGraphs = function (db) {
|
||||||
@@ -766,14 +759,8 @@ const insertChildren = (nodeArray, parentLookupDb) => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const draw = async function (text, id, _version, diagObj) {
|
export const draw = async function (text, id, _version, diagObj) {
|
||||||
// Add temporary render element
|
|
||||||
diagObj.db.clear();
|
|
||||||
nodeDb = {};
|
nodeDb = {};
|
||||||
portPos = {};
|
portPos = {};
|
||||||
diagObj.db.setGen('gen-2');
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parser.parse(text);
|
|
||||||
|
|
||||||
const renderEl = select('body').append('div').attr('style', 'height:400px').attr('id', 'cy');
|
const renderEl = select('body').append('div').attr('style', 'height:400px').attr('id', 'cy');
|
||||||
let graph = {
|
let graph = {
|
||||||
id: 'root',
|
id: 'root',
|
||||||
|
@@ -1,10 +1,7 @@
|
|||||||
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
|
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
|
||||||
import { select, curveLinear, selectAll } from 'd3';
|
import { select, curveLinear, selectAll } from 'd3';
|
||||||
|
|
||||||
import flowDb from './flowDb.js';
|
|
||||||
import { getConfig } from '../../config.js';
|
import { getConfig } from '../../config.js';
|
||||||
import utils from '../../utils.js';
|
import utils from '../../utils.js';
|
||||||
|
|
||||||
import { render } from '../../dagre-wrapper/index.js';
|
import { render } from '../../dagre-wrapper/index.js';
|
||||||
import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js';
|
import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js';
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
@@ -344,15 +341,7 @@ export const addEdges = function (edges, g, diagObj) {
|
|||||||
* @returns {object} ClassDef styles
|
* @returns {object} ClassDef styles
|
||||||
*/
|
*/
|
||||||
export const getClasses = function (text, diagObj) {
|
export const getClasses = function (text, diagObj) {
|
||||||
log.info('Extracting classes');
|
|
||||||
diagObj.db.clear();
|
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
return diagObj.db.getClasses();
|
return diagObj.db.getClasses();
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -364,10 +353,6 @@ export const getClasses = function (text, diagObj) {
|
|||||||
|
|
||||||
export const draw = async function (text, id, _version, diagObj) {
|
export const draw = async function (text, id, _version, diagObj) {
|
||||||
log.info('Drawing flowchart');
|
log.info('Drawing flowchart');
|
||||||
diagObj.db.clear();
|
|
||||||
flowDb.setGen('gen-2');
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parser.parse(text);
|
|
||||||
|
|
||||||
// Fetch the default direction, use TD if none was found
|
// Fetch the default direction, use TD if none was found
|
||||||
let dir = diagObj.db.getDirection();
|
let dir = diagObj.db.getDirection();
|
||||||
|
@@ -273,15 +273,7 @@ export const addEdges = function (edges, g, diagObj) {
|
|||||||
*/
|
*/
|
||||||
export const getClasses = function (text, diagObj) {
|
export const getClasses = function (text, diagObj) {
|
||||||
log.info('Extracting classes');
|
log.info('Extracting classes');
|
||||||
diagObj.db.clear();
|
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
return diagObj.db.getClasses();
|
return diagObj.db.getClasses();
|
||||||
} catch (e) {
|
|
||||||
log.error(e);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -294,7 +286,6 @@ export const getClasses = function (text, diagObj) {
|
|||||||
*/
|
*/
|
||||||
export const draw = function (text, id, _version, diagObj) {
|
export const draw = function (text, id, _version, diagObj) {
|
||||||
log.info('Drawing flowchart');
|
log.info('Drawing flowchart');
|
||||||
diagObj.db.clear();
|
|
||||||
const { securityLevel, flowchart: conf } = getConfig();
|
const { securityLevel, flowchart: conf } = getConfig();
|
||||||
let sandboxElement;
|
let sandboxElement;
|
||||||
if (securityLevel === 'sandbox') {
|
if (securityLevel === 'sandbox') {
|
||||||
|
@@ -172,14 +172,11 @@ describe('more than one sequence diagram', () => {
|
|||||||
|
|
||||||
describe('when parsing a sequenceDiagram', function () {
|
describe('when parsing a sequenceDiagram', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
// diagram.db = sequenceDb;
|
|
||||||
// diagram.db.clear();
|
|
||||||
diagram = new Diagram(`
|
diagram = new Diagram(`
|
||||||
sequenceDiagram
|
sequenceDiagram
|
||||||
Alice->Bob:Hello Bob, how are you?
|
Alice->Bob:Hello Bob, how are you?
|
||||||
Note right of Bob: Bob thinks
|
Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`);
|
Bob-->Alice: I am good thanks!`);
|
||||||
diagram.db.clear();
|
|
||||||
});
|
});
|
||||||
it('should handle a sequenceDiagram definition', async function () {
|
it('should handle a sequenceDiagram definition', async function () {
|
||||||
const str = `
|
const str = `
|
||||||
@@ -1482,8 +1479,6 @@ describe('when checking the bounds in a sequenceDiagram', function () {
|
|||||||
let conf;
|
let conf;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mermaidAPI.reset();
|
mermaidAPI.reset();
|
||||||
// diagram.db = sequenceDb;
|
|
||||||
// diagram.db.clear();
|
|
||||||
diagram.renderer.bounds.init();
|
diagram.renderer.bounds.init();
|
||||||
conf = diagram.db.getConfig();
|
conf = diagram.db.getConfig();
|
||||||
});
|
});
|
||||||
@@ -1635,7 +1630,6 @@ sequenceDiagram
|
|||||||
Alice->Bob:Hello Bob, how are you?
|
Alice->Bob:Hello Bob, how are you?
|
||||||
Note right of Bob: Bob thinks
|
Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`);
|
Bob-->Alice: I am good thanks!`);
|
||||||
diagram.db.clear();
|
|
||||||
});
|
});
|
||||||
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
['tspan', 'fo', 'old', undefined].forEach(function (textPlacement) {
|
||||||
it(`
|
it(`
|
||||||
@@ -2009,8 +2003,6 @@ describe('when rendering a sequenceDiagram with actor mirror activated', () => {
|
|||||||
let conf;
|
let conf;
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mermaidAPI.reset();
|
mermaidAPI.reset();
|
||||||
// diagram.db = sequenceDb;
|
|
||||||
diagram.db.clear();
|
|
||||||
conf = diagram.db.getConfig();
|
conf = diagram.db.getConfig();
|
||||||
diagram.renderer.bounds.init();
|
diagram.renderer.bounds.init();
|
||||||
});
|
});
|
||||||
@@ -2052,12 +2044,8 @@ describe('when rendering a sequenceDiagram with directives', () => {
|
|||||||
mermaidAPI.initialize({ sequence: conf });
|
mermaidAPI.initialize({ sequence: conf });
|
||||||
});
|
});
|
||||||
|
|
||||||
let conf;
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mermaidAPI.reset();
|
mermaidAPI.reset();
|
||||||
// diagram.db = sequenceDb;
|
|
||||||
diagram.db.clear();
|
|
||||||
conf = diagram.db.getConfig();
|
|
||||||
diagram.renderer.bounds.init();
|
diagram.renderer.bounds.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2069,10 +2057,7 @@ sequenceDiagram
|
|||||||
participant Alice
|
participant Alice
|
||||||
`;
|
`;
|
||||||
diagram = new Diagram(str);
|
diagram = new Diagram(str);
|
||||||
|
|
||||||
diagram.renderer.bounds.init();
|
diagram.renderer.bounds.init();
|
||||||
await mermaidAPI.parse(str);
|
|
||||||
|
|
||||||
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
||||||
|
|
||||||
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
||||||
@@ -2093,7 +2078,7 @@ sequenceDiagram
|
|||||||
participant Alice
|
participant Alice
|
||||||
`;
|
`;
|
||||||
|
|
||||||
diagram.parse(str);
|
diagram = new Diagram(str);
|
||||||
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
|
||||||
|
|
||||||
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
const { bounds, models } = diagram.renderer.bounds.getBounds();
|
||||||
@@ -2114,7 +2099,7 @@ Alice->Bob:Hello Bob, how are you?
|
|||||||
Note right of Bob: Bob thinks
|
Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
await mermaidAPI.parse(str1);
|
diagram = new Diagram(str1);
|
||||||
diagram.renderer.draw(str1, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers
|
diagram.renderer.draw(str1, 'tst', '1.2.3', diagram); // needs to be rendered for the correct value of visibility auto numbers
|
||||||
expect(diagram.db.showSequenceNumbers()).toBe(true);
|
expect(diagram.db.showSequenceNumbers()).toBe(true);
|
||||||
|
|
||||||
@@ -2124,7 +2109,7 @@ Alice->Bob:Hello Bob, how are you?
|
|||||||
Note right of Bob: Bob thinks
|
Note right of Bob: Bob thinks
|
||||||
Bob-->Alice: I am good thanks!`;
|
Bob-->Alice: I am good thanks!`;
|
||||||
|
|
||||||
await mermaidAPI.parse(str2);
|
diagram = new Diagram(str2);
|
||||||
diagram.renderer.draw(str2, 'tst', '1.2.3', diagram);
|
diagram.renderer.draw(str2, 'tst', '1.2.3', diagram);
|
||||||
expect(diagram.db.showSequenceNumbers()).toBe(false);
|
expect(diagram.db.showSequenceNumbers()).toBe(false);
|
||||||
});
|
});
|
||||||
|
@@ -749,9 +749,6 @@ function adjustCreatedDestroyedData(
|
|||||||
export const draw = function (_text: string, id: string, _version: string, diagObj: Diagram) {
|
export const draw = function (_text: string, id: string, _version: string, diagObj: Diagram) {
|
||||||
const { securityLevel, sequence } = configApi.getConfig();
|
const { securityLevel, sequence } = configApi.getConfig();
|
||||||
conf = sequence;
|
conf = sequence;
|
||||||
diagObj.db.clear();
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parser.parse(_text);
|
|
||||||
// Handle root and Document for when rendering in sandbox mode
|
// Handle root and Document for when rendering in sandbox mode
|
||||||
let sandboxElement;
|
let sandboxElement;
|
||||||
if (securityLevel === 'sandbox') {
|
if (securityLevel === 'sandbox') {
|
||||||
|
@@ -84,17 +84,8 @@ export const setConf = function (cnf) {
|
|||||||
* @returns {object} ClassDef styles (a Map with keys = strings, values = )
|
* @returns {object} ClassDef styles (a Map with keys = strings, values = )
|
||||||
*/
|
*/
|
||||||
export const getClasses = function (text, diagramObj) {
|
export const getClasses = function (text, diagramObj) {
|
||||||
log.trace('Extracting classes');
|
|
||||||
diagramObj.db.clear();
|
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagramObj.parser.parse(text);
|
|
||||||
// must run extract() to turn the parsed statements into states, relationships, classes, etc.
|
|
||||||
diagramObj.db.extract(diagramObj.db.getRootDocV2());
|
diagramObj.db.extract(diagramObj.db.getRootDocV2());
|
||||||
return diagramObj.db.getClasses();
|
return diagramObj.db.getClasses();
|
||||||
} catch (e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,7 +375,6 @@ const getDir = (parsedItem, defaultDir = DEFAULT_NESTED_DOC_DIR) => {
|
|||||||
*/
|
*/
|
||||||
export const draw = async function (text, id, _version, diag) {
|
export const draw = async function (text, id, _version, diag) {
|
||||||
log.info('Drawing state diagram (v2)', id);
|
log.info('Drawing state diagram (v2)', id);
|
||||||
// diag.sb.clear();
|
|
||||||
nodeDb = {};
|
nodeDb = {};
|
||||||
// Fetch the default direction, use TD if none was found
|
// Fetch the default direction, use TD if none was found
|
||||||
let dir = diag.db.getDirection();
|
let dir = diag.db.getDirection();
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#### Grammar
|
#### Grammar
|
||||||
|
|
||||||
This would be to define a jison grammar for the new diagram type. That should start with a way to identify that the text in the mermaid tag is a diagram of that type. Create a new folder under diagrams for your new diagram type and a parser folder in it. This leads us to step 2.
|
This would be to define a JISON grammar for the new diagram type. That should start with a way to identify that the text in the mermaid tag is a diagram of that type. Create a new folder under diagrams for your new diagram type and a parser folder in it. This leads us to step 2.
|
||||||
|
|
||||||
For instance:
|
For instance:
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ Place the renderer in the diagram folder.
|
|||||||
|
|
||||||
### Step 3: Detection of the new diagram type
|
### Step 3: Detection of the new diagram type
|
||||||
|
|
||||||
The second thing to do is to add the capability to detect the new diagram to type to the detectType in utils.js. The detection should return a key for the new diagram type.
|
The second thing to do is to add the capability to detect the new diagram to type to the detectType in `diagram-api/detectType.ts`. The detection should return a key for the new diagram type.
|
||||||
[This key will be used to as the aria roledescription](#aria-roledescription), so it should be a word that clearly describes the diagram type.
|
[This key will be used to as the aria roledescription](#aria-roledescription), so it should be a word that clearly describes the diagram type.
|
||||||
For example, if your new diagram use a UML deployment diagram, a good key would be "UMLDeploymentDiagram" because assistive technologies such as a screen reader
|
For example, if your new diagram use a UML deployment diagram, a good key would be "UMLDeploymentDiagram" because assistive technologies such as a screen reader
|
||||||
would voice that as "U-M-L Deployment diagram." Another good key would be "deploymentDiagram" because that would be voiced as "Deployment Diagram." A bad key would be "deployment" because that would not sufficiently describe the diagram.
|
would voice that as "U-M-L Deployment diagram." Another good key would be "deploymentDiagram" because that would be voiced as "Deployment Diagram." A bad key would be "deployment" because that would not sufficiently describe the diagram.
|
||||||
|
@@ -3,6 +3,7 @@ import { mermaidAPI } from './mermaidAPI.js';
|
|||||||
import './diagram-api/diagram-orchestration.js';
|
import './diagram-api/diagram-orchestration.js';
|
||||||
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
||||||
import { beforeAll, describe, it, expect, vi } from 'vitest';
|
import { beforeAll, describe, it, expect, vi } from 'vitest';
|
||||||
|
import type { DiagramDefinition } from './diagram-api/types.js';
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
addDiagrams();
|
addDiagrams();
|
||||||
@@ -92,13 +93,16 @@ describe('when using mermaid and ', () => {
|
|||||||
|
|
||||||
it('should defer diagram load based on parameter', async () => {
|
it('should defer diagram load based on parameter', async () => {
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
const dummyDiagram = {
|
const dummyDiagram: DiagramDefinition = {
|
||||||
db: {},
|
db: {},
|
||||||
renderer: () => {
|
renderer: () => {
|
||||||
// do nothing
|
// do nothing
|
||||||
},
|
},
|
||||||
parser: () => {
|
parser: {
|
||||||
// do nothing
|
parse: (_text) => {
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
parser: { yy: {} },
|
||||||
},
|
},
|
||||||
styles: () => {
|
styles: () => {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@@ -108,8 +108,7 @@ export interface RenderResult {
|
|||||||
async function parse(text: string, parseOptions?: ParseOptions): Promise<boolean> {
|
async function parse(text: string, parseOptions?: ParseOptions): Promise<boolean> {
|
||||||
addDiagrams();
|
addDiagrams();
|
||||||
try {
|
try {
|
||||||
const diagram = await getDiagramFromText(text);
|
await getDiagramFromText(text);
|
||||||
diagram.parse();
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (parseOptions?.suppressErrors) {
|
if (parseOptions?.suppressErrors) {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -19,7 +19,6 @@ import classDiagram from './diagrams/class/styles.js';
|
|||||||
import flowchart from './diagrams/flowchart/styles.js';
|
import flowchart from './diagrams/flowchart/styles.js';
|
||||||
import flowchartElk from './diagrams/flowchart/elk/styles.js';
|
import flowchartElk from './diagrams/flowchart/elk/styles.js';
|
||||||
import er from './diagrams/er/styles.js';
|
import er from './diagrams/er/styles.js';
|
||||||
import error from './diagrams/error/styles.js';
|
|
||||||
import git from './diagrams/git/styles.js';
|
import git from './diagrams/git/styles.js';
|
||||||
import gantt from './diagrams/gantt/styles.js';
|
import gantt from './diagrams/gantt/styles.js';
|
||||||
import pie from './diagrams/pie/styles.js';
|
import pie from './diagrams/pie/styles.js';
|
||||||
@@ -86,7 +85,6 @@ describe('styles', () => {
|
|||||||
c4,
|
c4,
|
||||||
classDiagram,
|
classDiagram,
|
||||||
er,
|
er,
|
||||||
error,
|
|
||||||
flowchart,
|
flowchart,
|
||||||
flowchartElk,
|
flowchartElk,
|
||||||
gantt,
|
gantt,
|
||||||
|
Reference in New Issue
Block a user