所有布局都在 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}'
);