Browse Source

fixed viewable area check as per #812

flowchartTest
Alex de Mulder 9 years ago
parent
commit
5b3f19acb5
19 changed files with 1054 additions and 1075 deletions
  1. +2
    -2
      dist/vis.css
  2. +973
    -1019
      dist/vis.js
  3. +1
    -1
      dist/vis.min.css
  4. +1
    -1
      lib/network/dotparser.js
  5. +3
    -1
      lib/network/modules/Canvas.js
  6. +31
    -23
      lib/network/modules/CanvasRenderer.js
  7. +8
    -6
      lib/network/modules/Clustering.js
  8. +2
    -2
      lib/network/modules/ConfigurationSystem.js
  9. +2
    -2
      lib/network/modules/Groups.js
  10. +2
    -2
      lib/network/modules/InteractionHandler.js
  11. +2
    -2
      lib/network/modules/LayoutEngine.js
  12. +1
    -1
      lib/network/modules/ManipulationSystem.js
  13. +2
    -2
      lib/network/modules/NodesHandler.js
  14. +3
    -3
      lib/network/modules/PhysicsEngine.js
  15. +3
    -4
      lib/network/modules/SelectionHandler.js
  16. +1
    -1
      lib/network/modules/components/Edge.js
  17. +14
    -0
      lib/network/modules/components/Node.js
  18. +2
    -2
      lib/network/modules/components/edges/util/EdgeBase.js
  19. +1
    -1
      lib/network/modules/components/shared/Label.js

+ 2
- 2
dist/vis.css View File

@ -222,7 +222,7 @@
box-sizing: border-box; box-sizing: border-box;
} }
.vis-item.background {
.vis-item.vis-background {
border: none; border: none;
background-color: rgba(213, 221, 246, 0.4); background-color: rgba(213, 221, 246, 0.4);
box-sizing: border-box; box-sizing: border-box;
@ -244,7 +244,7 @@
display: inline-block; display: inline-block;
} }
.vis-item.background .vis-item-content {
.vis-item.vis-background .vis-item-content {
position: absolute; position: absolute;
display: inline-block; display: inline-block;
} }

+ 973
- 1019
dist/vis.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/vis.min.css
File diff suppressed because it is too large
View File


+ 1
- 1
lib/network/dotparser.js View File

