-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5237 Sample orchestration of new flow in state diagrams-v3
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/mermaid/src/diagrams/state/stateDiagram-v3-unified.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
packages/mermaid/src/diagrams/state/stateRenderer-v3-unified.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |