mirror of
https://gitee.com/antv/g6.git
synced 2024-12-02 11:48:29 +08:00
add some test
This commit is contained in:
parent
44eae59b4a
commit
2c495e5e2a
@ -98,8 +98,8 @@
|
||||
"prepublishOnly": "npm run build-lib && npm run dist && node ./bin/version.js",
|
||||
"screenshot": "node ./bin/screenshot.js",
|
||||
"start": "npm run dev",
|
||||
"test": "torch --compile --renderer --recursive ./test/unit",
|
||||
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/",
|
||||
"test": "torch --compile --renderer --recursive ./test/unit/plugins/",
|
||||
"test-live": "torch --compile --interactive --watch --recursive ./test/unit/plugins/",
|
||||
"watch": "webpack --config webpack-dev.config.js",
|
||||
"win-dev": "node ./bin/win-dev.js"
|
||||
},
|
||||
|
@ -12,14 +12,14 @@ function panCanvas(graph, button = 'left') {
|
||||
ev.domEvent.preventDefault();
|
||||
});
|
||||
}
|
||||
graph.behaviourOn('mousedown', ev => {
|
||||
if (button === 'left' && ev.domEvent.button === 0 || button === 'right' && ev.domEvent.button === 2) {
|
||||
lastPoint = {
|
||||
x: ev.domX,
|
||||
y: ev.domY
|
||||
};
|
||||
}
|
||||
});
|
||||
// graph.behaviourOn('mousedown', ev => {
|
||||
// if (button === 'left' && ev.domEvent.button === 0 || button === 'right' && ev.domEvent.button === 2) {
|
||||
// lastPoint = {
|
||||
// x: ev.domX,
|
||||
// y: ev.domY
|
||||
// };
|
||||
// }
|
||||
// });
|
||||
graph.behaviourOn('canvas:mouseenter', () => {
|
||||
graph.css({
|
||||
cursor: '-webkit-grab'
|
||||
@ -130,3 +130,5 @@ G6.registerBehaviour('wheelZoom', graph => {
|
||||
}, 50);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = true;
|
||||
|
@ -1,6 +1,7 @@
|
||||
const Body = require('./body');
|
||||
const Quad = require('./quad');
|
||||
const QuadTree = require('./quadTree');
|
||||
|
||||
onmessage = function(event) {
|
||||
let {
|
||||
nodes,
|
||||
|
@ -5,8 +5,10 @@
|
||||
const G6 = require('@antv/g6');
|
||||
const Util = G6.Util;
|
||||
const randomData = {
|
||||
// 生成链式图数据
|
||||
createChainData(num, nodes = [], edges = []) {
|
||||
// generate chain graph data
|
||||
createChainData(num) {
|
||||
const nodes = [];
|
||||
const edges = [];
|
||||
for (let index = 0; index < num; index++) {
|
||||
nodes.push({
|
||||
id: index
|
||||
@ -26,7 +28,7 @@ const randomData = {
|
||||
edges
|
||||
};
|
||||
},
|
||||
// 生成圆数据
|
||||
// generate cyclic graph data
|
||||
createCyclicData(num) {
|
||||
const data = randomData.createChainData(num);
|
||||
const { nodes, edges } = data;
|
||||
@ -37,16 +39,16 @@ const randomData = {
|
||||
});
|
||||
return data;
|
||||
},
|
||||
// generate num * num nodes withou edges
|
||||
createNodesData(num, nodes = [], edges = []) {
|
||||
// generate num * num nodes without edges
|
||||
createNodesData(num) {
|
||||
const nodes = [];
|
||||
for (let index = 0; index < num * num; index++) {
|
||||
nodes.push({
|
||||
id: index
|
||||
});
|
||||
}
|
||||
return {
|
||||
nodes,
|
||||
edges
|
||||
nodes
|
||||
};
|
||||
}
|
||||
};
|
||||
|
@ -15,6 +15,8 @@ Shape.registerGroup('common', {
|
||||
}
|
||||
return this.drawExpanded(item);
|
||||
},
|
||||
defaultWidth: 184,
|
||||
defaultHeight: 40,
|
||||
getLabel(item) {
|
||||
const model = item.getModel();
|
||||
return model.label;
|
||||
@ -41,35 +43,47 @@ Shape.registerGroup('common', {
|
||||
attrs
|
||||
});
|
||||
},
|
||||
drawKeyShape(item, x, y, width, height) {
|
||||
drawKeyShape(item, box) {
|
||||
const { x, y, width, height } = box;
|
||||
const model = item.getModel();
|
||||
const group = item.getGraphicGroup();
|
||||
const attrs = Util.mix({}, Global.groupStyle, model.style);
|
||||
const path = Util.getRectPath(x, y, width, height, attrs.radius);
|
||||
item.lastChildrenBox = box;
|
||||
return group.addShape('path', {
|
||||
attrs: Util.mix({}, attrs, {
|
||||
path
|
||||
})
|
||||
});
|
||||
},
|
||||
getChildrenBBox(item) {
|
||||
const box = {
|
||||
...item.lastChildrenBox
|
||||
};
|
||||
if (item.getChildren().length > 0) {
|
||||
const childrenBBox = item.getChildrenBBox();
|
||||
box.x = childrenBBox.minX - Global.groupBackgroundPadding[3];
|
||||
box.y = childrenBBox.minY - Global.groupBackgroundPadding[0];
|
||||
box.width = (childrenBBox.maxX - childrenBBox.minX) + Global.groupBackgroundPadding[3] + Global.groupBackgroundPadding[1];
|
||||
box.height = (childrenBBox.maxY - childrenBBox.minY) + Global.groupBackgroundPadding[0] + Global.groupBackgroundPadding[2];
|
||||
} else {
|
||||
box.width = this.width;
|
||||
box.height = this.height;
|
||||
}
|
||||
return box;
|
||||
},
|
||||
drawExpanded(item) {
|
||||
const box = item.getChildrenBBox();
|
||||
const x = box.minX - Global.groupBackgroundPadding[3];
|
||||
const y = box.minY - Global.groupBackgroundPadding[0];
|
||||
const width = (box.maxX - box.minX) + Global.groupBackgroundPadding[3] + Global.groupBackgroundPadding[1];
|
||||
const height = (box.maxY - box.minY) + Global.groupBackgroundPadding[0] + Global.groupBackgroundPadding[2];
|
||||
const keyShape = this.drawKeyShape(item, x, y, width, height);
|
||||
this.drawLabel(item, x, y);
|
||||
const box = this.getChildrenBBox(item);
|
||||
const keyShape = this.drawKeyShape(item, box);
|
||||
this.drawLabel(item, box.x, box.y);
|
||||
return keyShape;
|
||||
},
|
||||
drawCollapsed(item) {
|
||||
const box = item.getChildrenBBox();
|
||||
const x = box.minX - Global.groupBackgroundPadding[3];
|
||||
const y = box.minY - Global.groupBackgroundPadding[0];
|
||||
const width = 184;
|
||||
const height = 40;
|
||||
const keyShape = this.drawKeyShape(item, x, y, width, height);
|
||||
this.drawLabel(item, x, y);
|
||||
const box = this.getChildrenBBox(item);
|
||||
box.width = this.width;
|
||||
box.height = this.height;
|
||||
const keyShape = this.drawKeyShape(item, box);
|
||||
this.drawLabel(item, box.x, box.y);
|
||||
return keyShape;
|
||||
},
|
||||
anchor: {
|
||||
|
36
test/unit/plugins/behaviour.analysis-spec.js
Normal file
36
test/unit/plugins/behaviour.analysis-spec.js
Normal file
@ -0,0 +1,36 @@
|
||||
const G6 = require('../../../src/index');
|
||||
const expect = require('chai').expect;
|
||||
const Util = G6.Util;
|
||||
require('../../../plugins/behaviour.analysis/');
|
||||
document.body.appendChild(Util.createDOM(`
|
||||
<div id='mountNode'></div>
|
||||
`));
|
||||
describe('behaviour analysis test', () => {
|
||||
const data = {
|
||||
nodes: [{
|
||||
id: 'node1',
|
||||
x: 100,
|
||||
y: 200
|
||||
}, {
|
||||
id: 'node2',
|
||||
x: 300,
|
||||
y: 200
|
||||
}],
|
||||
edges: [{
|
||||
target: 'node2',
|
||||
source: 'node1'
|
||||
}]
|
||||
};
|
||||
const graph = new G6.Graph({
|
||||
container: 'mountNode',
|
||||
width: 500,
|
||||
height: 500,
|
||||
modes: {
|
||||
default: [ 'panCanvas' ]
|
||||
}
|
||||
});
|
||||
graph.read(data);
|
||||
it('panCanvas', () => {
|
||||
|
||||
});
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
// const G6 = require('../../../src/index');
|
||||
// const Layout = require('../../../build/plugin.layout.forceAtlas2');
|
||||
// const Layout = require('../../../plugins/layout.forceAtlas2/');
|
||||
// const expect = require('chai').expect;
|
||||
// const Util = G6.Util;
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
const G6 = require('../../../src/index');
|
||||
const Extractor = require('../../../plugins/util.extractSubgraph/');
|
||||
const expect = require('chai').expect;
|
||||
const Util = G6.Util;
|
||||
|
||||
require('../../../plugins/util.extractSubgraph/');
|
||||
describe('extract subgraph test', () => {
|
||||
const data = {
|
||||
nodes: [{
|
||||
|
20
test/unit/plugins/util.randomData-spec.js
Normal file
20
test/unit/plugins/util.randomData-spec.js
Normal file
@ -0,0 +1,20 @@
|
||||
const G6 = require('../../../src/index');
|
||||
const expect = require('chai').expect;
|
||||
const Util = G6.Util;
|
||||
require('../../../plugins/util.randomData/');
|
||||
describe('plugin random data test', () => {
|
||||
it('createChainData', () => {
|
||||
const data = Util.createChainData(10);
|
||||
expect(data.nodes.length).eql(10);
|
||||
expect(data.edges.length).eql(9);
|
||||
});
|
||||
it('createCyclicData', () => {
|
||||
const data = Util.createCyclicData(10);
|
||||
expect(data.nodes.length).eql(10);
|
||||
expect(data.edges.length).eql(10);
|
||||
});
|
||||
it('createNodesData', () => {
|
||||
const data = Util.createNodesData(10);
|
||||
expect(data.nodes.length).eql(100);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user