2019-12-30 01:21:15 +08:00
|
|
|
|
// 注意:这里不能直接require原始的src文件,而要使用build后的文件,因为web worker代码是通过worker-loader内联进来的
|
2019-12-31 12:05:28 +08:00
|
|
|
|
import G6 from '../../../dist/g6.min';
|
2019-12-30 01:21:15 +08:00
|
|
|
|
import data from './data';
|
|
|
|
|
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
div.id = 'force-layout-web-worker';
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
2020-01-09 15:16:20 +08:00
|
|
|
|
describe('force layout(web worker)', function() {
|
2019-12-30 12:00:25 +08:00
|
|
|
|
// this.timeout(10000);
|
2019-12-30 01:21:15 +08:00
|
|
|
|
|
2020-01-03 19:49:26 +08:00
|
|
|
|
it('force layout(web worker) with default configs', done => {
|
2019-12-30 01:21:15 +08:00
|
|
|
|
const node = data.nodes[0];
|
|
|
|
|
let count = 0;
|
|
|
|
|
let ended = false;
|
|
|
|
|
const graph = new G6.Graph({
|
|
|
|
|
container: div,
|
|
|
|
|
layout: {
|
|
|
|
|
type: 'force',
|
|
|
|
|
onTick() {
|
|
|
|
|
count++;
|
|
|
|
|
expect(node.x).not.toEqual(undefined);
|
|
|
|
|
expect(node.y).not.toEqual(undefined);
|
|
|
|
|
},
|
|
|
|
|
onLayoutEnd() {
|
|
|
|
|
ended = true;
|
|
|
|
|
},
|
|
|
|
|
// use web worker to layout
|
|
|
|
|
workerEnabled: true,
|
|
|
|
|
},
|
|
|
|
|
width: 500,
|
|
|
|
|
height: 500,
|
|
|
|
|
defaultNode: { size: 10 },
|
|
|
|
|
});
|
|
|
|
|
graph.data(data);
|
2020-01-03 19:49:26 +08:00
|
|
|
|
graph.render();
|
2019-12-30 01:21:15 +08:00
|
|
|
|
graph.on('afterlayout', () => {
|
|
|
|
|
expect(node.x).not.toEqual(undefined);
|
|
|
|
|
expect(node.y).not.toEqual(undefined);
|
2020-01-03 19:49:26 +08:00
|
|
|
|
expect(count >= 1).toEqual(true);
|
|
|
|
|
expect(ended).toEqual(true);
|
2019-12-30 01:21:15 +08:00
|
|
|
|
graph.destroy();
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|