Skip to content

Commit

Permalink
refactor: fix addVertex type parameter
Browse files Browse the repository at this point in the history
I went through
`packages/mermaid/src/diagrams/flowchart/parser/flow.jison` and found
every possible value this `type` parameter could be.
  • Loading branch information
aloisklink committed Oct 28, 2024
1 parent 7fa8b35 commit 17e2f9e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/mermaid/src/diagrams/flowchart/flowDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ import {
setDiagramTitle,
getDiagramTitle,
} from '../common/commonDb.js';
import type { FlowVertex, FlowClass, FlowSubGraph, FlowText, FlowEdge, FlowLink } from './types.js';
import type {
FlowVertex,
FlowClass,
FlowSubGraph,
FlowText,
FlowEdge,
FlowLink,
FlowVertexTypeParam,
} from './types.js';
import type { NodeMetaData } from '../../types.js';

const MERMAID_DOM_ID_PREFIX = 'flowchart-';
Expand Down Expand Up @@ -53,12 +61,11 @@ export const lookUpDomId = function (id: string) {

/**
* Function called by parser when a node definition has been found
*
*/
export const addVertex = function (
id: string,
textObj: FlowText,
type: 'group',
type: FlowVertexTypeParam,
style: string[],
classes: string[],
dir: string,
Expand Down
23 changes: 23 additions & 0 deletions packages/mermaid/src/diagrams/flowchart/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/**
* Valid `type` args to `yy.addVertex` taken from
* `packages/mermaid/src/diagrams/flowchart/parser/flow.jison`
*/
export type FlowVertexTypeParam =
| undefined
| 'square'
| 'doublecircle'
| 'circle'
| 'ellipse'
| 'stadium'
| 'subroutine'
| 'rect'
| 'cylinder'
| 'round'
| 'diamond'
| 'hexagon'
| 'odd'
| 'trapezoid'
| 'inv_trapezoid'
| 'lean_right'
| 'lean_left';

export interface FlowVertex {
classes: string[];
dir?: string;
Expand Down

0 comments on commit 17e2f9e

Please sign in to comment.