Browse Source

Updated zoomExtent and added to methods as per #39, removed width property from zoom extent -> getrange. typos.

css_transitions
Alex de Mulder 10 years ago
parent
commit
5262fa059a
7 changed files with 54 additions and 64 deletions
  1. +24
    -29
      dist/vis.js
  2. +7
    -7
      dist/vis.min.js
  3. +6
    -0
      docs/graph.html
  4. +1
    -1
      examples/graph/20_navigation.html
  5. +13
    -8
      src/graph/Graph.js
  6. +2
    -18
      src/graph/graphMixins/HierarchicalLayoutMixin.js
  7. +1
    -1
      src/graph/graphMixins/NavigationMixin.js

+ 24
- 29
dist/vis.js View File

@ -4,8 +4,8 @@
* *
* A dynamic, browser-based visualization library. * A dynamic, browser-based visualization library.
* *
* @version 0.5.1
* @date 2014-02-20
* @version @@version
* @date @@date
* *
* @license * @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com * Copyright (C) 2011-2014 Almende B.V, http://almende.com
@ -12156,7 +12156,7 @@ var HierarchicalLayoutMixin = {
// if the user defined some levels but not all, alert and run without hierarchical layout // if the user defined some levels but not all, alert and run without hierarchical layout
if (undefinedLevel == true && definedLevel == true) { if (undefinedLevel == true && definedLevel == true) {
alert("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.") alert("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.")
this.zoomToFit(true,this.constants.clustering.enabled);
this.zoomExtent(true,this.constants.clustering.enabled);
if (!this.constants.clustering.enabled) { if (!this.constants.clustering.enabled) {
this.start(); this.start();
} }
@ -12204,24 +12204,8 @@ var HierarchicalLayoutMixin = {
} }
} }
// give the nodes a defined width so the zoomToFit can be used. This size is arbitrary.
for (nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
node = this.nodes[nodeId];
node.width = 100;
node.height = 100;
}
}
// stabilize the system after positioning. This function calls zoomToFit.
// stabilize the system after positioning. This function calls zoomExtent.
this._doStabilize(); this._doStabilize();
// reset the arbitrary width and height we gave the nodes.
for (nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
this.nodes[nodeId]._reset();
}
}
}, },
@ -15095,7 +15079,7 @@ var NavigationMixin = {
this.navigationDivs = {}; this.navigationDivs = {};
var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends']; var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends'];
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','zoomToFit'];
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','zoomExtent'];
this.navigationDivs['wrapper'] = document.createElement('div'); this.navigationDivs['wrapper'] = document.createElement('div');
this.navigationDivs['wrapper'].id = "graph-navigation_wrapper"; this.navigationDivs['wrapper'].id = "graph-navigation_wrapper";
@ -15727,7 +15711,9 @@ function Graph (container, data, options) {
} }
else { else {
// zoom so all data will fit on the screen, if clustering is enabled, we do not want start to be called here. // zoom so all data will fit on the screen, if clustering is enabled, we do not want start to be called here.
this.zoomToFit(true,this.constants.clustering.enabled);
if (this.stabilize == false) {
this.zoomExtent(true,this.constants.clustering.enabled);
}
} }
@ -15773,10 +15759,10 @@ Graph.prototype._getRange = function() {
for (var nodeId in this.nodes) { for (var nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) { if (this.nodes.hasOwnProperty(nodeId)) {
node = this.nodes[nodeId]; node = this.nodes[nodeId];
if (minX > (node.x - node.width)) {minX = node.x - node.width;}
if (maxX < (node.x + node.width)) {maxX = node.x + node.width;}
if (minY > (node.y - node.height)) {minY = node.y - node.height;}
if (maxY < (node.y + node.height)) {maxY = node.y + node.height;}
if (minX > (node.x)) {minX = node.x;}
if (maxX < (node.x)) {maxX = node.x;}
if (minY > (node.y)) {minY = node.y;}
if (maxY < (node.y)) {maxY = node.y;}
} }
} }
return {minX: minX, maxX: maxX, minY: minY, maxY: maxY}; return {minX: minX, maxX: maxX, minY: minY, maxY: maxY};
@ -15816,10 +15802,13 @@ Graph.prototype._centerGraph = function(range) {
* *
* @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false; * @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false;
*/ */
Graph.prototype.zoomToFit = function(initialZoom, disableStart) {
Graph.prototype.zoomExtent = function(initialZoom, disableStart) {
if (initialZoom === undefined) { if (initialZoom === undefined) {
initialZoom = false; initialZoom = false;
} }
if (disableStart === undefined) {
disableStart = false;
}
var range = this._getRange(); var range = this._getRange();
var zoomLevel; var zoomLevel;
@ -15844,6 +15833,10 @@ Graph.prototype.zoomToFit = function(initialZoom, disableStart) {
zoomLevel = 30.5062972 / (numberOfNodes + 19.93597763) + 0.08413486; // this is obtained from fitting a dataset from 5 points with scale levels that looked good. zoomLevel = 30.5062972 / (numberOfNodes + 19.93597763) + 0.08413486; // this is obtained from fitting a dataset from 5 points with scale levels that looked good.
} }
} }
// correct for larger canvasses.
var factor = Math.min(this.frame.canvas.clientWidth / 600, this.frame.canvas.clientHeight / 600);
zoomLevel *= factor;
} }
else { else {
var xDistance = (Math.abs(range.minX) + Math.abs(range.maxX)) * 1.1; var xDistance = (Math.abs(range.minX) + Math.abs(range.maxX)) * 1.1;
@ -15859,10 +15852,12 @@ Graph.prototype.zoomToFit = function(initialZoom, disableStart) {
zoomLevel = 1.0; zoomLevel = 1.0;
} }
this.pinch.mousewheelScale = zoomLevel; this.pinch.mousewheelScale = zoomLevel;
this._setScale(zoomLevel); this._setScale(zoomLevel);
this._centerGraph(range); this._centerGraph(range);
if (disableStart == false || disableStart === undefined) {
if (disableStart == false) {
this.moving = true; this.moving = true;
this.start(); this.start();
} }
@ -17181,7 +17176,7 @@ Graph.prototype._doStabilize = function() {
count++; count++;
} }
this.zoomToFit(false,true);
this.zoomExtent(false,true);
}; };

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


