mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-12-04 19:44:11 +01:00
Add logic to add subgraph title margin on layout
This commit is contained in:
@@ -6,6 +6,7 @@ import { getConfig } from '../diagram-api/diagramAPI.js';
|
|||||||
import utils from '../utils.js';
|
import utils from '../utils.js';
|
||||||
import { evaluate } from '../diagrams/common/common.js';
|
import { evaluate } from '../diagrams/common/common.js';
|
||||||
import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js';
|
import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js';
|
||||||
|
import { getSubGraphTitleMargins } from '../utils/getSubGraphTitleMargins.js';
|
||||||
|
|
||||||
let edgeLabels = {};
|
let edgeLabels = {};
|
||||||
let terminalLabels = {};
|
let terminalLabels = {};
|
||||||
@@ -263,6 +264,7 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
|
|
||||||
const Q = Math.abs(outsidePoint.y - insidePoint.y);
|
const Q = Math.abs(outsidePoint.y - insidePoint.y);
|
||||||
const R = Math.abs(outsidePoint.x - insidePoint.x);
|
const R = Math.abs(outsidePoint.x - insidePoint.x);
|
||||||
|
const { subGraphTitleTotalMargin } = getSubGraphTitleMargins();
|
||||||
// log.warn();
|
// log.warn();
|
||||||
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) {
|
if (Math.abs(y - outsidePoint.y) * w > Math.abs(x - outsidePoint.x) * h) {
|
||||||
// Intersection is top or bottom of rect.
|
// Intersection is top or bottom of rect.
|
||||||
@@ -280,6 +282,9 @@ export const intersection = (node, outsidePoint, insidePoint) => {
|
|||||||
}
|
}
|
||||||
if (R === 0) {
|
if (R === 0) {
|
||||||
res.x = outsidePoint.x;
|
res.x = outsidePoint.x;
|
||||||
|
if (q && subGraphTitleTotalMargin) {
|
||||||
|
res.y = insidePoint.y < outsidePoint.y ? y + h : y - h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Q === 0) {
|
if (Q === 0) {
|
||||||
res.y = outsidePoint.y;
|
res.y = outsidePoint.y;
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ import { insertNode, positionNode, clear as clearNodes, setNodeElem } from './no
|
|||||||
import { insertCluster, clear as clearClusters } from './clusters.js';
|
import { insertCluster, clear as clearClusters } from './clusters.js';
|
||||||
import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges.js';
|
import { insertEdgeLabel, positionEdgeLabel, insertEdge, clear as clearEdges } from './edges.js';
|
||||||
import { log } from '../logger.js';
|
import { log } from '../logger.js';
|
||||||
|
import { getSubGraphTitleMargins } from '../utils/getSubGraphTitleMargins.js';
|
||||||
|
|
||||||
|
const { subGraphTitleTotalMargin } = getSubGraphTitleMargins();
|
||||||
|
|
||||||
const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster) => {
|
const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster) => {
|
||||||
log.info('Graph in recursive render: XXX', graphlibJson.write(graph), parentCluster);
|
log.info('Graph in recursive render: XXX', graphlibJson.write(graph), parentCluster);
|
||||||
@@ -114,13 +117,20 @@ const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster) =>
|
|||||||
);
|
);
|
||||||
if (node && node.clusterNode) {
|
if (node && node.clusterNode) {
|
||||||
// clusterDb[node.id].node = node;
|
// clusterDb[node.id].node = node;
|
||||||
|
node.y += subGraphTitleTotalMargin;
|
||||||
positionNode(node);
|
positionNode(node);
|
||||||
} else {
|
} else {
|
||||||
// Non cluster node
|
// Non cluster node
|
||||||
if (graph.children(v).length > 0) {
|
if (graph.children(v).length > 0) {
|
||||||
// A cluster in the non-recursive way
|
// A cluster in the non-recursive way
|
||||||
// positionCluster(node);
|
// positionCluster(node);
|
||||||
|
node.height += subGraphTitleTotalMargin * 2;
|
||||||
|
graph.children(v).forEach((c) => {
|
||||||
|
if (!clusterDb[c]) return;
|
||||||
|
if (!clusterDb[c].clusterData) {
|
||||||
|
node.height += subGraphTitleTotalMargin * 2;
|
||||||
|
}
|
||||||
|
});
|
||||||
insertCluster(clusters, node);
|
insertCluster(clusters, node);
|
||||||
clusterDb[node.id].node = node;
|
clusterDb[node.id].node = node;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user