所有布局都在 LayoutService 中声明projects/swimlane/ngx-graph/src/lib/graph/layouts/layout.service.ts
我可以创建一个新的布局,但 LayoutService#getLayout(( 无法发现新的布局。
const layouts = {
dagre: DagreLayout,
dagreCluster: DagreClusterLayout,
dagreNodesOnly: DagreNodesOnlyLayout,
d3ForceDirected: D3ForceDirectedLayout,
colaForceDirected: ColaForceDirectedLayout
};
@Injectable()
export class LayoutService {
getLayout(name: string): Layout {
if (layouts[name]) {
return new layouts[name]();
} else {
throw new Error(`Unknown layout type '${name}'`);
}
}
}
我得到:抛出新的错误(Unknown layout type '${name}'
(;
也在这里发布我的答案:
您需要使用 Layout 接口实现一个类,然后从该类创建一个对象,并将该对象传递给布局输入而不是字符串。
下面是一个演示如何执行此操作的组件:https://github.com/swimlane/ngx-graph/blob/master/src/docs/demos/components/ngx-graph-custom-curve/ngx-graph-custom-curve.component.ts#L15