mirror of
https://gitee.com/antv/g6.git
synced 2024-12-05 05:09:07 +08:00
radiallayout test spec detailed
This commit is contained in:
parent
607ebb0287
commit
9d0c3db76a
@ -99,7 +99,7 @@
|
||||
"prepublishOnly": "npm run build-lib && npm run build",
|
||||
"screenshot": "node ./bin/screenshot.js",
|
||||
"start": "npm run dev",
|
||||
"test": "torch --compile --renderer --opts test/mocha.opts --recursive ./test/unit/",
|
||||
"test": "torch --compile --renderer --opts test/mocha.opts --recursive ./test/unit",
|
||||
"test-live": "torch --compile --interactive --watch --opts test/mocha.opts --recursive ./test/unit/",
|
||||
"test-bugs": "torch --compile --renderer --recursive ./test/bugs",
|
||||
"test-bugs-live": "torch --compile --interactive --watch --recursive ./test/bugs",
|
||||
|
@ -20,20 +20,43 @@ describe('radial layout', () => {
|
||||
});
|
||||
fruch.initPlugin(graph);
|
||||
fruch.layout(data);
|
||||
expect(data.nodes[0].x != null);
|
||||
expect(data.nodes[0].x === 250);
|
||||
expect(data.nodes[0].x === 250);
|
||||
done();
|
||||
});
|
||||
|
||||
it('radial with fixed focusNode, unit radius, link length, and max iteration', done => {
|
||||
const unitRadius = 100;
|
||||
const radial = new Radial({
|
||||
center: [ 250, 250 ],
|
||||
maxIteration: 10000,
|
||||
focusNode: data.nodes[2],
|
||||
unitRadius: 100,
|
||||
unitRadius,
|
||||
linkDistance: 100
|
||||
});
|
||||
radial.initPlugin(graph);
|
||||
expect(data.nodes[0].x != null);
|
||||
expect(data.nodes[2].x === 250);
|
||||
expect(data.nodes[2].x === 250);
|
||||
const vx = data.nodes[0].x - data.nodes[2].x;
|
||||
const vy = data.nodes[0].y - data.nodes[2].y;
|
||||
const distToFocus = Math.sqrt(vx * vx, vy * vy);
|
||||
expect(distToFocus % unitRadius === 0);
|
||||
done();
|
||||
});
|
||||
|
||||
it('radial with fixed id focusNode', done => {
|
||||
const radial = new Radial({
|
||||
center: [ 250, 250 ],
|
||||
focusNode: 'Belgium'
|
||||
});
|
||||
let focusNodeIndex = -1;
|
||||
data.nodes.forEach((node, i) => {
|
||||
if (node.id === 'Belgium') focusNodeIndex = i;
|
||||
return;
|
||||
});
|
||||
radial.initPlugin(graph);
|
||||
expect(data.nodes[focusNodeIndex].x === 250);
|
||||
expect(data.nodes[focusNodeIndex].y === 250);
|
||||
done();
|
||||
});
|
||||
|
||||
@ -52,8 +75,14 @@ describe('radial layout', () => {
|
||||
{ source: '1', target: '2' },
|
||||
{ source: '0', target: '2' }
|
||||
];
|
||||
radial.updateLayout({ unitRadius: 80, linkDistance: 70, focusNode: data.nodes[1], data });
|
||||
expect(data.nodes[0].x != null);
|
||||
const newUnitRadius = 80;
|
||||
radial.updateLayout({ center: [ 100, 150 ], unitRadius: newUnitRadius, linkDistance: 70, focusNode: data.nodes[1], data });
|
||||
expect(data.nodes[0].x === 100);
|
||||
expect(data.nodes[0].x === 150);
|
||||
const vx = data.nodes[0].x - data.nodes[2].x;
|
||||
const vy = data.nodes[0].y - data.nodes[2].y;
|
||||
const distToFocus = Math.sqrt(vx * vx, vy * vy);
|
||||
expect(distToFocus % newUnitRadius === 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user