mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-28 07:03:17 +08:00
fix: Type of render
Make optional parameter an object
This commit is contained in:
parent
037ba2fa9c
commit
3593fa63db
@ -1,17 +1,11 @@
|
||||
import { curveLinear } from 'd3';
|
||||
import ELK from 'elkjs/lib/elk.bundled.js';
|
||||
import type { InternalHelpers, LayoutData } from 'mermaid';
|
||||
import type { InternalHelpers, LayoutData, RenderOptions, SVG, SVGGroup } from 'mermaid';
|
||||
import { type TreeData, findCommonAncestor } from './find-common-ancestor.js';
|
||||
|
||||
export const render = async (
|
||||
data4Layout: LayoutData,
|
||||
svg: {
|
||||
insert: (arg0: string) => {
|
||||
(): any;
|
||||
new (): any;
|
||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
||||
};
|
||||
},
|
||||
svg: SVG,
|
||||
element: any,
|
||||
{
|
||||
common,
|
||||
@ -26,7 +20,7 @@ export const render = async (
|
||||
log,
|
||||
positionEdgeLabel,
|
||||
}: InternalHelpers,
|
||||
algorithm: any
|
||||
{ algorithm }: RenderOptions
|
||||
) => {
|
||||
const nodeDb: Record<string, any> = {};
|
||||
const portPos: Record<string, any> = {};
|
||||
@ -135,13 +129,7 @@ export const render = async (
|
||||
relY: number,
|
||||
nodeArray: any[],
|
||||
svg: any,
|
||||
subgraphsEl: {
|
||||
insert: (arg0: string) => {
|
||||
(): any;
|
||||
new (): any;
|
||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
||||
};
|
||||
},
|
||||
subgraphsEl: SVGGroup,
|
||||
depth: number
|
||||
) => {
|
||||
await Promise.all(
|
||||
@ -338,13 +326,7 @@ export const render = async (
|
||||
children?: never[];
|
||||
edges: any;
|
||||
},
|
||||
svg: {
|
||||
insert: (arg0: string) => {
|
||||
(): any;
|
||||
new (): any;
|
||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
||||
};
|
||||
}
|
||||
svg: SVG
|
||||
) {
|
||||
log.info('abc78 DAGA edges = ', dataForLayout);
|
||||
const edges = dataForLayout.edges;
|
||||
|
@ -1,14 +1,21 @@
|
||||
import type { SVG } from '$root/diagram-api/types.js';
|
||||
import type { InternalHelpers } from '$root/internals.js';
|
||||
import { internalHelpers } from '$root/internals.js';
|
||||
import { log } from '$root/logger.js';
|
||||
import type { LayoutData } from './types.js';
|
||||
|
||||
export interface RenderOptions {
|
||||
algorithm?: string;
|
||||
}
|
||||
|
||||
export interface LayoutAlgorithm {
|
||||
render(
|
||||
data4Layout: any,
|
||||
svg: any,
|
||||
layoutData: LayoutData,
|
||||
svg: SVG,
|
||||
element: any,
|
||||
helpers: typeof internalHelpers,
|
||||
algorithm?: string
|
||||
): any;
|
||||
helpers: InternalHelpers,
|
||||
options?: RenderOptions
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
||||
@ -38,20 +45,16 @@ const registerDefaultLayoutLoaders = () => {
|
||||
|
||||
registerDefaultLayoutLoaders();
|
||||
|
||||
export const render = async (data4Layout: any, svg: any, element: any) => {
|
||||
export const render = async (data4Layout: LayoutData, svg: SVG, element: any) => {
|
||||
if (!(data4Layout.layoutAlgorithm in layoutAlgorithms)) {
|
||||
throw new Error(`Unknown layout algorithm: ${data4Layout.layoutAlgorithm}`);
|
||||
}
|
||||
|
||||
const layoutDefinition = layoutAlgorithms[data4Layout.layoutAlgorithm];
|
||||
const layoutRenderer = await layoutDefinition.loader();
|
||||
return layoutRenderer.render(
|
||||
data4Layout,
|
||||
svg,
|
||||
element,
|
||||
internalHelpers,
|
||||
layoutDefinition.algorithm
|
||||
);
|
||||
return layoutRenderer.render(data4Layout, svg, element, internalHelpers, {
|
||||
algorithm: layoutDefinition.algorithm,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user