mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +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 { curveLinear } from 'd3';
|
||||||
import ELK from 'elkjs/lib/elk.bundled.js';
|
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';
|
import { type TreeData, findCommonAncestor } from './find-common-ancestor.js';
|
||||||
|
|
||||||
export const render = async (
|
export const render = async (
|
||||||
data4Layout: LayoutData,
|
data4Layout: LayoutData,
|
||||||
svg: {
|
svg: SVG,
|
||||||
insert: (arg0: string) => {
|
|
||||||
(): any;
|
|
||||||
new (): any;
|
|
||||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
|
||||||
};
|
|
||||||
},
|
|
||||||
element: any,
|
element: any,
|
||||||
{
|
{
|
||||||
common,
|
common,
|
||||||
@ -26,7 +20,7 @@ export const render = async (
|
|||||||
log,
|
log,
|
||||||
positionEdgeLabel,
|
positionEdgeLabel,
|
||||||
}: InternalHelpers,
|
}: InternalHelpers,
|
||||||
algorithm: any
|
{ algorithm }: RenderOptions
|
||||||
) => {
|
) => {
|
||||||
const nodeDb: Record<string, any> = {};
|
const nodeDb: Record<string, any> = {};
|
||||||
const portPos: Record<string, any> = {};
|
const portPos: Record<string, any> = {};
|
||||||
@ -135,13 +129,7 @@ export const render = async (
|
|||||||
relY: number,
|
relY: number,
|
||||||
nodeArray: any[],
|
nodeArray: any[],
|
||||||
svg: any,
|
svg: any,
|
||||||
subgraphsEl: {
|
subgraphsEl: SVGGroup,
|
||||||
insert: (arg0: string) => {
|
|
||||||
(): any;
|
|
||||||
new (): any;
|
|
||||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
|
||||||
};
|
|
||||||
},
|
|
||||||
depth: number
|
depth: number
|
||||||
) => {
|
) => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
@ -338,13 +326,7 @@ export const render = async (
|
|||||||
children?: never[];
|
children?: never[];
|
||||||
edges: any;
|
edges: any;
|
||||||
},
|
},
|
||||||
svg: {
|
svg: SVG
|
||||||
insert: (arg0: string) => {
|
|
||||||
(): any;
|
|
||||||
new (): any;
|
|
||||||
attr: { (arg0: string, arg1: string): any; new (): any };
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
log.info('abc78 DAGA edges = ', dataForLayout);
|
log.info('abc78 DAGA edges = ', dataForLayout);
|
||||||
const edges = dataForLayout.edges;
|
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 { internalHelpers } from '$root/internals.js';
|
||||||
import { log } from '$root/logger.js';
|
import { log } from '$root/logger.js';
|
||||||
|
import type { LayoutData } from './types.js';
|
||||||
|
|
||||||
|
export interface RenderOptions {
|
||||||
|
algorithm?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface LayoutAlgorithm {
|
export interface LayoutAlgorithm {
|
||||||
render(
|
render(
|
||||||
data4Layout: any,
|
layoutData: LayoutData,
|
||||||
svg: any,
|
svg: SVG,
|
||||||
element: any,
|
element: any,
|
||||||
helpers: typeof internalHelpers,
|
helpers: InternalHelpers,
|
||||||
algorithm?: string
|
options?: RenderOptions
|
||||||
): any;
|
): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
export type LayoutLoader = () => Promise<LayoutAlgorithm>;
|
||||||
@ -38,20 +45,16 @@ const registerDefaultLayoutLoaders = () => {
|
|||||||
|
|
||||||
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)) {
|
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(
|
return layoutRenderer.render(data4Layout, svg, element, internalHelpers, {
|
||||||
data4Layout,
|
algorithm: layoutDefinition.algorithm,
|
||||||
svg,
|
});
|
||||||
element,
|
|
||||||
internalHelpers,
|
|
||||||
layoutDefinition.algorithm
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user