Skip to content

Commit

Permalink
test: layout dendrogram (#5539)
Browse files Browse the repository at this point in the history
* test: layout dendrogram

* fix: resolve conversation
  • Loading branch information
lxfu1 authored Mar 15, 2024
1 parent 87621a4 commit 494779c
Show file tree
Hide file tree
Showing 11 changed files with 4,034 additions and 340 deletions.
2 changes: 2 additions & 0 deletions packages/g6/__tests__/demo/case/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export * from './layout-combo-combined';
export * from './layout-concentric';
export * from './layout-dagre-flow';
export * from './layout-dagre-flow-combo';
export * from './layout-dendrogram-basic';
export * from './layout-dendrogram-tb';
export * from './layout-force';
export * from './layout-fruchterman-basic';
export * from './layout-fruchterman-cluster';
Expand Down
34 changes: 34 additions & 0 deletions packages/g6/__tests__/demo/case/layout-dendrogram-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Graph, Utils } from '@/src';
import data from '@@/dataset/algorithm-category.json';
import type { STDTestCase } from '../types';

export const layoutDendrogramBasic: STDTestCase = async (context) => {
const graph = new Graph({
...context,
autoFit: 'view',
data: Utils.treeToGraphData(data),
node: {
style: {
labelText: (d) => d.id,
labelPlacement: (model) => (model.style!.children?.length ? 'left' : 'right'),
ports: [{ placement: 'right' }, { placement: 'left' }],
},
},
edge: {
style: {
type: 'cubic-horizontal',
},
},
layout: {
type: 'dendrogram',
direction: 'LR',
nodeSep: 36,
rankSep: 250,
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node', 'collapse-expand-tree'],
});

await graph.render();

return graph;
};
41 changes: 41 additions & 0 deletions packages/g6/__tests__/demo/case/layout-dendrogram-tb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Graph, Utils } from '@/src';
import data from '@@/dataset/algorithm-category.json';
import type { STDTestCase } from '../types';

export const layoutDendrogramTb: STDTestCase = async (context) => {
const graph = new Graph({
...context,
autoFit: 'view',
data: Utils.treeToGraphData(data),
node: {
style: (model) => {
const hasChildren = !!model.style!.children?.length;
return {
labelMaxWidth: 200,
labelPlacement: hasChildren ? 'right' : 'bottom',
labelText: model.id,
labelTextAlign: 'start',
labelTextBaseline: hasChildren ? 'middle' : 'bottom',
transform: hasChildren ? '' : 'rotate(90)',
ports: [{ placement: 'bottom' }, { placement: 'top' }],
};
},
},
edge: {
style: {
type: 'cubic-vertical',
},
},
layout: {
type: 'dendrogram',
direction: 'TB',
nodeSep: 40,
rankSep: 100,
},
behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node', 'collapse-expand-tree'],
});

await graph.render();

return graph;
};
Loading

0 comments on commit 494779c

Please sign in to comment.