Skip to content

Commit

Permalink
feat:add subLayout method
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Feb 8, 2021
1 parent 8df518e commit 66b9cca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/graphin/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import processEdges from './processEdges';
import { deepMix } from '@antv/util';
import uuid from './uuid';
import walk from './walk';
import subLayout from './subLayout';
import { layouts } from '../layout/utils/options';

export default {
hexToRgba,
Expand All @@ -24,4 +26,6 @@ export default {
uuid,
walk,
processEdges,
subLayout,
layouts,
};
26 changes: 26 additions & 0 deletions packages/graphin/src/utils/subLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Layout } from '@antv/layout';
import { GraphinData } from '../typings/type';

const subLayout = () => {
const newData: GraphinData = {
nodes: [],
edges: [],
combos: null,
};
return {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
add: (data: GraphinData, layout: any) => {
const layoutInstance = new Layout(layout);
// TODO:计算数据中最小包围盒,从而计算布局所需要的中心点和宽高
// @ts-ignore
const subData = layoutInstance.layout(data) as GraphinData;
newData.nodes = [...newData.nodes, ...subData.nodes];
newData.edges = [...newData.edges, ...subData.edges];
},
layout: () => {
return newData;
},
};
};

export default subLayout;

0 comments on commit 66b9cca

Please sign in to comment.