mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 17:59:39 +02:00
fix: Remove triple parsing of diagrams
This commit is contained in:
@@ -32,7 +32,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,6 +48,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;
|
||||||
|
this.db.clear?.();
|
||||||
if (diagram.init) {
|
if (diagram.init) {
|
||||||
diagram.init(cnf);
|
diagram.init(cnf);
|
||||||
log.info('Initialized diagram ' + this.type, cnf);
|
log.info('Initialized diagram ' + this.type, cnf);
|
||||||
@@ -60,7 +60,6 @@ export class Diagram {
|
|||||||
if (this.detectError) {
|
if (this.detectError) {
|
||||||
throw this.detectError;
|
throw this.detectError;
|
||||||
}
|
}
|
||||||
this.db.clear?.();
|
|
||||||
this.parser.parse(this.text);
|
this.parser.parse(this.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
|
@@ -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');
|
return diagObj.db.getClasses();
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
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');
|
return diagObj.db.getClasses();
|
||||||
diagObj.db.clear();
|
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
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();
|
return diagObj.db.getClasses();
|
||||||
try {
|
|
||||||
// Parse the graph definition
|
|
||||||
diagObj.parse(text);
|
|
||||||
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') {
|
||||||
|
@@ -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,7 @@ 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');
|
return diagramObj.db.getClasses();
|
||||||
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());
|
|
||||||
return diagramObj.db.getClasses();
|
|
||||||
} catch (e) {
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -384,7 +374,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();
|
||||||
|
Reference in New Issue
Block a user