2019-12-30 01:21:15 +08:00
|
|
|
import G6 from '../../../src';
|
2020-04-24 18:23:07 +08:00
|
|
|
import dataset from './data';
|
|
|
|
|
|
|
|
const data = dataset.data;
|
2019-12-30 01:21:15 +08:00
|
|
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.id = 'mds-layout';
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
2020-01-09 15:16:20 +08:00
|
|
|
describe('mds', () => {
|
2019-12-30 01:21:15 +08:00
|
|
|
it('mds layout with default configs', () => {
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
layout: {
|
|
|
|
type: 'mds',
|
|
|
|
},
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
2020-01-03 19:49:26 +08:00
|
|
|
defaultNode: {
|
2020-02-14 10:10:54 +08:00
|
|
|
size: 10,
|
|
|
|
},
|
2019-12-30 01:21:15 +08:00
|
|
|
});
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
|
|
|
expect(data.nodes[0].x != null).toEqual(true);
|
|
|
|
graph.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('mds with fixed link length', () => {
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
layout: {
|
|
|
|
type: 'mds',
|
|
|
|
center: [250, 250],
|
|
|
|
linkDistance: 120,
|
|
|
|
},
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
});
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
|
|
|
expect(data.nodes[0].x != null).toEqual(true);
|
|
|
|
graph.destroy();
|
|
|
|
});
|
2020-01-03 19:49:26 +08:00
|
|
|
|
|
|
|
it('mds layout with no node', () => {
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
layout: {
|
|
|
|
type: 'mds',
|
|
|
|
},
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
});
|
|
|
|
graph.data({
|
2020-02-14 10:10:54 +08:00
|
|
|
nodes: [],
|
2020-01-03 19:49:26 +08:00
|
|
|
});
|
|
|
|
graph.render();
|
|
|
|
graph.destroy();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('mds layout with one node', () => {
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
layout: {
|
|
|
|
type: 'mds',
|
|
|
|
},
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
});
|
|
|
|
graph.data({
|
2020-02-14 10:10:54 +08:00
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node',
|
|
|
|
},
|
|
|
|
],
|
2020-01-03 19:49:26 +08:00
|
|
|
});
|
|
|
|
graph.render();
|
|
|
|
const nodeModel = graph.getNodes()[0].getModel();
|
|
|
|
expect(nodeModel.x).toEqual(250);
|
|
|
|
expect(nodeModel.y).toEqual(250);
|
|
|
|
graph.destroy();
|
|
|
|
});
|
|
|
|
it('mds layout with unconnected graph', () => {
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
layout: {
|
|
|
|
type: 'mds',
|
|
|
|
},
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
defaultNode: {
|
2020-02-14 10:10:54 +08:00
|
|
|
size: 10,
|
|
|
|
},
|
2020-01-03 19:49:26 +08:00
|
|
|
});
|
|
|
|
graph.data({
|
2020-02-14 10:10:54 +08:00
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node0',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'node1',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'node2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
edges: [
|
|
|
|
{
|
|
|
|
source: 'node0',
|
|
|
|
target: 'node1',
|
|
|
|
},
|
|
|
|
],
|
2020-01-03 19:49:26 +08:00
|
|
|
});
|
|
|
|
graph.render();
|
|
|
|
// const nodeModel = graph.getNodes()[0].getModel();
|
|
|
|
// expect(nodeModel.x).toEqual(250);
|
|
|
|
// expect(nodeModel.y).toEqual(250);
|
|
|
|
// graph.destroy();
|
|
|
|
});
|
2019-12-30 01:21:15 +08:00
|
|
|
});
|