resize |
- Fired when the size of the canvas has been updated (not neccecarily changed) by the setSize() function or by the setOptions() function. |
+ Fired when the size of the canvas has been resized, either by a redraw call when the container div has changed in size, a setSize() call with new values or a setOptions() with new width and/or height values. |
width : the new width of the canvas
diff --git a/examples/network/02_random_nodes.html b/examples/network/02_random_nodes.html
index 34c42ebe..f30842fe 100644
--- a/examples/network/02_random_nodes.html
+++ b/examples/network/02_random_nodes.html
@@ -8,8 +8,6 @@
font: 10pt sans;
}
#mynetwork {
- width: 600px;
- height: 600px;
border: 1px solid lightgray;
}
@@ -78,8 +76,6 @@
};
var options = {
- edges: {
- }
};
network = new vis.Network(container, data, options);
@@ -90,7 +86,9 @@
network.on('stabilized', function (params) {
document.getElementById('stabilization').innerHTML = 'Stabilization took ' + params.iterations + ' iterations.';
});
+
}
+
diff --git a/lib/network/Network.js b/lib/network/Network.js
index fa99b615..29d777e5 100644
--- a/lib/network/Network.js
+++ b/lib/network/Network.js
@@ -1277,16 +1277,39 @@ Network.prototype._checkHidePopup = function (pointer) {
* or '30%')
*/
Network.prototype.setSize = function(width, height) {
- this.frame.style.width = width;
- this.frame.style.height = height;
+ var emitEvent = false;
+ if (width != this.constants.width || height != this.constants.height || this.frame.style.width != width || this.frame.style.height != height) {
+ this.frame.style.width = width;
+ this.frame.style.height = height;
- this.frame.canvas.style.width = '100%';
- this.frame.canvas.style.height = '100%';
+ this.frame.canvas.style.width = '100%';
+ this.frame.canvas.style.height = '100%';
- this.frame.canvas.width = this.frame.canvas.clientWidth;
- this.frame.canvas.height = this.frame.canvas.clientHeight;
+ this.frame.canvas.width = this.frame.canvas.clientWidth;
+ this.frame.canvas.height = this.frame.canvas.clientHeight;
- this.emit('resize', {width:this.frame.canvas.width,height:this.frame.canvas.height});
+ this.constants.width = width;
+ this.constants.height = height;
+
+ emitEvent = true;
+ }
+ else {
+ // this would adapt the width of the canvas to the width from 100% if and only if
+ // there is a change.
+
+ if (this.frame.canvas.width != this.frame.canvas.clientWidth) {
+ this.frame.canvas.width = this.frame.canvas.clientWidth;
+ emitEvent = true;
+ }
+ if (this.frame.canvas.height != this.frame.canvas.clientHeight) {
+ this.frame.canvas.height = this.frame.canvas.clientHeight;
+ emitEvent = true;
+ }
+ }
+
+ if (emitEvent == true) {
+ this.emit('resize', {width:this.frame.canvas.width,height:this.frame.canvas.height});
+ }
};
/**
|