mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 09:49:46 +02:00
Create helper function for subgraph title margin fetching.
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import { vi } from 'vitest';
|
import { vi } from 'vitest';
|
||||||
import utils, { calculatePoint, cleanAndMerge, detectDirective } from './utils.js';
|
import utils, { calculatePoint, cleanAndMerge, detectDirective } from './utils.js';
|
||||||
|
import { getSubGraphTitleMargins } from './utils/getSubGraphTitleMargins.js';
|
||||||
|
import * as configApi from './config.js';
|
||||||
import assignWithDepth from './assignWithDepth.js';
|
import assignWithDepth from './assignWithDepth.js';
|
||||||
import { detectType } from './diagram-api/detectType.js';
|
import { detectType } from './diagram-api/detectType.js';
|
||||||
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
|
||||||
@@ -593,4 +595,24 @@ describe('calculatePoint', () => {
|
|||||||
'Could not find a suitable point for the given distance'
|
'Could not find a suitable point for the given distance'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getSubGraphTitleMargins', () => {
|
||||||
|
it('should get subgraph title margins after config has been set', () => {
|
||||||
|
const config_0 = {
|
||||||
|
flowchart: {
|
||||||
|
subGraphTitleMargin: {
|
||||||
|
top: 10,
|
||||||
|
bottom: 5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
configApi.setSiteConfig(config_0);
|
||||||
|
expect(getSubGraphTitleMargins()).toEqual({
|
||||||
|
subGraphTitleTopMargin: 10,
|
||||||
|
subGraphTitleBottomMargin: 5,
|
||||||
|
subGraphTitleTotalMargin: 15,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
17
packages/mermaid/src/utils/getSubGraphTitleMargins.ts
Normal file
17
packages/mermaid/src/utils/getSubGraphTitleMargins.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { getConfig } from '../diagram-api/diagramAPI.js';
|
||||||
|
|
||||||
|
export const getSubGraphTitleMargins = (): {
|
||||||
|
subGraphTitleTopMargin: number;
|
||||||
|
subGraphTitleBottomMargin: number;
|
||||||
|
subGraphTitleTotalMargin: number;
|
||||||
|
} => {
|
||||||
|
const subGraphTitleTopMargin = getConfig().flowchart?.subGraphTitleMargin?.top || 0;
|
||||||
|
const subGraphTitleBottomMargin = getConfig().flowchart?.subGraphTitleMargin?.bottom || 0;
|
||||||
|
const subGraphTitleTotalMargin = subGraphTitleTopMargin + subGraphTitleBottomMargin;
|
||||||
|
|
||||||
|
return {
|
||||||
|
subGraphTitleTopMargin,
|
||||||
|
subGraphTitleBottomMargin,
|
||||||
|
subGraphTitleTotalMargin,
|
||||||
|
};
|
||||||
|
};
|
Reference in New Issue
Block a user