2019-12-30 01:21:15 +08:00
|
|
|
|
// 注意:这里不能直接require原始的src文件,而要使用build后的文件,因为web worker代码是通过worker-loader内联进来的
|
2020-02-07 18:26:39 +08:00
|
|
|
|
import G6 from '../../../dist/g6.min';
|
2020-04-24 18:23:07 +08:00
|
|
|
|
import dataset from './data';
|
2019-12-30 01:21:15 +08:00
|
|
|
|
import { mathEqual } from './util';
|
|
|
|
|
|
2020-04-24 18:23:07 +08:00
|
|
|
|
const data = dataset.data;
|
|
|
|
|
|
2019-12-30 01:21:15 +08:00
|
|
|
|
const div = document.createElement('div');
|
|
|
|
|
div.id = 'circular-layout-web-worker';
|
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
2020-01-09 15:16:20 +08:00
|
|
|
|
describe('circular layout(web worker)', () => {
|
2020-12-17 15:05:50 +08:00
|
|
|
|
it('circular layout(web worker) with default configs', () => {
|
|
|
|
|
//done
|
2020-12-15 20:36:32 +08:00
|
|
|
|
// const graph = new G6.Graph({
|
|
|
|
|
// container: div,
|
|
|
|
|
// layout: {
|
|
|
|
|
// type: 'circular',
|
|
|
|
|
// // use web worker to layout
|
|
|
|
|
// workerEnabled: true,
|
|
|
|
|
// },
|
|
|
|
|
// width: 500,
|
|
|
|
|
// height: 500,
|
|
|
|
|
// defaultNode: { size: 10 },
|
|
|
|
|
// });
|
|
|
|
|
// graph.data(data);
|
|
|
|
|
// graph.on('afterlayout', () => {
|
|
|
|
|
// const width = graph.get('width');
|
|
|
|
|
// const height = graph.get('height');
|
|
|
|
|
// const radius = height > width ? width / 2 : height / 2;
|
|
|
|
|
// expect(mathEqual(data.nodes[0].x, 250 + radius)).toEqual(true);
|
|
|
|
|
// expect(mathEqual(data.nodes[0].y, 250)).toEqual(true);
|
|
|
|
|
// expect(data.nodes[0].y === 250);
|
|
|
|
|
// graph.destroy();
|
|
|
|
|
// done();
|
|
|
|
|
// });
|
|
|
|
|
// graph.render();
|
2019-12-30 01:21:15 +08:00
|
|
|
|
});
|
|
|
|
|
|
2020-12-15 20:36:32 +08:00
|
|
|
|
// it('circular(web worker) counterclockwise, and fixed radius, start angle, end angle', (done) => {
|
|
|
|
|
// const graph = new G6.Graph({
|
|
|
|
|
// container: div,
|
|
|
|
|
// layout: {
|
|
|
|
|
// type: 'circular',
|
|
|
|
|
// center: [250, 250],
|
|
|
|
|
// radius: 200,
|
|
|
|
|
// startAngle: Math.PI / 4,
|
|
|
|
|
// endAngle: Math.PI,
|
|
|
|
|
// // use web worker to layout
|
|
|
|
|
// workerEnabled: true,
|
|
|
|
|
// },
|
|
|
|
|
// width: 500,
|
|
|
|
|
// height: 500,
|
|
|
|
|
// defaultNode: { size: 10 },
|
|
|
|
|
// });
|
|
|
|
|
// graph.data(data);
|
|
|
|
|
// graph.on('afterlayout', () => {
|
|
|
|
|
// const pos = (200 * Math.sqrt(2)) / 2;
|
|
|
|
|
// expect(mathEqual(data.nodes[0].x, 250 + pos)).toEqual(true);
|
|
|
|
|
// expect(mathEqual(data.nodes[0].y, 250 + pos)).toEqual(true);
|
|
|
|
|
// graph.destroy();
|
|
|
|
|
// done();
|
|
|
|
|
// });
|
|
|
|
|
// graph.render();
|
|
|
|
|
// });
|
2019-12-30 01:21:15 +08:00
|
|
|
|
});
|