@ -769,7 +769,7 @@ function DOTToGraph (data) {
merge(graphEdge, dotEdge.attr); merge(graphEdge, dotEdge.attr);
graphEdge.style = (dotEdge.type === '->') ? 'arrow' : 'line'; graphEdge.style = (dotEdge.type === '->') ? 'arrow' : 'line';
return graphEdge; return graphEdge;
}
};
dotData.edges.forEach(function (dotEdge) { dotData.edges.forEach(function (dotEdge) {
var from, to; var from, to;

+ 3
- 1
lib/network/modules/Canvas.js View File

@ -22,7 +22,7 @@ class Canvas {
width:'100%', width:'100%',
height:'100%', height:'100%',
autoResize: true autoResize: true
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this.bindEventListeners(); this.bindEventListeners();
@ -157,6 +157,8 @@ class Canvas {
// init hammer // init hammer
this.hammer = new Hammer(this.frame.canvas); this.hammer = new Hammer(this.frame.canvas);
this.hammer.get('pinch').set({enable: true}); this.hammer.get('pinch').set({enable: true});
// enable to get better response, todo: test on mobile.
//this.hammer.get('pan').set({threshold:2});
hammerUtil.onTouch(this.hammer, (event) => {this.body.eventListeners.onTouch(event)}); hammerUtil.onTouch(this.hammer, (event) => {this.body.eventListeners.onTouch(event)});
this.hammer.on('tap', (event) => {this.body.eventListeners.onTap(event)}); this.hammer.on('tap', (event) => {this.body.eventListeners.onTap(event)});

+ 31
- 23
lib/network/modules/CanvasRenderer.js View File

@ -3,7 +3,7 @@ if (typeof window !== 'undefined') {
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
} }
var util = require('../../util');
let util = require('../../util');
class CanvasRenderer { class CanvasRenderer {
@ -24,7 +24,7 @@ class CanvasRenderer {
this.defaultOptions = { this.defaultOptions = {
hideEdgesOnDrag: false, hideEdgesOnDrag: false,
hideNodesOnDrag: false hideNodesOnDrag: false
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this._determineBrowserMethod(); this._determineBrowserMethod();
@ -136,14 +136,14 @@ class CanvasRenderer {
this.body.emitter.emit("initRedraw"); this.body.emitter.emit("initRedraw");
this.redrawRequested = false; this.redrawRequested = false;
var ctx = this.canvas.frame.canvas.getContext('2d');
let ctx = this.canvas.frame.canvas.getContext('2d');
// when the container div was hidden, this fixes it back up! // when the container div was hidden, this fixes it back up!
if (this.canvas.frame.canvas.width === 0 || this.canvas.frame.canvas.height === 0) { if (this.canvas.frame.canvas.width === 0 || this.canvas.frame.canvas.height === 0) {
this.canvas.setSize(); this.canvas.setSize();
} }
if (this.pixelRation === undefined) {
if (this.pixelRatio === undefined) {
this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio || ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio || ctx.msBackingStorePixelRatio ||
@ -154,8 +154,8 @@ class CanvasRenderer {
ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0); ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
// clear the canvas // clear the canvas
var w = this.canvas.frame.canvas.clientWidth;
var h = this.canvas.frame.canvas.clientHeight;
let w = this.canvas.frame.canvas.clientWidth;
let h = this.canvas.frame.canvas.clientHeight;
ctx.clearRect(0, 0, w, h); ctx.clearRect(0, 0, w, h);
@ -190,8 +190,6 @@ class CanvasRenderer {
if (hidden === true) { if (hidden === true) {
ctx.clearRect(0, 0, w, h); ctx.clearRect(0, 0, w, h);
} }
} }
@ -203,10 +201,18 @@ class CanvasRenderer {
* @private * @private
*/ */
_drawNodes(ctx, alwaysShow = false) { _drawNodes(ctx, alwaysShow = false) {
var nodes = this.body.nodes;
var nodeIndices = this.body.nodeIndices;
var node;
var selected = [];
let nodes = this.body.nodes;
let nodeIndices = this.body.nodeIndices;
let node;
let selected = [];
let margin = 20;
let topLeft = this.canvas.DOMtoCanvas({x:-margin,y:-margin});
let bottomRight = this.canvas.DOMtoCanvas({
x: this.canvas.frame.canvas.clientWidth+margin,
y: this.canvas.frame.canvas.clientHeight+margin
});
let viewableArea = {top:topLeft.y,left:topLeft.x,bottom:bottomRight.y,right:bottomRight.x};
// draw unselected nodes; // draw unselected nodes;
for (let i = 0; i < nodeIndices.length; i++) { for (let i = 0; i < nodeIndices.length; i++) {
@ -219,10 +225,12 @@ class CanvasRenderer {
if (alwaysShow === true) { if (alwaysShow === true) {
node.draw(ctx); node.draw(ctx);
} }
// todo: replace check
//else if (node.inArea() === true) {
node.draw(ctx);
//}
else if (node.isBoundingBoxOverlappingWith(viewableArea) === true) {
node.draw(ctx);
}
else {
console.log("hidden")
}
} }
} }
@ -241,9 +249,9 @@ class CanvasRenderer {
* @private * @private
*/ */
_drawEdges(ctx) { _drawEdges(ctx) {
var edges = this.body.edges;
var edgeIndices = this.body.edgeIndices;
var edge;
let edges = this.body.edges;
let edgeIndices = this.body.edgeIndices;
let edge;
for (let i = 0; i < edgeIndices.length; i++) { for (let i = 0; i < edgeIndices.length; i++) {
edge = edges[edgeIndices[i]]; edge = edges[edgeIndices[i]];
@ -260,9 +268,9 @@ class CanvasRenderer {
* @private * @private
*/ */
_drawControlNodes(ctx) { _drawControlNodes(ctx) {
var edges = this.body.edges;
var edgeIndices = this.body.edgeIndices;
var edge;
let edges = this.body.edges;
let edgeIndices = this.body.edgeIndices;
let edge;
for (let i = 0; i < edgeIndices.length; i++) { for (let i = 0; i < edgeIndices.length; i++) {
edge = edges[edgeIndices[i]]; edge = edges[edgeIndices[i]];
@ -277,7 +285,7 @@ class CanvasRenderer {
*/ */
_determineBrowserMethod() { _determineBrowserMethod() {
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
var browserType = navigator.userAgent.toLowerCase();
let browserType = navigator.userAgent.toLowerCase();
this.requiresTimeout = false; this.requiresTimeout = false;
if (browserType.indexOf('msie 9.0') != -1) { // IE 9 if (browserType.indexOf('msie 9.0') != -1) { // IE 9
this.requiresTimeout = true; this.requiresTimeout = true;

+ 8
- 6
lib/network/modules/Clustering.js View File

@ -59,7 +59,7 @@ class ClusterEngine {
options = this._checkOptions(options); options = this._checkOptions(options);
let childNodesObj = {}; let childNodesObj = {};
let childEdgesObj = {}
let childEdgesObj = {};
// collect the nodes that will be in the cluster // collect the nodes that will be in the cluster
for (let i = 0; i < this.body.nodeIndices.length; i++) { for (let i = 0; i < this.body.nodeIndices.length; i++) {
@ -143,7 +143,7 @@ class ClusterEngine {
let childNodesObj = {}; let childNodesObj = {};
let childEdgesObj = {}
let childEdgesObj = {};
let parentNodeId = node.id; let parentNodeId = node.id;
let parentClonedOptions = this._cloneOptions(parentNodeId); let parentClonedOptions = this._cloneOptions(parentNodeId);
childNodesObj[parentNodeId] = node; childNodesObj[parentNodeId] = node;
@ -388,7 +388,7 @@ class ClusterEngine {
return this.body.nodes[nodeId].isCluster === true; return this.body.nodes[nodeId].isCluster === true;
} }
else { else {
console.log("Node does not exist.")
console.log("Node does not exist.");
return false; return false;
} }
} }
@ -426,8 +426,10 @@ class ClusterEngine {
// kill conditions // kill conditions
if (clusterNodeId === undefined) {throw new Error("No clusterNodeId supplied to openCluster.");} if (clusterNodeId === undefined) {throw new Error("No clusterNodeId supplied to openCluster.");}
if (this.body.nodes[clusterNodeId] === undefined) {throw new Error("The clusterNodeId supplied to openCluster does not exist.");} if (this.body.nodes[clusterNodeId] === undefined) {throw new Error("The clusterNodeId supplied to openCluster does not exist.");}
if (this.body.nodes[clusterNodeId].containedNodes === undefined) {console.log("The node:" + clusterNodeId + " is not a cluster."); return};
if (this.body.nodes[clusterNodeId].containedNodes === undefined) {
console.log("The node:" + clusterNodeId + " is not a cluster.");
return
}
let clusterNode = this.body.nodes[clusterNodeId]; let clusterNode = this.body.nodes[clusterNodeId];
let containedNodes = clusterNode.containedNodes; let containedNodes = clusterNode.containedNodes;
let containedEdges = clusterNode.containedEdges; let containedEdges = clusterNode.containedEdges;
@ -492,7 +494,7 @@ class ClusterEngine {
if (from === true) { if (from === true) {
edge.from = clusterStack[clusterStack.length - 1]; edge.from = clusterStack[clusterStack.length - 1];
edge.fromId = clusterStack[clusterStack.length - 1].id; edge.fromId = clusterStack[clusterStack.length - 1].id;
clusterStack.pop()
clusterStack.pop();
edge.fromArray = clusterStack; edge.fromArray = clusterStack;
} }
else { else {

+ 2
- 2
lib/network/modules/ConfigurationSystem.js View File

@ -27,7 +27,7 @@ class ConfigurationSystem {
enabled: false, enabled: false,
filter: true, filter: true,
container: undefined container: undefined
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this.configureOptions = configureOptions; this.configureOptions = configureOptions;
@ -371,7 +371,7 @@ class ConfigurationSystem {
value = value === undefined ? defaultColor : value; value = value === undefined ? defaultColor : value;
div.onclick = () => { div.onclick = () => {
this._showColorPicker(value,div,path); this._showColorPicker(value,div,path);
}
};
let label = this._makeLabel(path[path.length-1], path); let label = this._makeLabel(path[path.length-1], path);
this._makeItem(path,label, div); this._makeItem(path,label, div);

+ 2
- 2
lib/network/modules/Groups.js View File

@ -34,13 +34,13 @@ class Groups {
{border: "#FFC0CB", background: "#FD5A77", highlight: {border: "#FFD1D9", background: "#FD5A77"}, hover: {border: "#FFD1D9", background: "#FD5A77"}}, // 18: pink {border: "#FFC0CB", background: "#FD5A77", highlight: {border: "#FFD1D9", background: "#FD5A77"}, hover: {border: "#FFD1D9", background: "#FD5A77"}}, // 18: pink
{border: "#C2FABC", background: "#74D66A", highlight: {border: "#E6FFE3", background: "#74D66A"}, hover: {border: "#E6FFE3", background: "#74D66A"}}, // 19: mint {border: "#C2FABC", background: "#74D66A", highlight: {border: "#E6FFE3", background: "#74D66A"}, hover: {border: "#E6FFE3", background: "#74D66A"}}, // 19: mint
{border: "#EE0000", background: "#990000", highlight: {border: "#FF3333", background: "#BB0000"}, hover: {border: "#FF3333", background: "#BB0000"}}, // 20:bright red
{border: "#EE0000", background: "#990000", highlight: {border: "#FF3333", background: "#BB0000"}, hover: {border: "#FF3333", background: "#BB0000"}} // 20:bright red
]; ];
this.options = {}; this.options = {};
this.defaultOptions = { this.defaultOptions = {
useDefaultGroups: true useDefaultGroups: true
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
} }

+ 2
- 2
lib/network/modules/InteractionHandler.js View File

@ -47,7 +47,7 @@ class InteractionHandler {
speed: {x: 10, y: 10, zoom: 0.02}, speed: {x: 10, y: 10, zoom: 0.02},
bindToWindow: true bindToWindow: true
} }
}
};
util.extend(this.options,this.defaultOptions); util.extend(this.options,this.defaultOptions);
this.bindEventListeners() this.bindEventListeners()
@ -477,7 +477,7 @@ class InteractionHandler {
// if the popup was not hidden above // if the popup was not hidden above
if (this.popup.hidden === false) { if (this.popup.hidden === false) {
popupVisible = true; popupVisible = true;
this.popup.setPosition(pointer.x + 3, pointer.y - 5)
this.popup.setPosition(pointer.x + 3, pointer.y - 5);
this.popup.show(); this.popup.show();
} }
} }

+ 2
- 2
lib/network/modules/LayoutEngine.js View File

@ -17,7 +17,7 @@ class LayoutEngine {
direction: 'UD', // UD, DU, LR, RL direction: 'UD', // UD, DU, LR, RL
sortMethod: 'hubsize' // hubsize, directed sortMethod: 'hubsize' // hubsize, directed
} }
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this.hierarchicalLevels = {}; this.hierarchicalLevels = {};
@ -28,7 +28,7 @@ class LayoutEngine {
bindEventListeners() { bindEventListeners() {
this.body.emitter.on('_dataChanged', () => { this.body.emitter.on('_dataChanged', () => {
this.setupHierarchicalLayout(); this.setupHierarchicalLayout();
})
});
this.body.emitter.on('_resetHierarchicalLayout', () => { this.body.emitter.on('_resetHierarchicalLayout', () => {
this.setupHierarchicalLayout(); this.setupHierarchicalLayout();
}); });

+ 1
- 1
lib/network/modules/ManipulationSystem.js View File

@ -49,7 +49,7 @@ class ManipulationSystem {
borderWidth: 2, borderWidth: 2,
borderWidthSelected: 2 borderWidthSelected: 2
} }
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this.body.emitter.on('destroy', () => {this._clean();}); this.body.emitter.on('destroy', () => {this._clean();});

+ 2
- 2
lib/network/modules/NodesHandler.js View File

@ -216,7 +216,7 @@ class NodesHandler {
for (let i = 0; i < ids.length; i++) { for (let i = 0; i < ids.length; i++) {
id = ids[i]; id = ids[i];
let properties = this.body.data.nodes.get(id); let properties = this.body.data.nodes.get(id);
let node = this.create(properties);;
let node = this.create(properties);
newNodes.push(node); newNodes.push(node);
this.body.nodes[id] = node; // note: this may replace an existing node this.body.nodes[id] = node; // note: this may replace an existing node
} }
@ -386,7 +386,7 @@ class NodesHandler {
} }
else if (edge.fromId === nodeId) { else if (edge.fromId === nodeId) {
if (nodeObj[edge.toId] === undefined) { if (nodeObj[edge.toId] === undefined) {
nodeList.push(edge.toId)
nodeList.push(edge.toId);
nodeObj[edge.toId] = true; nodeObj[edge.toId] = true;
} }
} }

+ 3
- 3
lib/network/modules/PhysicsEngine.js View File

@ -60,7 +60,7 @@ class PhysicsEngine {
fit: true fit: true
}, },
timestep: 0.5 timestep: 0.5
}
};
util.extend(this.options, this.defaultOptions); util.extend(this.options, this.defaultOptions);
this.bindEventListeners(); this.bindEventListeners();
@ -80,7 +80,7 @@ class PhysicsEngine {
if (this.ready === true) { if (this.ready === true) {
this.startSimulation(); this.startSimulation();
} }
})
});
this.body.emitter.on('stopSimulation', () => {this.stopSimulation();}); this.body.emitter.on('stopSimulation', () => {this.stopSimulation();});
this.body.emitter.on('destroy', () => { this.body.emitter.on('destroy', () => {
this.stopSimulation(false); this.stopSimulation(false);
@ -135,7 +135,7 @@ class PhysicsEngine {
else { else {
this.stabilized = false; this.stabilized = false;
this.ready = true; this.ready = true;
this.body.emitter.emit('fit', {}, true)
this.body.emitter.emit('fit', {}, true);
this.startSimulation(); this.startSimulation();
} }
} }

+ 3
- 4
lib/network/modules/SelectionHandler.js View File

@ -37,7 +37,7 @@ class SelectionHandler {
let selected = false; let selected = false;
if (this.options.select === true) { if (this.options.select === true) {
this.unselectAll(); this.unselectAll();
let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer);;
let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer);
if (obj !== undefined) { if (obj !== undefined) {
selected = this.selectObject(obj); selected = this.selectObject(obj);
} }
@ -49,8 +49,7 @@ class SelectionHandler {
selectAdditionalOnPoint(pointer) { selectAdditionalOnPoint(pointer) {
let selectionChanged = false; let selectionChanged = false;
if (this.options.select === true) { if (this.options.select === true) {
let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer);;
let obj = this.getNodeAt(pointer) || this.getEdgeAt(pointer);
if (obj !== undefined) { if (obj !== undefined) {
selectionChanged = true; selectionChanged = true;
if (obj.isSelected() === true) { if (obj.isSelected() === true) {
@ -71,7 +70,7 @@ class SelectionHandler {
properties['pointer'] = { properties['pointer'] = {
DOM: {x: pointer.x, y: pointer.y}, DOM: {x: pointer.x, y: pointer.y},
canvas: this.canvas.DOMtoCanvas(pointer) canvas: this.canvas.DOMtoCanvas(pointer)
}
};
properties['event'] = event; properties['event'] = event;
if (oldSelection !== undefined) { if (oldSelection !== undefined) {

+ 1
- 1
lib/network/modules/components/Edge.js View File

@ -104,7 +104,7 @@ class Edge {
'to', 'to',
'title', 'title',
'value', 'value',
'width',
'width'
]; ];
// only deep extend the items in the field array. These do not have shorthand. // only deep extend the items in the field array. These do not have shorthand.

+ 14
- 0
lib/network/modules/components/Node.js View File

@ -393,6 +393,20 @@ class Node {
); );
} }
/**
* Check if this object is overlapping with the provided object
* @param {Object} obj an object with parameters left, top, right, bottom
* @return {boolean} True if location is located on node
*/
isBoundingBoxOverlappingWith(obj) {
return (
this.shape.boundingBox.left < obj.right &&
this.shape.boundingBox.right > obj.left &&
this.shape.boundingBox.top < obj.bottom &&
this.shape.boundingBox.bottom > obj.top
);
}
} }

+ 2
- 2
lib/network/modules/components/edges/util/EdgeBase.js View File

@ -1,4 +1,4 @@
let util = require("../../../../../util")
let util = require("../../../../../util");
class EdgeBase { class EdgeBase {
constructor(options, body, labelModule) { constructor(options, body, labelModule) {
@ -198,7 +198,7 @@ class EdgeBase {
let radius = this.options.selfReferenceSize; let radius = this.options.selfReferenceSize;
let pos, angle, distanceToBorder, distanceToPoint, difference; let pos, angle, distanceToBorder, distanceToPoint, difference;
let threshold = 0.05; let threshold = 0.05;
let middle = (low + high) * 0.5
let middle = (low + high) * 0.5;
while (low <= high && iteration < maxIterations) { while (low <= high && iteration < maxIterations) {
middle = (low + high) * 0.5; middle = (low + high) * 0.5;

+ 1
- 1
lib/network/modules/components/shared/Label.js View File

@ -90,7 +90,7 @@ class Label {
break; break;
case 'bottom': case 'bottom':
ctx.fillRect(-this.size.width * 0.5, lineMargin, this.size.width, this.size.height); ctx.fillRect(-this.size.width * 0.5, lineMargin, this.size.width, this.size.height);
break
break;
default: default:
ctx.fillRect(this.size.left, this.size.top, this.size.width, this.size.height); ctx.fillRect(this.size.left, this.size.top, this.size.width, this.size.height);
break; break;

Loading…
Cancel
Save