Browse Source

added DOMtoCanvas and canvasToDOM

css_transitions
Alex de Mulder 10 years ago
parent
commit
6c7e6968bc
3 changed files with 37 additions and 1 deletions
  1. +4
    -0
      HISTORY.md
  2. +12
    -1
      docs/graph.html
  3. +21
    -0
      src/graph/Graph.js

+ 4
- 0
HISTORY.md View File

@ -4,6 +4,10 @@ http://visjs.org
## not yet released, version 1.0.1
### Graph
- added coordinate conversion from DOM to Canvas.
## 2014-05-02, version 1.0.0

+ 12
- 1
docs/graph.html View File

@ -1999,7 +1999,18 @@ var options: {
You can use this to stablize your graph once, then save the positions in a database so the next time you load the nodes, stabilization will be near instantaneous.
</td>
</tr>
<tr>
<td>DOMtoCanvas(pos)</td>
<td>object</td>
<td>This function converts DOM coordinates to coordinates on the canvas. Input and output are in the form of {x:xpos,y:ypos}. The DOM values are relative to the graph container.
</td>
</tr>
<tr>
<td>canvasToDOM(pos)</td>
<td>object</td>
<td>This function converts canvas coordinates to coordinates on the DOM. Input and output are in the form of {x:xpos,y:ypos}. The DOM values are relative to the graph container.
</td>
</tr>
<tr>
<td>on(event, callback)</td>
<td>none</td>

+ 21
- 0
src/graph/Graph.js View File

@ -1734,6 +1734,27 @@ Graph.prototype._yToCanvas = function(y) {
return y * this.scale + this.translation.y ;
};
/**
*
* @param {object} pos = {x: number, y: number}
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.DOMtoCanvas = function(pos) {
return {x:this._xToCanvas(pos.x),y:this._yToCanvas(pos.y)};
}
/**
*
* @param {object} pos = {x: number, y: number}
* @returns {{x: number, y: number}}
* @constructor
*/
Graph.prototype.canvasToDOM = function(pos) {
return {x:this._canvasToX(pos.x),y:this._canvasToY(pos.y)};
}
/**
* Redraw all nodes
* The 2d context of a HTML canvas can be retrieved by canvas.getContext('2d');

Loading…
Cancel
Save