mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
#3687 Separating the render specific data from the data related to parsing
This commit is contained in:
parent
aec1d80966
commit
752a6b2cb0
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mermaid-js/mermaid-mindmap",
|
"name": "@mermaid-js/mermaid-mindmap",
|
||||||
"version": "9.2.0-rc3",
|
"version": "9.2.0-rc4",
|
||||||
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
|
||||||
"main": "dist/mermaid-mindmap.core.mjs",
|
"main": "dist/mermaid-mindmap.core.mjs",
|
||||||
"module": "dist/mermaid-mindmap.core.mjs",
|
"module": "dist/mermaid-mindmap.core.mjs",
|
||||||
|
@ -3,11 +3,10 @@ import { sanitizeText, getConfig, log } from './mermaidUtils';
|
|||||||
|
|
||||||
let nodes = [];
|
let nodes = [];
|
||||||
let cnt = 0;
|
let cnt = 0;
|
||||||
let elements = {};
|
|
||||||
export const clear = () => {
|
export const clear = () => {
|
||||||
nodes = [];
|
nodes = [];
|
||||||
cnt = 0;
|
cnt = 0;
|
||||||
elements = {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const getParent = function (level) {
|
const getParent = function (level) {
|
||||||
@ -27,7 +26,7 @@ export const addNode = (level, id, descr, type) => {
|
|||||||
log.info('addNode', level, id, descr, type);
|
log.info('addNode', level, id, descr, type);
|
||||||
const conf = getConfig();
|
const conf = getConfig();
|
||||||
const node = {
|
const node = {
|
||||||
id: cnt++,
|
id: `id-${cnt++}`,
|
||||||
nodeId: sanitizeText(id),
|
nodeId: sanitizeText(id),
|
||||||
level,
|
level,
|
||||||
descr: sanitizeText(descr),
|
descr: sanitizeText(descr),
|
||||||
@ -99,10 +98,6 @@ export const getType = (startStr, endStr) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setElementForId = (id, element) => {
|
|
||||||
elements[id] = element;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const decorateNode = (decoration) => {
|
export const decorateNode = (decoration) => {
|
||||||
const node = nodes[nodes.length - 1];
|
const node = nodes[nodes.length - 1];
|
||||||
if (decoration && decoration.icon) {
|
if (decoration && decoration.icon) {
|
||||||
@ -141,4 +136,3 @@ export const setErrorHandler = (handler) => {
|
|||||||
export const getLogger = () => log;
|
export const getLogger = () => log;
|
||||||
|
|
||||||
export const getNodeById = (id) => nodes[id];
|
export const getNodeById = (id) => nodes[id];
|
||||||
export const getElementById = (id) => elements[id];
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/** Created by knut on 14-12-11. */
|
/** Created by knut on 14-12-11. */
|
||||||
import { select } from 'd3';
|
import { select } from 'd3';
|
||||||
import { log, getConfig, setupGraphViewbox } from './mermaidUtils';
|
import { log, getConfig, setupGraphViewbox } from './mermaidUtils';
|
||||||
import svgDraw from './svgDraw';
|
import svgDraw, { getElementById, clearElementRefs } from './svgDraw';
|
||||||
import cytoscape from 'cytoscape';
|
import cytoscape from 'cytoscape';
|
||||||
import coseBilkent from 'cytoscape-cose-bilkent';
|
import coseBilkent from 'cytoscape-cose-bilkent';
|
||||||
import * as db from './mindmapDb';
|
import * as db from './mindmapDb';
|
||||||
@ -155,7 +155,7 @@ function positionNodes(cy) {
|
|||||||
data.x = node.position().x;
|
data.x = node.position().x;
|
||||||
data.y = node.position().y;
|
data.y = node.position().y;
|
||||||
svgDraw.positionNode(data);
|
svgDraw.positionNode(data);
|
||||||
const el = db.getElementById(data.nodeId);
|
const el = getElementById(data.nodeId);
|
||||||
log.info('Id:', id, 'Position: (', node.position().x, ', ', node.position().y, ')', data);
|
log.info('Id:', id, 'Position: (', node.position().x, ', ', node.position().y, ')', data);
|
||||||
el.attr(
|
el.attr(
|
||||||
'transform',
|
'transform',
|
||||||
@ -179,6 +179,7 @@ export const draw = async (text, id, version, diagObj) => {
|
|||||||
|
|
||||||
// This is done only for throwing the error if the text is not valid.
|
// This is done only for throwing the error if the text is not valid.
|
||||||
diagObj.db.clear();
|
diagObj.db.clear();
|
||||||
|
clearElementRefs();
|
||||||
// Parse the graph definition
|
// Parse the graph definition
|
||||||
diagObj.parser.parse(text);
|
diagObj.parser.parse(text);
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ export const drawNode = function (elem, node, fullSection, conf) {
|
|||||||
// if (typeof node.x !== 'undefined' && typeof node.y !== 'undefined') {
|
// if (typeof node.x !== 'undefined' && typeof node.y !== 'undefined') {
|
||||||
// nodeElem.attr('transform', 'translate(' + node.x + ',' + node.y + ')');
|
// nodeElem.attr('transform', 'translate(' + node.x + ',' + node.y + ')');
|
||||||
// }
|
// }
|
||||||
db.setElementForId(node.id, nodeElem);
|
setElementById(node.id, nodeElem);
|
||||||
return node.height;
|
return node.height;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -286,7 +286,7 @@ export const drawEdge = function drawEdge(edgesElem, mindmap, parent, depth, ful
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const positionNode = function (node) {
|
export const positionNode = function (node) {
|
||||||
const nodeElem = db.getElementById(node.id);
|
const nodeElem = getElementById(node.id);
|
||||||
|
|
||||||
const x = node.x || 0;
|
const x = node.x || 0;
|
||||||
const y = node.y || 0;
|
const y = node.y || 0;
|
||||||
@ -295,3 +295,17 @@ export const positionNode = function (node) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default { drawNode, positionNode, drawEdge };
|
export default { drawNode, positionNode, drawEdge };
|
||||||
|
|
||||||
|
let elements = {};
|
||||||
|
|
||||||
|
export const setElementById = (id, element) => {
|
||||||
|
elements[id] = element;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getElementById = (id) => {
|
||||||
|
return elements[id];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const clearElementRefs = () => {
|
||||||
|
elements = {};
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user