Fix for issues in errorhandling and class diagrams after refactoring

This commit is contained in:
Knut Sveidqvist
2022-09-16 14:05:15 +02:00
parent 2d9f25b163
commit 9c88c785cb
7 changed files with 29 additions and 14 deletions

View File

@@ -47,9 +47,17 @@
<div>Security check</div> <div>Security check</div>
<div class="flex"> <div class="flex">
<pre id="diagram" class="mermaid"> <pre id="diagram" class="mermaid">
sequenceDiagram flowchart TD
Nothing:Valid; A[myClass1] --> B[default] & C[default]
</pre> B[default] & C[default] --> D[myClass2]
classDef default stroke-width:2px,fill:none,stroke:silver
classDef node color:red
classDef myClass1 color:#0000ff
classDef myClass2 stroke:#0000ff,fill:#ccccff
class A myClass1
class D myClass2
</pre
>
<div id="res" class=""></div> <div id="res" class=""></div>
</div> </div>
<script src="./mermaid.js"></script> <script src="./mermaid.js"></script>
@@ -59,6 +67,7 @@ sequenceDiagram
}; };
mermaid.initialize({ mermaid.initialize({
startOnLoad: false, startOnLoad: false,
logLevel: 0,
// themeVariables: {relationLabelColor: 'red'} // themeVariables: {relationLabelColor: 'red'}
}); });
function callback() { function callback() {

View File

@@ -119,7 +119,7 @@ const dependency = (elem, type) => {
.append('path') .append('path')
.attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z'); .attr('d', 'M 18,7 L9,13 L14,7 L9,1 Z');
}; };
const lollipop = (elem, type, id) => { const lollipop = (elem, type) => {
elem elem
.append('defs') .append('defs')
.append('marker') .append('marker')

View File

@@ -228,9 +228,9 @@ const config: Partial<MermaidConfig> = {
* Decides which rendering engine that is to be used for the rendering. Legal values are: * Decides which rendering engine that is to be used for the rendering. Legal values are:
* dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid * dagre-d3 dagre-wrapper - wrapper for dagre implemented in mermaid
* *
* Default value: 'dagre-d3' * Default value: 'dagre-wrapper'
*/ */
defaultRenderer: 'dagre-d3', defaultRenderer: 'dagre-wrapper',
}, },
/** The object containing configurations specific for sequence diagrams */ /** The object containing configurations specific for sequence diagrams */
@@ -387,7 +387,8 @@ const config: Partial<MermaidConfig> = {
* *
* **Notes:** * **Notes:**
* *
* This will display arrows that start and begin at the same node as right angles, rather than a curve * This will display arrows that start and begin at the same node as right angles, rather than a
* curve
* *
* Default value: false * Default value: false
*/ */
@@ -802,7 +803,8 @@ const config: Partial<MermaidConfig> = {
* *
* **Notes:** * **Notes:**
* *
* This will display arrows that start and begin at the same node as right angles, rather than a curves * This will display arrows that start and begin at the same node as right angles, rather than a
* curves
* *
* Default value: false * Default value: false
*/ */

View File

@@ -105,7 +105,11 @@ export const addDiagrams = () => {
'error', 'error',
// Special diagram with error messages but setup as a regular diagram // Special diagram with error messages but setup as a regular diagram
{ {
db: {}, db: {
clear: () => {
// Quite ok, clear needs to be there for error to work as a regular diagram
},
},
styles: errorStyles, styles: errorStyles,
renderer: errorRenderer, renderer: errorRenderer,
parser: { parser: {

View File

@@ -17,10 +17,11 @@ export const setConf = function (cnf: any) {
/** /**
* 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
* @param {string} id The text for the error * @param {string} id The text for the error
* @param {string} mermaidVersion The version * @param {string} mermaidVersion The version
*/ */
export const draw = (id: string, mermaidVersion: string) => { export const draw = (text: string, id: string, mermaidVersion: string) => {
try { try {
log.debug('Renering svg for syntax error\n'); log.debug('Renering svg for syntax error\n');

View File

@@ -312,7 +312,7 @@ const render = function (
try { try {
diag.renderer.draw(text, id, pkg.version, diag); diag.renderer.draw(text, id, pkg.version, diag);
} catch (e) { } catch (e) {
errorRenderer.draw(id, pkg.version); errorRenderer.draw(text, id, pkg.version);
throw e; throw e;
} }

View File

@@ -71,7 +71,7 @@ const directiveWithoutOpen =
* g-->h * g-->h
* ``` * ```
* @param {string} text The text defining the graph * @param {string} text The text defining the graph
* @param {any} cnf * @param {any} config
* @returns {object} The json object representing the init passed to mermaid.initialize() * @returns {object} The json object representing the init passed to mermaid.initialize()
*/ */
export const detectInit = function (text: string, config?: MermaidConfig): MermaidConfig { export const detectInit = function (text: string, config?: MermaidConfig): MermaidConfig {
@@ -392,7 +392,6 @@ const calcTerminalLabelPosition = (terminalMarkerSize, position, _points) => {
} }
points.forEach((point) => { points.forEach((point) => {
totalDistance += distance(point, prevPoint);
prevPoint = point; prevPoint = point;
}); });
@@ -746,7 +745,7 @@ let decoder;
* Decodes HTML, source: {@link https://github.com/shrpne/entity-decode/blob/v2.0.1/browser.js} * Decodes HTML, source: {@link https://github.com/shrpne/entity-decode/blob/v2.0.1/browser.js}
* *
* @param {string} html HTML as a string * @param {string} html HTML as a string
* @returns Unescaped HTML * @returns {string} Unescaped HTML
*/ */
export const entityDecode = function (html) { export const entityDecode = function (html) {
decoder = decoder || document.createElement('div'); decoder = decoder || document.createElement('div');