mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-10-31 10:54:15 +01:00 
			
		
		
		
	Merge branch 'develop' of https://github.com/mermaid-js/mermaid into knsv/new-shapes
This commit is contained in:
		| @@ -120,6 +120,8 @@ SUBROUTINEEND | |||||||
| SUBROUTINESTART | SUBROUTINESTART | ||||||
| Subschemas | Subschemas | ||||||
| substr | substr | ||||||
|  | SVGG | ||||||
|  | SVGSVG | ||||||
| TAGEND | TAGEND | ||||||
| TAGSTART | TAGSTART | ||||||
| techn | techn | ||||||
|   | |||||||
| @@ -84,17 +84,20 @@ | |||||||
|     <div class="flex"> |     <div class="flex"> | ||||||
|       <pre id="diagram" class="mermaid"> |       <pre id="diagram" class="mermaid"> | ||||||
| --- | --- | ||||||
| config: |   title: hello2 | ||||||
|   look: handDrawn |   config: | ||||||
|   layout: elk |     look: handDrawn | ||||||
|   elk: |     layout: elk | ||||||
|  |     elk: | ||||||
|         nodePlacementStrategy: BRANDES_KOEPF |         nodePlacementStrategy: BRANDES_KOEPF | ||||||
| --- | --- | ||||||
| flowchart TB | flowchart LR | ||||||
|     %% A --> C |   A[Start] --Some text--> B(Continue) | ||||||
|     B -- sdf sdf --> C{"Evaluate"} |   B --> C{Evaluate} | ||||||
|     C --> n4["salkdfjh akljd lkasdjf lkashj lksjadf klasdh"] |   C -- One --> D[Option 1] | ||||||
|     C --> F |   C -- Two --> E[Option 2] | ||||||
|  |   C -- Three --> F[fa:fa-car Option 3] | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| </pre | </pre | ||||||
|   | |||||||
| @@ -6,7 +6,6 @@ import { type TreeData, findCommonAncestor } from './find-common-ancestor.js'; | |||||||
| export const render = async ( | export const render = async ( | ||||||
|   data4Layout: LayoutData, |   data4Layout: LayoutData, | ||||||
|   svg: SVG, |   svg: SVG, | ||||||
|   element: any, |  | ||||||
|   { |   { | ||||||
|     common, |     common, | ||||||
|     getConfig, |     getConfig, | ||||||
| @@ -377,6 +376,7 @@ export const render = async ( | |||||||
|  |  | ||||||
|         // calculate start and end points of the edge, note that the source and target |         // calculate start and end points of the edge, note that the source and target | ||||||
|         // can be modified for shapes that have ports |         // can be modified for shapes that have ports | ||||||
|  |         // @ts-ignore TODO: fix this | ||||||
|         const { source, target, sourceId, targetId } = getEdgeStartEndPoint(edge, dir); |         const { source, target, sourceId, targetId } = getEdgeStartEndPoint(edge, dir); | ||||||
|         log.debug('abc78 source and target', source, target); |         log.debug('abc78 source and target', source, target); | ||||||
|         // Add the edge to the graph |         // Add the edge to the graph | ||||||
| @@ -739,7 +739,7 @@ export const render = async ( | |||||||
|  |  | ||||||
|   // @ts-ignore - ELK is not typed |   // @ts-ignore - ELK is not typed | ||||||
|   const elk = new ELK(); |   const elk = new ELK(); | ||||||
|  |   const element = svg.select('g'); | ||||||
|   // Add the arrowheads to the svg |   // Add the arrowheads to the svg | ||||||
|   insertMarkers(element, data4Layout.markers, data4Layout.type, data4Layout.diagramId); |   insertMarkers(element, data4Layout.markers, data4Layout.type, data4Layout.diagramId); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ import { select } from 'd3'; | |||||||
| import { getConfig } from '../../diagram-api/diagramAPI.js'; | import { getConfig } from '../../diagram-api/diagramAPI.js'; | ||||||
| import type { DiagramStyleClassDef } from '../../diagram-api/types.js'; | import type { DiagramStyleClassDef } from '../../diagram-api/types.js'; | ||||||
| import { log } from '../../logger.js'; | import { log } from '../../logger.js'; | ||||||
| import { getDiagramElements } from '../../rendering-util/insertElementsForSize.js'; | import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js'; | ||||||
| import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js'; | import { getRegisteredLayoutAlgorithm, render } from '../../rendering-util/render.js'; | ||||||
| import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; | import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; | ||||||
| import type { LayoutData } from '../../rendering-util/types.js'; | import type { LayoutData } from '../../rendering-util/types.js'; | ||||||
| @@ -35,8 +35,8 @@ export const draw = async function (text: string, id: string, _version: string, | |||||||
|   log.debug('Before getData: '); |   log.debug('Before getData: '); | ||||||
|   const data4Layout = diag.db.getData() as LayoutData; |   const data4Layout = diag.db.getData() as LayoutData; | ||||||
|   log.debug('Data: ', data4Layout); |   log.debug('Data: ', data4Layout); | ||||||
|   // Create the root SVG - the element is the div containing the SVG element |   // Create the root SVG | ||||||
|   const { element, svg } = getDiagramElements(id, securityLevel); |   const svg = getDiagramElement(id, securityLevel); | ||||||
|   const direction = getDirection(); |   const direction = getDirection(); | ||||||
|  |  | ||||||
|   data4Layout.type = diag.type; |   data4Layout.type = diag.type; | ||||||
| @@ -53,7 +53,7 @@ export const draw = async function (text: string, id: string, _version: string, | |||||||
|  |  | ||||||
|   data4Layout.diagramId = id; |   data4Layout.diagramId = id; | ||||||
|   log.debug('REF1:', data4Layout); |   log.debug('REF1:', data4Layout); | ||||||
|   await render(data4Layout, svg, element); |   await render(data4Layout, svg); | ||||||
|   const padding = data4Layout.config.flowchart?.padding ?? 8; |   const padding = data4Layout.config.flowchart?.padding ?? 8; | ||||||
|   utils.insertTitle( |   utils.insertTitle( | ||||||
|     svg, |     svg, | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| import { getConfig } from '../../diagram-api/diagramAPI.js'; | import { getConfig } from '../../diagram-api/diagramAPI.js'; | ||||||
| import type { DiagramStyleClassDef } from '../../diagram-api/types.js'; | import type { DiagramStyleClassDef } from '../../diagram-api/types.js'; | ||||||
| import { log } from '../../logger.js'; | import { log } from '../../logger.js'; | ||||||
| import { getDiagramElements } from '../../rendering-util/insertElementsForSize.js'; | import { getDiagramElement } from '../../rendering-util/insertElementsForSize.js'; | ||||||
| import { render } from '../../rendering-util/render.js'; | import { render } from '../../rendering-util/render.js'; | ||||||
| import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; | import { setupViewPortForSVG } from '../../rendering-util/setupViewPortForSVG.js'; | ||||||
| import type { LayoutData } from '../../rendering-util/types.js'; | import type { LayoutData } from '../../rendering-util/types.js'; | ||||||
| @@ -55,7 +55,7 @@ export const draw = async function (text: string, id: string, _version: string, | |||||||
|   const data4Layout = diag.db.getData() as LayoutData; |   const data4Layout = diag.db.getData() as LayoutData; | ||||||
|  |  | ||||||
|   // Create the root SVG - the element is the div containing the SVG element |   // Create the root SVG - the element is the div containing the SVG element | ||||||
|   const { element, svg } = getDiagramElements(id, securityLevel); |   const svg = getDiagramElement(id, securityLevel); | ||||||
|  |  | ||||||
|   data4Layout.type = diag.type; |   data4Layout.type = diag.type; | ||||||
|   data4Layout.layoutAlgorithm = layout; |   data4Layout.layoutAlgorithm = layout; | ||||||
| @@ -67,10 +67,10 @@ export const draw = async function (text: string, id: string, _version: string, | |||||||
|   data4Layout.markers = ['barb']; |   data4Layout.markers = ['barb']; | ||||||
|   data4Layout.diagramId = id; |   data4Layout.diagramId = id; | ||||||
|   // console.log('REF1:', data4Layout); |   // console.log('REF1:', data4Layout); | ||||||
|   await render(data4Layout, svg, element); |   await render(data4Layout, svg); | ||||||
|   const padding = 8; |   const padding = 8; | ||||||
|   utils.insertTitle( |   utils.insertTitle( | ||||||
|     element, |     svg, | ||||||
|     'statediagramTitleText', |     'statediagramTitleText', | ||||||
|     conf?.titleTopMargin ?? 25, |     conf?.titleTopMargin ?? 25, | ||||||
|     diag.db.getDiagramTitle() |     diag.db.getDiagramTitle() | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| import { select } from 'd3'; | import { select } from 'd3'; | ||||||
| import { insertNode } from '../dagre-wrapper/nodes.js'; | import { insertNode } from '../dagre-wrapper/nodes.js'; | ||||||
|  |  | ||||||
| export const getDiagramElements = (id, securityLevel) => { | export const getDiagramElement = (id, securityLevel) => { | ||||||
|   let sandboxElement; |   let sandboxElement; | ||||||
|   if (securityLevel === 'sandbox') { |   if (securityLevel === 'sandbox') { | ||||||
|     sandboxElement = select('#i' + id); |     sandboxElement = select('#i' + id); | ||||||
| @@ -15,9 +15,7 @@ export const getDiagramElements = (id, securityLevel) => { | |||||||
|  |  | ||||||
|   // Run the renderer. This is what draws the final graph. |   // Run the renderer. This is what draws the final graph. | ||||||
|  |  | ||||||
|   // @ts-ignore todo: fix this |   return svg; | ||||||
|   const element = root.select('#' + id + ' g'); |  | ||||||
|   return { svg, element }; |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export function insertElementsForSize(el, data) { | export function insertElementsForSize(el, data) { | ||||||
|   | |||||||
| @@ -268,7 +268,7 @@ const recursiveRender = async (_elem, graph, diagramType, id, parentCluster, sit | |||||||
|   return { elem, diff }; |   return { elem, diff }; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const render = async (data4Layout, svg, element) => { | export const render = async (data4Layout, svg) => { | ||||||
|   const graph = new graphlib.Graph({ |   const graph = new graphlib.Graph({ | ||||||
|     multigraph: true, |     multigraph: true, | ||||||
|     compound: true, |     compound: true, | ||||||
| @@ -289,7 +289,7 @@ export const render = async (data4Layout, svg, element) => { | |||||||
|     .setDefaultEdgeLabel(function () { |     .setDefaultEdgeLabel(function () { | ||||||
|       return {}; |       return {}; | ||||||
|     }); |     }); | ||||||
|  |   const element = svg.select('g'); | ||||||
|   insertMarkers(element, data4Layout.markers, data4Layout.type, data4Layout.diagramId); |   insertMarkers(element, data4Layout.markers, data4Layout.type, data4Layout.diagramId); | ||||||
|   clearNodes(); |   clearNodes(); | ||||||
|   clearEdges(); |   clearEdges(); | ||||||
|   | |||||||
| @@ -12,7 +12,6 @@ export interface LayoutAlgorithm { | |||||||
|   render( |   render( | ||||||
|     layoutData: LayoutData, |     layoutData: LayoutData, | ||||||
|     svg: SVG, |     svg: SVG, | ||||||
|     element: any, |  | ||||||
|     helpers: InternalHelpers, |     helpers: InternalHelpers, | ||||||
|     options?: RenderOptions |     options?: RenderOptions | ||||||
|   ): Promise<void>; |   ): Promise<void>; | ||||||
| @@ -45,14 +44,14 @@ const registerDefaultLayoutLoaders = () => { | |||||||
|  |  | ||||||
| registerDefaultLayoutLoaders(); | registerDefaultLayoutLoaders(); | ||||||
|  |  | ||||||
| export const render = async (data4Layout: LayoutData, svg: SVG, element: any) => { | export const render = async (data4Layout: LayoutData, svg: SVG) => { | ||||||
|   if (!(data4Layout.layoutAlgorithm in layoutAlgorithms)) { |   if (!(data4Layout.layoutAlgorithm in layoutAlgorithms)) { | ||||||
|     throw new Error(`Unknown layout algorithm: ${data4Layout.layoutAlgorithm}`); |     throw new Error(`Unknown layout algorithm: ${data4Layout.layoutAlgorithm}`); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm]; |   const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm]; | ||||||
|   const layoutRenderer = await layoutDefinition.loader(); |   const layoutRenderer = await layoutDefinition.loader(); | ||||||
|   return layoutRenderer.render(data4Layout, svg, element, internalHelpers, { |   return layoutRenderer.render(data4Layout, svg, internalHelpers, { | ||||||
|     algorithm: layoutDefinition.algorithm, |     algorithm: layoutDefinition.algorithm, | ||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 saurabhg772244
					saurabhg772244