mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-15 06:19:24 +02:00
Compare commits
2 Commits
mermaid@11
...
halo-layou
Author | SHA1 | Date | |
---|---|---|---|
![]() |
39598baaa3 | ||
![]() |
08fbed7c47 |
@@ -1,7 +1,7 @@
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import type { DiagramStyleClassDef } from '../../diagram-api/types.js';
|
||||
import { log } from '../../logger.js';
|
||||
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js';
|
||||
import { getDiagramElement } from '../../rendering-util/getDiagramElement.js';
|
||||
import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js';
|
||||
import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js';
|
||||
import type { LayoutData } from '../../rendering-util/types.js';
|
||||
|
@@ -2,7 +2,7 @@ import { select } from 'd3';
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import type { DiagramStyleClassDef } from '../../diagram-api/types.js';
|
||||
import { log } from '../../logger.js';
|
||||
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js';
|
||||
import { getDiagramElement } from '../../rendering-util/getDiagramElement.js';
|
||||
import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js';
|
||||
import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js';
|
||||
import type { LayoutData } from '../../rendering-util/types.js';
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||
import type { DiagramStyleClassDef } from '../../diagram-api/types.js';
|
||||
import { log } from '../../logger.js';
|
||||
import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js';
|
||||
import { getDiagramElement } from '../../rendering-util/getDiagramElement.js';
|
||||
import { render } from '../../rendering-util/render.js';
|
||||
import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js';
|
||||
import type { LayoutData } from '../../rendering-util/types.js';
|
||||
|
20
packages/mermaid/src/rendering-util/insertElementsForSize.ts
Normal file
20
packages/mermaid/src/rendering-util/insertElementsForSize.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { SVG } from '../diagram-api/types.js';
|
||||
import { getConfig } from '../diagram-api/diagramAPI.js';
|
||||
import type { LayoutData } from './types.js';
|
||||
import { insertNode } from './rendering-elements/nodes.js';
|
||||
|
||||
export async function insertElementsForSize(el: SVG, data: LayoutData) {
|
||||
const nodesElem = el.insert('g').attr('class', 'nodes');
|
||||
el.insert('g').attr('class', 'edges');
|
||||
for (const item of data.nodes) {
|
||||
if (!item.isGroup) {
|
||||
const node = item;
|
||||
const config = getConfig();
|
||||
const newNode = await insertNode(nodesElem, node, { config, dir: node.dir });
|
||||
const boundingBox = newNode.node()!.getBBox();
|
||||
item.domId = newNode.attr('id');
|
||||
item.width = boundingBox.width;
|
||||
item.height = boundingBox.height;
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,6 +3,7 @@ import type { InternalHelpers } from '../internals.js';
|
||||
import { internalHelpers } from '../internals.js';
|
||||
import { log } from '../logger.js';
|
||||
import type { LayoutData } from './types.js';
|
||||
import { insertElementsForSize } from './insertElementsForSize.js';
|
||||
|
||||
export interface RenderOptions {
|
||||
algorithm?: string;
|
||||
@@ -51,6 +52,8 @@ export const render = async (data4Layout: LayoutData, svg: SVG) => {
|
||||
|
||||
const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];
|
||||
const layoutRenderer = await layoutDefinition.loader();
|
||||
// Add the bounding box to the layout so that the render can run
|
||||
await insertElementsForSize(svg, data4Layout);
|
||||
return layoutRenderer.render(data4Layout, svg, internalHelpers, {
|
||||
algorithm: layoutDefinition.algorithm,
|
||||
});
|
||||
|
Reference in New Issue
Block a user