mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-10 19:09:44 +02:00
feat: Set config.layout=elk when using flowchart-elk
This commit is contained in:
@@ -1,34 +1,26 @@
|
|||||||
import type {
|
import type {
|
||||||
ExternalDiagramDefinition,
|
|
||||||
DiagramDetector,
|
DiagramDetector,
|
||||||
DiagramLoader,
|
DiagramLoader,
|
||||||
|
ExternalDiagramDefinition,
|
||||||
} from '../../../diagram-api/types.js';
|
} from '../../../diagram-api/types.js';
|
||||||
import { log } from '../../../logger.js';
|
|
||||||
|
|
||||||
const id = 'flowchart-elk';
|
const id = 'flowchart-elk';
|
||||||
|
|
||||||
const detector: DiagramDetector = (txt, config): boolean => {
|
const detector: DiagramDetector = (txt, config = {}): boolean => {
|
||||||
if (
|
if (
|
||||||
// If diagram explicitly states flowchart-elk
|
// If diagram explicitly states flowchart-elk
|
||||||
/^\s*flowchart-elk/.test(txt) ||
|
/^\s*flowchart-elk/.test(txt) ||
|
||||||
// If a flowchart/graph diagram has their default renderer set to elk
|
// If a flowchart/graph diagram has their default renderer set to elk
|
||||||
(/^\s*flowchart|graph/.test(txt) && config?.flowchart?.defaultRenderer === 'elk')
|
(/^\s*flowchart|graph/.test(txt) && config?.flowchart?.defaultRenderer === 'elk')
|
||||||
) {
|
) {
|
||||||
// This will log at the end, hopefully.
|
config.layout = 'elk';
|
||||||
setTimeout(
|
|
||||||
() =>
|
|
||||||
log.warn(
|
|
||||||
'flowchart-elk was moved to an external package in Mermaid v11. Please refer [release notes](link) for more details. This diagram will be rendered using `dagre` layout as a fallback.'
|
|
||||||
),
|
|
||||||
500
|
|
||||||
);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const loader: DiagramLoader = async () => {
|
const loader: DiagramLoader = async () => {
|
||||||
const { diagram } = await import('../flowDiagram-v2.js');
|
const { diagram } = await import('../flowDiagram.js');
|
||||||
return { id, diagram };
|
return { id, diagram };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -1,10 +1,10 @@
|
|||||||
// @ts-ignore: JISON doesn't support types
|
|
||||||
import flowParser from './parser/flow.jison';
|
|
||||||
import flowDb from './flowDb.js';
|
|
||||||
import renderer from './flowRenderer-v3-unified.js';
|
|
||||||
import flowStyles from './styles.js';
|
|
||||||
import type { MermaidConfig } from '../../config.type.js';
|
import type { MermaidConfig } from '../../config.type.js';
|
||||||
import { setConfig } from '../../diagram-api/diagramAPI.js';
|
import { setConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
|
import flowDb from './flowDb.js';
|
||||||
|
import renderer from './flowRenderer-v3-unified.js';
|
||||||
|
// @ts-ignore: JISON doesn't support types
|
||||||
|
import flowParser from './parser/flow.jison';
|
||||||
|
import flowStyles from './styles.js';
|
||||||
|
|
||||||
export const diagram = {
|
export const diagram = {
|
||||||
parser: flowParser,
|
parser: flowParser,
|
||||||
@@ -15,6 +15,9 @@ export const diagram = {
|
|||||||
if (!cnf.flowchart) {
|
if (!cnf.flowchart) {
|
||||||
cnf.flowchart = {};
|
cnf.flowchart = {};
|
||||||
}
|
}
|
||||||
|
if (cnf.layout) {
|
||||||
|
setConfig({ layout: cnf.layout });
|
||||||
|
}
|
||||||
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
||||||
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
|
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
|
||||||
flowDb.clear();
|
flowDb.clear();
|
||||||
|
Reference in New Issue
Block a user