2020-02-11 22:25:43 +08:00
|
|
|
/**
|
|
|
|
* @fileOverview Shape 工厂方法的测试
|
|
|
|
* @author dxq613@gmai.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
import G6 from '../../../src';
|
|
|
|
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.id = 'graph-spec';
|
|
|
|
document.body.appendChild(div);
|
|
|
|
|
|
|
|
describe('register node', () => {
|
|
|
|
const data = {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node1',
|
|
|
|
x: 50,
|
2020-02-14 10:10:54 +08:00
|
|
|
y: 50,
|
2020-02-11 22:25:43 +08:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 10:10:54 +08:00
|
|
|
id: 'node2',
|
2020-02-11 22:25:43 +08:00
|
|
|
x: 250,
|
2020-02-14 10:10:54 +08:00
|
|
|
y: 50,
|
2020-02-11 22:25:43 +08:00
|
|
|
},
|
|
|
|
],
|
2020-02-14 10:10:54 +08:00
|
|
|
edges: [
|
|
|
|
{
|
|
|
|
source: 'node1',
|
|
|
|
target: 'node2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-06-22 09:20:46 +08:00
|
|
|
it('shape test without extended shape and draw function', () => {
|
2020-02-14 10:10:54 +08:00
|
|
|
G6.registerNode(
|
|
|
|
'custom-node',
|
|
|
|
{
|
|
|
|
drawShape(cfg, group) {
|
|
|
|
const keyShape = group.addShape('circle', {
|
|
|
|
attrs: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
r: 30,
|
|
|
|
fill: '#87e8de',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
const circle = group.addShape('circle', {
|
|
|
|
attrs: {
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
r: 10,
|
|
|
|
fill: '#ff0000',
|
|
|
|
},
|
|
|
|
className: 'test-circle',
|
|
|
|
});
|
2020-02-11 22:25:43 +08:00
|
|
|
|
2020-02-14 10:10:54 +08:00
|
|
|
return keyShape;
|
|
|
|
},
|
|
|
|
afterDraw(cfg, group) {
|
|
|
|
const foundShape = group.findByClassName('test-circle');
|
|
|
|
expect(foundShape.attr('r')).toBe(10);
|
|
|
|
expect(foundShape.attr('fill')).toBe('#ff0000');
|
|
|
|
},
|
2020-02-11 22:25:43 +08:00
|
|
|
},
|
2020-02-14 10:10:54 +08:00
|
|
|
'single-node',
|
|
|
|
);
|
2020-02-11 22:25:43 +08:00
|
|
|
const graph = new G6.Graph({
|
|
|
|
container: div,
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
defaultNode: {
|
2020-02-14 10:10:54 +08:00
|
|
|
type: 'custom-node',
|
|
|
|
},
|
2020-02-11 22:25:43 +08:00
|
|
|
});
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
|
|
|
expect(graph.getNodes()[0].getModel().x).not.toBe(undefined);
|
|
|
|
expect(graph.getNodes()[0].getModel().y).not.toBe(undefined);
|
|
|
|
graph.destroy();
|
|
|
|
});
|
|
|
|
});
|