Skip to content

Commit

Permalink
#5237 Sample orchestration of new flow in state diagrams-v3
Browse files Browse the repository at this point in the history
  • Loading branch information
knsv committed Mar 18, 2024
1 parent b7c72cb commit fcda3dc
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/mermaid/src/diagrams/state/stateDiagram-v3-unified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { DiagramDefinition } from '../../diagram-api/types.js';
// @ts-ignore: JISON doesn't support types
import parser from './parser/stateDiagram.jison';
import db from './stateDb.js';
import styles from './styles.js';
import renderer from './stateRenderer-v3-unified.js';

export const diagram: DiagramDefinition = {
parser,
db,
renderer,
styles,
init: (cnf) => {
if (!cnf.state) {
cnf.state = {};
}
cnf.state.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
db.clear();
},
};
67 changes: 67 additions & 0 deletions packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { log } from '../../logger.js';
import type { DiagramStyleClassDef } from '../../diagram-api/types.js';

interface LayoutData {}
interface RenderData {}
type LayoutMethod =
| 'dagre'
| 'dagre-wrapper'
| 'elk'
| 'neato'
| 'dot'
| 'circo'
| 'fdp'
| 'osage'
| 'grid';

const performLayout = (
layoutData: LayoutData,
id: string,
_version: string,
layoutMethod: LayoutMethod
): RenderData => {
return {};
};
const performRender = (data: RenderData) => {};

// Configuration
const conf: Record<string, any> = {};

export const setConf = function (cnf: Record<string, any>) {
const keys = Object.keys(cnf);
for (const key of keys) {
conf[key] = cnf[key];
}
};

export const getClasses = function (
text: string,
diagramObj: any
): Record<string, DiagramStyleClassDef> {
diagramObj.db.extract(diagramObj.db.getRootDocV2());
return diagramObj.db.getClasses();
};

export const draw = async function (text: string, id: string, _version: string, diag: any) {
log.info('Drawing state diagram (v2)', id);

// Extracting the data from the parsed structure into a more usable form
// Not related to the refactoring, but this is the first step in the rendering process
diag.db.extract(diag.db.getRootDocV2());

// The getData method provided in all supported diagrams is used to extract the data from the parsed structure
// into the Layout data format
const data4Layout = diag.db.getData();

// For some diagrams this call is not needed, but in the state diagram it is
const data4Rendering = performLayout(data4Layout, id, _version, 'dagre-wrapper');

// The performRender method provided in all supported diagrams is used to render the data
performRender(data4Rendering);
};

export default {
setConf,
getClasses,
draw,
};

0 comments on commit fcda3dc

Please sign in to comment.