-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add fruchterman layout test (#5530)
* test: add fruchterman layout test * docs: add fruchterman demo * fix: eslint error * chore: fix cr * chore: remove unused code * chore: fix cr
- Loading branch information
Showing
29 changed files
with
10,259 additions
and
733 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/g6/__tests__/demo/case/layout-fruchterman-basic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const layoutFruchtermanBasic: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data, | ||
behaviors: ['drag-canvas', 'drag-node'], | ||
layout: { | ||
type: 'fruchterman', | ||
gravity: 5, | ||
speed: 5, | ||
}, | ||
node: { | ||
style: { | ||
size: 30, | ||
stroke: '#5B8FF9', | ||
fill: '#C6E5FF', | ||
lineWidth: 1, | ||
labelPlacement: 'center', | ||
labelText: (d: any) => d.id, | ||
labelBackground: false, | ||
}, | ||
}, | ||
}); | ||
|
||
await graph.render(); | ||
|
||
return graph; | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/g6/__tests__/demo/case/layout-fruchterman-cluster.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/cluster.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const layoutFruchtermanCluster: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data: { ...data, nodes: data.nodes.map((n) => ({ ...n, cluster: n.data.cluster })) }, | ||
behaviors: ['drag-canvas', 'drag-node'], | ||
layout: { | ||
type: 'fruchterman', | ||
gravity: 10, | ||
speed: 5, | ||
clustering: true, | ||
nodeClusterBy: 'cluster', | ||
}, | ||
node: { | ||
style: { | ||
size: 20, | ||
stroke: '#5B8FF9', | ||
fill: '#C6E5FF', | ||
lineWidth: 1, | ||
labelPlacement: 'center', | ||
labelText: (d: any) => d.id, | ||
labelBackground: false, | ||
}, | ||
}, | ||
edge: { | ||
style: { | ||
endArrow: true, | ||
endArrowPath: 'M 0,0 L 4,2 L 4,-2 Z', | ||
}, | ||
}, | ||
}); | ||
|
||
await graph.render(); | ||
|
||
return graph; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Graph } from '@/src'; | ||
import data from '@@/dataset/relations.json'; | ||
import type { STDTestCase } from '../types'; | ||
|
||
export const layoutFruchtermanFix: STDTestCase = async (context) => { | ||
const graph = new Graph({ | ||
...context, | ||
data, | ||
behaviors: ['drag-canvas', 'drag-node'], | ||
layout: { | ||
type: 'fruchterman', | ||
speed: 10, | ||
maxIteration: 500, | ||
}, | ||
node: { | ||
style: { | ||
size: 15, | ||
stroke: '#5B8FF9', | ||
fill: '#C6E5FF', | ||
lineWidth: 1, | ||
}, | ||
}, | ||
edge: { | ||
style: { | ||
stroke: '#E2E2E2', | ||
}, | ||
}, | ||
}); | ||
|
||
graph.on('node:dragstart', function () { | ||
graph.stopLayout(); | ||
}); | ||
|
||
graph.on('node:dragend', function () { | ||
// FIXME: 不应该完全重新布局,而是以当前画布数据进行布局 | ||
graph.layout(); | ||
}); | ||
|
||
await graph.render(); | ||
|
||
return graph; | ||
}; |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.