g6/tests/unit/layout/circular-web-worker-spec.ts

64 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 注意这里不能直接require原始的src文件而要使用build后的文件因为web worker代码是通过worker-loader内联进来的
import G6 from '../../../dist/g6.min';
import data from './data';
import { mathEqual } from './util';
const div = document.createElement('div');
div.id = 'circular-layout-web-worker';
document.body.appendChild(div);
describe('circular layout(web worker)', () => {
it('circular layout(web worker) with default configs', (done) => {
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();
});
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();
});
});