mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-22 08:50:13 +02:00
Change getSubGraphTitleMargins to accept config object as parameter
This commit is contained in:
@@ -64,7 +64,7 @@ const rect = (parent, node) => {
|
|||||||
.attr('width', width)
|
.attr('width', width)
|
||||||
.attr('height', node.height + padding);
|
.attr('height', node.height + padding);
|
||||||
|
|
||||||
const { subGraphTitleTopMargin } = getSubGraphTitleMargins();
|
const { subGraphTitleTopMargin } = getSubGraphTitleMargins(getConfig());
|
||||||
if (useHtmlLabels) {
|
if (useHtmlLabels) {
|
||||||
label.attr(
|
label.attr(
|
||||||
'transform',
|
'transform',
|
||||||
@@ -181,7 +181,7 @@ const roundedWithTitle = (parent, node) => {
|
|||||||
.attr('width', width + padding)
|
.attr('width', width + padding)
|
||||||
.attr('height', node.height + padding - bbox.height - 3);
|
.attr('height', node.height + padding - bbox.height - 3);
|
||||||
|
|
||||||
const { subGraphTitleTopMargin } = getSubGraphTitleMargins();
|
const { subGraphTitleTopMargin } = getSubGraphTitleMargins(getConfig());
|
||||||
// Center the label
|
// Center the label
|
||||||
label.attr(
|
label.attr(
|
||||||
'transform',
|
'transform',
|
||||||
|
@@ -14,8 +14,7 @@ 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';
|
import { getSubGraphTitleMargins } from '../utils/getSubGraphTitleMargins.js';
|
||||||
|
import { getConfig } from '../diagram-api/diagramAPI.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);
|
||||||
@@ -104,6 +103,7 @@ const recursiveRender = async (_elem, graph, diagramtype, id, parentCluster) =>
|
|||||||
log.info('Graph after layout:', graphlibJson.write(graph));
|
log.info('Graph after layout:', graphlibJson.write(graph));
|
||||||
// Move the nodes to the correct place
|
// Move the nodes to the correct place
|
||||||
let diff = 0;
|
let diff = 0;
|
||||||
|
const { subGraphTitleTotalMargin } = getSubGraphTitleMargins(getConfig());
|
||||||
sortNodesByHierarchy(graph).forEach(function (v) {
|
sortNodesByHierarchy(graph).forEach(function (v) {
|
||||||
const node = graph.node(v);
|
const node = graph.node(v);
|
||||||
log.info('Position ' + v + ': ' + JSON.stringify(graph.node(v)));
|
log.info('Position ' + v + ': ' + JSON.stringify(graph.node(v)));
|
||||||
|
@@ -609,7 +609,7 @@ describe('getSubGraphTitleMargins', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
configApi.setSiteConfig(config_0);
|
configApi.setSiteConfig(config_0);
|
||||||
expect(getSubGraphTitleMargins()).toEqual({
|
expect(getSubGraphTitleMargins(config_0)).toEqual({
|
||||||
subGraphTitleTopMargin: 10,
|
subGraphTitleTopMargin: 10,
|
||||||
subGraphTitleBottomMargin: 5,
|
subGraphTitleBottomMargin: 5,
|
||||||
subGraphTitleTotalMargin: 15,
|
subGraphTitleTotalMargin: 15,
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
import { getConfig } from '../diagram-api/diagramAPI.js';
|
import { FlowchartDiagramConfig } from '../config.type.js';
|
||||||
|
|
||||||
export const getSubGraphTitleMargins = (): {
|
export const getSubGraphTitleMargins = ({
|
||||||
|
flowchart,
|
||||||
|
}: {
|
||||||
|
flowchart: FlowchartDiagramConfig;
|
||||||
|
}): {
|
||||||
subGraphTitleTopMargin: number;
|
subGraphTitleTopMargin: number;
|
||||||
subGraphTitleBottomMargin: number;
|
subGraphTitleBottomMargin: number;
|
||||||
subGraphTitleTotalMargin: number;
|
subGraphTitleTotalMargin: number;
|
||||||
} => {
|
} => {
|
||||||
const { flowchart } = getConfig();
|
|
||||||
const subGraphTitleTopMargin = flowchart?.subGraphTitleMargin?.top ?? 0;
|
const subGraphTitleTopMargin = flowchart?.subGraphTitleMargin?.top ?? 0;
|
||||||
const subGraphTitleBottomMargin = flowchart?.subGraphTitleMargin?.bottom ?? 0;
|
const subGraphTitleBottomMargin = flowchart?.subGraphTitleMargin?.bottom ?? 0;
|
||||||
const subGraphTitleTotalMargin = subGraphTitleTopMargin + subGraphTitleBottomMargin;
|
const subGraphTitleTotalMargin = subGraphTitleTopMargin + subGraphTitleBottomMargin;
|
||||||
|
Reference in New Issue
Block a user