+ 6
- 0
docs/graph.html View File

@ -1778,6 +1778,12 @@ var options: {
or in percentages.</td> or in percentages.</td>
</tr> </tr>
<tr>
<td>zoomExtent</td>
<td>none</td>
<td>Scales the graph so all the nodes are in center view.</td>
</tr>
</table> </table>
<h2 id="Events">Events</h2> <h2 id="Events">Events</h2>

+ 1
- 1
examples/graph/20_navigation.html View File

@ -156,7 +156,7 @@
<td><div class="table_content">Move right</div></td> <td><div class="table_content">Move right</div></td>
<td><div class="table_content">Zoom in</div></td> <td><div class="table_content">Zoom in</div></td>
<td><div class="table_content">Zoom out</div></td> <td><div class="table_content">Zoom out</div></td>
<td><div class="table_content">Zoom extends</div></td>
<td><div class="table_content">Zoom extent</div></td>
</tr> </tr>
</table> </table>
<br /> <br />

+ 13
- 8
src/graph/Graph.js View File

@ -243,7 +243,9 @@ function Graph (container, data, options) {
} }
else { else {
// zoom so all data will fit on the screen, if clustering is enabled, we do not want start to be called here. // zoom so all data will fit on the screen, if clustering is enabled, we do not want start to be called here.
this.zoomToFit(true,this.constants.clustering.enabled);
if (this.stabilize == false) {
this.zoomExtent(true,this.constants.clustering.enabled);
}
} }
@ -289,10 +291,10 @@ Graph.prototype._getRange = function() {
for (var nodeId in this.nodes) { for (var nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) { if (this.nodes.hasOwnProperty(nodeId)) {
node = this.nodes[nodeId]; node = this.nodes[nodeId];
if (minX > (node.x - node.width)) {minX = node.x - node.width;}
if (maxX < (node.x + node.width)) {maxX = node.x + node.width;}
if (minY > (node.y - node.height)) {minY = node.y - node.height;}
if (maxY < (node.y + node.height)) {maxY = node.y + node.height;}
if (minX > (node.x)) {minX = node.x;}
if (maxX < (node.x)) {maxX = node.x;}
if (minY > (node.y)) {minY = node.y;}
if (maxY < (node.y)) {maxY = node.y;}
} }
} }
return {minX: minX, maxX: maxX, minY: minY, maxY: maxY}; return {minX: minX, maxX: maxX, minY: minY, maxY: maxY};
@ -332,10 +334,13 @@ Graph.prototype._centerGraph = function(range) {
* *
* @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false; * @param {Boolean} [initialZoom] | zoom based on fitted formula or range, true = fitted, default = false;
*/ */
Graph.prototype.zoomToFit = function(initialZoom, disableStart) {
Graph.prototype.zoomExtent = function(initialZoom, disableStart) {
if (initialZoom === undefined) { if (initialZoom === undefined) {
initialZoom = false; initialZoom = false;
} }
if (disableStart === undefined) {
disableStart = false;
}
var range = this._getRange(); var range = this._getRange();
var zoomLevel; var zoomLevel;
@ -384,7 +389,7 @@ Graph.prototype.zoomToFit = function(initialZoom, disableStart) {
this.pinch.mousewheelScale = zoomLevel; this.pinch.mousewheelScale = zoomLevel;
this._setScale(zoomLevel); this._setScale(zoomLevel);
this._centerGraph(range); this._centerGraph(range);
if (disableStart == false || disableStart === undefined) {
if (disableStart == false) {
this.moving = true; this.moving = true;
this.start(); this.start();
} }
@ -1703,7 +1708,7 @@ Graph.prototype._doStabilize = function() {
count++; count++;
} }
this.zoomToFit(false,true);
this.zoomExtent(false,true);
}; };

+ 2
- 18
src/graph/graphMixins/HierarchicalLayoutMixin.js View File

@ -34,7 +34,7 @@ var HierarchicalLayoutMixin = {
// if the user defined some levels but not all, alert and run without hierarchical layout // if the user defined some levels but not all, alert and run without hierarchical layout
if (undefinedLevel == true && definedLevel == true) { if (undefinedLevel == true && definedLevel == true) {
alert("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.") alert("To use the hierarchical layout, nodes require either no predefined levels or levels have to be defined for all nodes.")
this.zoomToFit(true,this.constants.clustering.enabled);
this.zoomExtent(true,this.constants.clustering.enabled);
if (!this.constants.clustering.enabled) { if (!this.constants.clustering.enabled) {
this.start(); this.start();
} }
@ -82,24 +82,8 @@ var HierarchicalLayoutMixin = {
} }
} }
// give the nodes a defined width so the zoomToFit can be used. This size is arbitrary.
for (nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
node = this.nodes[nodeId];
node.width = 100;
node.height = 100;
}
}
// stabilize the system after positioning. This function calls zoomToFit.
// stabilize the system after positioning. This function calls zoomExtent.
this._doStabilize(); this._doStabilize();
// reset the arbitrary width and height we gave the nodes.
for (nodeId in this.nodes) {
if (this.nodes.hasOwnProperty(nodeId)) {
this.nodes[nodeId]._reset();
}
}
}, },

+ 1
- 1
src/graph/graphMixins/NavigationMixin.js View File

@ -26,7 +26,7 @@ var NavigationMixin = {
this.navigationDivs = {}; this.navigationDivs = {};
var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends']; var navigationDivs = ['up','down','left','right','zoomIn','zoomOut','zoomExtends'];
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','zoomToFit'];
var navigationDivActions = ['_moveUp','_moveDown','_moveLeft','_moveRight','_zoomIn','_zoomOut','zoomExtent'];
this.navigationDivs['wrapper'] = document.createElement('div'); this.navigationDivs['wrapper'] = document.createElement('div');
this.navigationDivs['wrapper'].id = "graph-navigation_wrapper"; this.navigationDivs['wrapper'].id = "graph-navigation_wrapper";

Loading…
Cancel
Save