Browse Source

interchanged canvasToDOM and DOMtoCanvas to correspond with the docs.

css_transitions
Alex de Mulder 10 years ago
parent
commit
0066f31dab
2 changed files with 61 additions and 53 deletions
  1. +59
    -51
      dist/vis.js
  2. +2
    -2
      src/graph/Graph.js

+ 59
- 51
dist/vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 1.0.2-SNAPSHOT
* @date 2014-05-23
* @date 2014-05-28
*
* @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com
@ -11103,7 +11103,7 @@ var physicsMixin = {
*/
_calculateSpringForces: function () {
var edgeLength, edge, edgeId;
var dx, dy, fx, fy, springForce, length;
var dx, dy, fx, fy, springForce, distance;
var edges = this.edges;
// forces caused by the edges, modelled as springs
@ -11119,13 +11119,14 @@ var physicsMixin = {
dx = (edge.from.x - edge.to.x);
dy = (edge.from.y - edge.to.y);
length = Math.sqrt(dx * dx + dy * dy);
distance = Math.sqrt(dx * dx + dy * dy);
if (length == 0) {
length = 0.01;
if (distance == 0) {
distance = 0.01;
}
springForce = this.constants.physics.springConstant * (edgeLength - length) / length;
// the 1/distance is so the fx and fy can be calculated without sine or cosine.
springForce = this.constants.physics.springConstant * (edgeLength - distance) / distance;
fx = dx * springForce;
fy = dy * springForce;
@ -11187,17 +11188,18 @@ var physicsMixin = {
* @private
*/
_calculateSpringForce: function (node1, node2, edgeLength) {
var dx, dy, fx, fy, springForce, length;
var dx, dy, fx, fy, springForce, distance;
dx = (node1.x - node2.x);
dy = (node1.y - node2.y);
length = Math.sqrt(dx * dx + dy * dy);
distance = Math.sqrt(dx * dx + dy * dy);
if (length == 0) {
length = 0.01;
if (distance == 0) {
distance = 0.01;
}
springForce = this.constants.physics.springConstant * (edgeLength - length) / length;
// the 1/distance is so the fx and fy can be calculated without sine or cosine.
springForce = this.constants.physics.springConstant * (edgeLength - distance) / distance;
fx = dx * springForce;
fy = dy * springForce;
@ -15735,7 +15737,9 @@ function Graph (container, data, options) {
border: '#666',
background: '#FFFFC6'
}
}
},
moveable: true,
zoomable: true
};
this.editMode = this.constants.dataManipulation.initiallyVisible;
@ -16075,7 +16079,8 @@ Graph.prototype.setOptions = function (options) {
if (options.freezeForStabilization !== undefined) {this.constants.freezeForStabilization = options.freezeForStabilization;}
if (options.configurePhysics !== undefined){this.constants.configurePhysics = options.configurePhysics;}
if (options.stabilizationIterations !== undefined) {this.constants.stabilizationIterations = options.stabilizationIterations;}
if (options.moveable !== undefined) {this.constants.moveable = options.moveable;}
if (options.zoomable !== undefined) {this.constants.zoomable = options.zoomable;}
if (options.labels !== undefined) {
@ -16524,16 +16529,18 @@ Graph.prototype._handleOnDrag = function(event) {
}
}
else {
// move the graph
var diffX = pointer.x - this.drag.pointer.x;
var diffY = pointer.y - this.drag.pointer.y;
this._setTranslation(
this.drag.translation.x + diffX,
this.drag.translation.y + diffY);
this._redraw();
this.moving = true;
this.start();
if (this.constants.moveable == true) {
// move the graph
var diffX = pointer.x - this.drag.pointer.x;
var diffY = pointer.y - this.drag.pointer.y;
this._setTranslation(
this.drag.translation.x + diffX,
this.drag.translation.y + diffY);
this._redraw();
this.moving = true;
this.start();
}
}
};
@ -16621,37 +16628,38 @@ Graph.prototype._onPinch = function (event) {
* @private
*/
Graph.prototype._zoom = function(scale, pointer) {
var scaleOld = this._getScale();
if (scale < 0.00001) {
scale = 0.00001;
}
if (scale > 10) {
scale = 10;
}
// + this.frame.canvas.clientHeight / 2
var translation = this._getTranslation();
var scaleFrac = scale / scaleOld;
var tx = (1 - scaleFrac) * pointer.x + translation.x * scaleFrac;
var ty = (1 - scaleFrac) * pointer.y + translation.y * scaleFrac;
if (this.constants.zoomable == true) {
var scaleOld = this._getScale();
if (scale < 0.00001) {
scale = 0.00001;
}
if (scale > 10) {
scale = 10;
}
// + this.frame.canvas.clientHeight / 2
var translation = this._getTranslation();
this.areaCenter = {"x" : this._canvasToX(pointer.x),
"y" : this._canvasToY(pointer.y)};
var scaleFrac = scale / scaleOld;
var tx = (1 - scaleFrac) * pointer.x + translation.x * scaleFrac;
var ty = (1 - scaleFrac) * pointer.y + translation.y * scaleFrac;
this._setScale(scale);
this._setTranslation(tx, ty);
this.updateClustersDefault();
this._redraw();
this.areaCenter = {"x" : this._canvasToX(pointer.x),
"y" : this._canvasToY(pointer.y)};
if (scaleOld < scale) {
this.emit("zoom", {direction:"+"});
}
else {
this.emit("zoom", {direction:"-"});
}
this._setScale(scale);
this._setTranslation(tx, ty);
this.updateClustersDefault();
this._redraw();
if (scaleOld < scale) {
this.emit("zoom", {direction:"+"});
}
else {
this.emit("zoom", {direction:"-"});
}
return scale;
return scale;
}
};
@ -17324,7 +17332,7 @@ Graph.prototype._yToCanvas = function(y) {
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.DOMtoCanvas = function(pos) {
Graph.prototype.canvasToDOM = function(pos) {
return {x:this._xToCanvas(pos.x),y:this._yToCanvas(pos.y)};
}
@ -17334,7 +17342,7 @@ Graph.prototype.DOMtoCanvas = function(pos) {
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.canvasToDOM = function(pos) {
Graph.prototype.DOMtoCanvas = function(pos) {
return {x:this._canvasToX(pos.x),y:this._canvasToY(pos.y)};
}

+ 2
- 2
src/graph/Graph.js View File

@ -1774,7 +1774,7 @@ Graph.prototype._yToCanvas = function(y) {
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.DOMtoCanvas = function(pos) {
Graph.prototype.canvasToDOM = function(pos) {
return {x:this._xToCanvas(pos.x),y:this._yToCanvas(pos.y)};
}
@ -1784,7 +1784,7 @@ Graph.prototype.DOMtoCanvas = function(pos) {
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.canvasToDOM = function(pos) {
Graph.prototype.DOMtoCanvas = function(pos) {
return {x:this._canvasToX(pos.x),y:this._canvasToY(pos.y)};
}

Loading…
Cancel
Save