2019-12-18 21:05:01 +08:00
|
|
|
import Graph from '../../../../src/graph/graph'
|
|
|
|
import '../../../../src/shape/node'
|
|
|
|
import '../../../../src/shape/nodes'
|
|
|
|
import '../../../../src/shape/edge'
|
|
|
|
import '../../../../src/shape/edges'
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
const div = document.createElement('div');
|
|
|
|
div.id = 'graph-spec';
|
|
|
|
document.body.appendChild(div);
|
2019-12-12 21:41:51 +08:00
|
|
|
|
|
|
|
describe('polyline e test', () => {
|
|
|
|
describe('default polyline test', () => {
|
2019-12-18 21:05:01 +08:00
|
|
|
const graph = new Graph({
|
|
|
|
container: div,
|
|
|
|
width: 500,
|
|
|
|
height: 500,
|
|
|
|
pixelRatio: 2,
|
|
|
|
defaultNode: {
|
|
|
|
shape: 'polyline'
|
|
|
|
}
|
|
|
|
});
|
2019-12-12 21:41:51 +08:00
|
|
|
it('default polyline config', () => {
|
2019-12-18 21:05:01 +08:00
|
|
|
const data = {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node1',
|
|
|
|
x: 200,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'node2',
|
|
|
|
x: 150,
|
|
|
|
y: 100
|
|
|
|
}
|
|
|
|
],
|
|
|
|
edges: [
|
|
|
|
{
|
|
|
|
source: 'node1',
|
|
|
|
target: 'node2',
|
|
|
|
shape: 'polyline'
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
const edges = graph.getEdges();
|
|
|
|
expect(edges.length).toEqual(1);
|
|
|
|
const edge = edges[0];
|
|
|
|
const keyShape = edge.getKeyShape();
|
|
|
|
expect(keyShape.attr('lineWidth')).toEqual(1);
|
|
|
|
expect(keyShape.attr('stroke')).toEqual('#333');
|
2019-12-12 21:41:51 +08:00
|
|
|
});
|
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
it('polyline with label', () => {
|
|
|
|
const data = {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node1',
|
|
|
|
x: 200,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'node2',
|
|
|
|
x: 150,
|
|
|
|
y: 100
|
|
|
|
}
|
|
|
|
], edges: [{
|
|
|
|
source: 'node1',
|
|
|
|
target: 'node2',
|
|
|
|
shape: 'polyline',
|
|
|
|
label: 'polyline1-2'
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
const edges = graph.getEdges();
|
|
|
|
expect(edges.length).toEqual(1);
|
|
|
|
const edge = edges[0];
|
|
|
|
const group = edge.get('group');
|
|
|
|
expect(group.getCount()).toEqual(2);
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
const label = group.find(g => {
|
|
|
|
return g.get('className') === 'edge-label';
|
|
|
|
});
|
|
|
|
expect(label).not.toBe(undefined);
|
|
|
|
expect(label.attr('fill')).toEqual('#595959');
|
|
|
|
const type = label.get('type');
|
|
|
|
expect(type).toEqual('text');
|
|
|
|
});
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
it('polyline with controlPoints', () => {
|
|
|
|
const data = {
|
|
|
|
nodes: [
|
|
|
|
{
|
|
|
|
id: 'node1',
|
|
|
|
x: 200,
|
|
|
|
y: 200
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'node2',
|
|
|
|
x: 150,
|
|
|
|
y: 100
|
|
|
|
}
|
|
|
|
], edges: [{
|
|
|
|
source: 'node1',
|
|
|
|
target: 'node2',
|
|
|
|
shape: 'polyline',
|
|
|
|
controlPoints: [{ x: 170, y: 160 }]
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
graph.data(data);
|
|
|
|
graph.render();
|
2019-12-12 21:41:51 +08:00
|
|
|
|
2019-12-18 21:05:01 +08:00
|
|
|
const edges = graph.getEdges();
|
|
|
|
expect(edges.length).toEqual(1);
|
|
|
|
const edge = edges[0];
|
|
|
|
const keyShape = edge.getKeyShape();
|
|
|
|
const path = keyShape.attr('path');
|
|
|
|
expect(path.length).toEqual(3);
|
|
|
|
expect(path[1]).toEqual([ 'L', 170, 160 ]);
|
|
|
|
graph.destroy();
|
|
|
|
expect(graph.destroyed).toBe(true);
|
|
|
|
});
|
2019-12-12 21:41:51 +08:00
|
|
|
});
|
|
|
|
});
|