Skip to content

Commit

Permalink
feat: Set config.layout=elk when using flowchart-elk
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Aug 21, 2024
1 parent 754fa24 commit bc3fe33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
16 changes: 4 additions & 12 deletions packages/mermaid/src/diagrams/flowchart/elk/detector.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
import type {
ExternalDiagramDefinition,
DiagramDetector,
DiagramLoader,
ExternalDiagramDefinition,
} from '../../../diagram-api/types.js';
import { log } from '../../../logger.js';

const id = 'flowchart-elk';

const detector: DiagramDetector = (txt, config): boolean => {
const detector: DiagramDetector = (txt, config = {}): boolean => {
if (
// If diagram explicitly states flowchart-elk
/^\s*flowchart-elk/.test(txt) ||
// If a flowchart/graph diagram has their default renderer set to elk
(/^\s*flowchart|graph/.test(txt) && config?.flowchart?.defaultRenderer === 'elk')
) {
// This will log at the end, hopefully.
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
);
config.layout = 'elk';
return true;
}
return false;
};

const loader: DiagramLoader = async () => {
const { diagram } = await import('../flowDiagram-v2.js');
const { diagram } = await import('../flowDiagram.js');
return { id, diagram };
};

Expand Down
11 changes: 7 additions & 4 deletions packages/mermaid/src/diagrams/flowchart/flowDiagram.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// @ts-ignore: JISON doesn't support types
import flowParser from './parser/flow.jison';
import type { MermaidConfig } from '../../config.type.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';
import type { MermaidConfig } from '../../config.type.js';
import { setConfig } from '../../diagram-api/diagramAPI.js';

export const diagram = {
parser: flowParser,
Expand All @@ -15,6 +15,9 @@ export const diagram = {
if (!cnf.flowchart) {
cnf.flowchart = {};
}
if (cnf.layout) {
setConfig({ layout: cnf.layout });
}
cnf.flowchart.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
setConfig({ flowchart: { arrowMarkerAbsolute: cnf.arrowMarkerAbsolute } });
flowDb.clear();
Expand Down

0 comments on commit bc3fe33

Please sign in to comment.