mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 19:58:46 +08:00
test: forceAtalas2 test case
This commit is contained in:
parent
0c1d1e1c47
commit
62890e452a
@ -97,7 +97,7 @@
|
||||
"screenshot": "node ./bin/screenshot.js",
|
||||
"start": "npm run dev",
|
||||
"test": "torch --compile --renderer --recursive ./test/unit",
|
||||
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/",
|
||||
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/plugins/",
|
||||
"watch": "webpack --config webpack-dev.config.js",
|
||||
"win-dev": "node ./bin/win-dev.js"
|
||||
},
|
||||
|
132
test/unit/plugins/layout.forceAtlas2-spec.js
Normal file
132
test/unit/plugins/layout.forceAtlas2-spec.js
Normal file
@ -0,0 +1,132 @@
|
||||
const G6 = require('../../../src/index');
|
||||
const Layout = require('../../../plugins/layout.forceAtlas2/');
|
||||
const expect = require('chai').expect;
|
||||
const Util = G6.Util;
|
||||
|
||||
document.body.appendChild(Util.createDOM(`
|
||||
<div id='mountNode'></div>
|
||||
`));
|
||||
|
||||
describe('custom layout test', () => {
|
||||
const layout = new Layout();
|
||||
const data = {
|
||||
nodes: [{
|
||||
id: 'node1'
|
||||
}, {
|
||||
id: 'node2'
|
||||
}, {
|
||||
id: 'node3'
|
||||
}],
|
||||
edges: [{
|
||||
target: 'node2',
|
||||
source: 'node1'
|
||||
}, {
|
||||
target: 'node2',
|
||||
source: 'node3'
|
||||
}]
|
||||
};
|
||||
const graph = new G6.Graph({
|
||||
container: 'mountNode',
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [ layout ]
|
||||
});
|
||||
|
||||
graph.read(data);
|
||||
it('layout node positions', () => {
|
||||
const node1Model = graph.find('node1').getModel();
|
||||
expect(node1Model.x).not.eql(undefined);
|
||||
expect(node1Model.y).not.eql(undefined);
|
||||
});
|
||||
it('graph destroy', () => {
|
||||
graph.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('node nonoverlapping test', () => {
|
||||
const layout = new Layout({ prevOverlapping: true });
|
||||
const data = {
|
||||
nodes: [{
|
||||
id: 'node1'
|
||||
}, {
|
||||
id: 'node2'
|
||||
}, {
|
||||
id: 'node3'
|
||||
}],
|
||||
edges: [{
|
||||
target: 'node2',
|
||||
source: 'node1'
|
||||
}, {
|
||||
target: 'node2',
|
||||
source: 'node3'
|
||||
}]
|
||||
};
|
||||
const graph = new G6.Graph({
|
||||
container: 'mountNode',
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [ layout ]
|
||||
});
|
||||
graph.read(data);
|
||||
it('overlapping', () => {
|
||||
const node1Model = graph.find('node1').getModel();
|
||||
const node2Model = graph.find('node2').getModel();
|
||||
const node3Model = graph.find('node3').getModel();
|
||||
const node1BBox = node1Model.getBBox();
|
||||
const node2BBox = node2Model.getBBox();
|
||||
const node3BBox = node3Model.getBBox();
|
||||
const node1Radius = (node1BBox.maxX - node1BBox.minX) / 2;
|
||||
const node2Radius = (node2BBox.maxX - node2BBox.minX) / 2;
|
||||
const node3Radius = (node3BBox.maxX - node3BBox.minX) / 2;
|
||||
const dist12 = Math.plot(node1Model.x - node2Model.x, node1Model.y - node2Model.y);
|
||||
const dist23 = Math.plot(node2Model.x - node3Model.x, node2Model.y - node3Model.y);
|
||||
const dist13 = Math.plot(node1Model.x - node3Model.x, node1Model.y - node3Model.y);
|
||||
expect(node1Radius - node2Radius <= dist12).eql(true);
|
||||
expect(node2Radius - node3Radius <= dist23).eql(true);
|
||||
expect(node1Radius - node3Radius <= dist13).eql(true);
|
||||
});
|
||||
it('layout node positions', () => {
|
||||
const node1Model = graph.find('node1').getModel();
|
||||
expect(node1Model.x).not.eql(undefined);
|
||||
expect(node1Model.y).not.eql(undefined);
|
||||
});
|
||||
it('graph destroy', () => {
|
||||
graph.destroy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('barnes hut optimiazation test', () => {
|
||||
const layout = new Layout();
|
||||
const data = {
|
||||
nodes: [{
|
||||
id: 'node1'
|
||||
}, {
|
||||
id: 'node2'
|
||||
}, {
|
||||
id: 'node3'
|
||||
}],
|
||||
edges: [{
|
||||
target: 'node2',
|
||||
source: 'node1'
|
||||
}, {
|
||||
target: 'node2',
|
||||
source: 'node3'
|
||||
}]
|
||||
};
|
||||
const graph = new G6.Graph({
|
||||
container: 'mountNode',
|
||||
width: 500,
|
||||
height: 500,
|
||||
plugins: [ layout ]
|
||||
});
|
||||
|
||||
graph.read(data);
|
||||
it('layout node positions', () => {
|
||||
const node1Model = graph.find('node1').getModel();
|
||||
expect(node1Model.x).not.eql(undefined);
|
||||
expect(node1Model.y).not.eql(undefined);
|
||||
});
|
||||
it('graph destroy', () => {
|
||||
graph.destroy();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user