mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-13 16:04:55 +01:00
Setup renderer and data collection
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
|
import type { Node, Edge } from '../../rendering-util/types.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
setAccTitle,
|
setAccTitle,
|
||||||
@@ -7,6 +8,8 @@ import {
|
|||||||
getAccDescription,
|
getAccDescription,
|
||||||
setAccDescription,
|
setAccDescription,
|
||||||
clear as commonClear,
|
clear as commonClear,
|
||||||
|
setDiagramTitle,
|
||||||
|
getDiagramTitle,
|
||||||
} from '../common/commonDb.js';
|
} from '../common/commonDb.js';
|
||||||
import type {
|
import type {
|
||||||
Element,
|
Element,
|
||||||
@@ -170,6 +173,44 @@ const clear = () => {
|
|||||||
commonClear();
|
commonClear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getData = () => {
|
||||||
|
const config = getConfig();
|
||||||
|
const nodes: Node[] = [];
|
||||||
|
const edges: Edge[] = [];
|
||||||
|
|
||||||
|
for (const requirement of requirements.values()) {
|
||||||
|
const node = requirement as unknown as Node;
|
||||||
|
node.shape = 'requirementBox';
|
||||||
|
node.look = config.look;
|
||||||
|
nodes.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const element of elements.values()) {
|
||||||
|
const node = element as unknown as Node;
|
||||||
|
node.shape = 'requirementBox';
|
||||||
|
node.look = config.look;
|
||||||
|
|
||||||
|
nodes.push(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const relation of relations) {
|
||||||
|
let counter = 0;
|
||||||
|
const edge: Edge = {
|
||||||
|
id: `${relation.src}-${relation.dst}-${counter}`,
|
||||||
|
start: requirements.get(relation.src)?.id,
|
||||||
|
end: requirements.get(relation.dst)?.id,
|
||||||
|
type: relation.type,
|
||||||
|
classes: 'relationshipLine',
|
||||||
|
style: ['fill:none'],
|
||||||
|
};
|
||||||
|
|
||||||
|
edges.push(edge);
|
||||||
|
counter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { nodes, edges, other: {}, config };
|
||||||
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Relationships,
|
Relationships,
|
||||||
RequirementType,
|
RequirementType,
|
||||||
@@ -186,6 +227,8 @@ export default {
|
|||||||
getAccTitle,
|
getAccTitle,
|
||||||
setAccDescription,
|
setAccDescription,
|
||||||
getAccDescription,
|
getAccDescription,
|
||||||
|
setDiagramTitle,
|
||||||
|
getDiagramTitle,
|
||||||
addElement,
|
addElement,
|
||||||
getElements,
|
getElements,
|
||||||
setNewElementType,
|
setNewElementType,
|
||||||
@@ -193,4 +236,5 @@ export default {
|
|||||||
addRelationship,
|
addRelationship,
|
||||||
getRelationships,
|
getRelationships,
|
||||||
clear,
|
clear,
|
||||||
|
getData,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { DiagramDefinition } from '../../diagram-api/types.js';
|
|||||||
import parser from './parser/requirementDiagram.jison';
|
import parser from './parser/requirementDiagram.jison';
|
||||||
import db from './requirementDb.js';
|
import db from './requirementDb.js';
|
||||||
import styles from './styles.js';
|
import styles from './styles.js';
|
||||||
import renderer from './requirementRenderer.js';
|
import renderer from './requirementRenderer-unified.js';
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
parser,
|
parser,
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
|
import { log } from '../../logger.js';
|
||||||
|
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js';
|
||||||
|
import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js';
|
||||||
|
import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js';
|
||||||
|
import type { LayoutData } from '../../rendering-util/types.js';
|
||||||
|
import utils from '../../utils.js';
|
||||||
|
|
||||||
|
export const draw = async function (text: string, id: string, _version: string, diag: any) {
|
||||||
|
log.info('REF0:');
|
||||||
|
log.info('Drawing requirement diagram (unified)', id);
|
||||||
|
const { securityLevel, state: conf, layout } = getConfig();
|
||||||
|
|
||||||
|
const data4Layout = diag.db.getData() as LayoutData;
|
||||||
|
|
||||||
|
// Create the root SVG - the element is the div containing the SVG element
|
||||||
|
const svg = getDiagramElement(id, securityLevel);
|
||||||
|
|
||||||
|
data4Layout.type = diag.type;
|
||||||
|
data4Layout.layoutAlgorithm = getRegisteredLayoutAlgorithm(layout);
|
||||||
|
|
||||||
|
data4Layout.nodeSpacing = conf?.nodeSpacing || 50;
|
||||||
|
data4Layout.rankSpacing = conf?.rankSpacing || 50;
|
||||||
|
data4Layout.markers = ['aggregation', 'extension', 'composition', 'dependency', 'lollipop'];
|
||||||
|
data4Layout.diagramId = id;
|
||||||
|
await render(data4Layout, svg);
|
||||||
|
const padding = 8;
|
||||||
|
utils.insertTitle(
|
||||||
|
svg,
|
||||||
|
'requirementDiagramTitleText',
|
||||||
|
conf?.titleTopMargin ?? 25,
|
||||||
|
diag.db.getDiagramTitle()
|
||||||
|
);
|
||||||
|
|
||||||
|
setupViewPortForSVG(svg, padding, 'requirementDiagram', conf?.useMaxWidth ?? true);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
draw,
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user