Browse Source

Implemented DOT support in Graph without need for a separate parse step.

css_transitions
josdejong 11 years ago
parent
commit
ed26e58144
16 changed files with 374 additions and 221 deletions
  1. +4
    -5
      README.md
  2. +9
    -4
      docs/css/prettify.css
  3. +1
    -19
      docs/css/style.css
  4. +103
    -82
      docs/graph.html
  5. +3
    -3
      docs/index.html
  6. +10
    -5
      docs/timeline.html
  7. +4
    -10
      examples/graph/19_dot_language.html
  8. +4
    -2
      examples/graph/20_dot_language_playground.html
  9. +1
    -2
      examples/timeline/01_basic.html
  10. +8
    -2
      src/graph/Edge.js
  11. +84
    -23
      src/graph/Graph.js
  12. +2
    -0
      src/graph/Node.js
  13. +16
    -13
      src/graph/dotparser.js
  14. +4
    -3
      src/timeline/component/ItemSet.js
  15. +115
    -42
      vis.js
  16. +6
    -6
      vis.min.js

+ 4
- 5
README.md View File

@ -2,8 +2,8 @@ vis.js
==================
Vis.js is a dynamic, browser based visualization library.
The library is designed to be easy to use, to handle large amounts
of dynamic data, and to enable manipulation of the data.
The library is designed to be easy to use, handle large amounts
of dynamic data, and enable manipulation of the data.
The library consists of the following components:
- Timeline. Display different types of data on a timeline.
@ -12,10 +12,9 @@ The library consists of the following components:
- Graph. Display a graph of network with nodes and edges.
- DataSet and DataView. A flexible key/value based data set.
Add, update, and remove items. Subscribe on changes in the data set.
Filter, order, and cast data.
Filter, order, and cast items.
Vis.js Library is part of [CHAP](http://chap.almende.com),
the Common Hybrid Agent Platform, developed by [Almende B.V](http://almende.com).
The vis.js library is developed by [Almende B.V](http://almende.com).
## Install

+ 9
- 4
docs/css/prettify.css View File

@ -11,12 +11,17 @@
}
.pln {
color: #1C1C1C;
color: #333333;
}
pre.prettyprint {
border:1px solid lightgray;
padding:2px;
border: 1px solid lightgray;
background-color: #fcfcfc;
padding: 5px;
font-size: 10pt;
line-height: 1.5em;
font-family: monospace;
}
ol.linenums {
@ -41,7 +46,7 @@ li.L1,li.L3,li.L5,li.L7,li.L9 {
}
.typ,.atn,.dec {
color: orange;
color: darkorange;
}
@media print {

+ 1
- 19
docs/css/style.css View File

@ -49,25 +49,7 @@ a:hover {
text-decoration: underline;
}
hr {
border: none 0;
border-top: 1px solid #abc;
height: 1px;
}
pre {
display: block;
font-size: 10pt;
line-height: 1.5em;
font-family: monospace;
}
pre, code {
background-color: #f5f5f5;
}
table
{
table {
border-collapse: collapse;
}

+ 103
- 82
docs/graph.html View File

@ -36,15 +36,21 @@
<li><a href="#Overview">Overview</a></li>
<li><a href="#Example">Example</a></li>
<li><a href="#Loading">Loading</a></li>
<li><a href="#Data_Format">Data Format</a></li>
<li><a href="#Data_Import">Data Import</a></li>
<li>
<a href="#Data_Format">Data Format</a>
<ul>
<li><a href="#Nodes">Nodes</a></li>
<li><a href="#Edges">Edges</a></li>
<li><a href="#DOT_language">DOT_language</a></li>
</ul>
</li>
<li><a href="#Configuration_Options">Configuration Options</a></li>
<li><a href="#Methods">Methods</a></li>
<li><a href="#Events">Events</a></li>
<li><a href="#Data_Policy">Data Policy</a></li>
</ul>
<h2><a name="Overview"></a>Overview</h2>
<h2 id="Overview">Overview</h2>
<p>
Graph is a visualization to display graphs and networks consisting of nodes
and edges. The visualization is easy to use and supports custom styles,
@ -61,7 +67,7 @@
<a href="http://visjs.org" target="_blank">vis.js</a> library.
</p>
<h2><a name="Example"></a>Example</h2>
<h2 id="Example">Example</h2>
<p>
Here a basic graph example. More examples can be found in the
<a href="../examples" target="_blank">examples directory</a>.
@ -115,7 +121,7 @@
</pre>
<h2><a name="Loading"></a>Loading</h2>
<h2 id="Loading">Loading</h2>
<p>
Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
in a subfolder of your project. Include the library script in the head of your html code:
@ -139,22 +145,62 @@ The constructor accepts three parameters:
<code>edges</code>, which both contain an array with objects.
Optionally, data may contain an <code>options</code> object.
The parameter <code>data</code> is optional, data can also be set using
the method <code>setData</code>.
the method <code>setData</code>. Section <a href="#Data_Format">Data Format</a>
describes the data object.
</li>
<li>
<code>options</code> is an optional Object containing a name-value map
with options. Options can also be set using the method
<code>setOptions</code>.
Section <a href="#Configuration_Options">Configuration Options</a>
describes the available options.
</li>
</ul>
<h2><a name="Data_Format"></a>Data Format</h2>
<h2 id="Data_Format">Data Format</h2>
<p>
The Graph draws nodes and edges, which are both an Array with objects.
This section describes the data format of nodes and edges.
The <code>data</code> parameter of the Graph constructor is an object
which can contain different types of data.
The following properties are supported in the <code>data</code> object:
</p>
<h3>Nodes</h3>
<ul>
<li>
<span style="font-weight: bold;">A property pair <code>nodes</code> and <code>edges</code></span>,
both containing an Array with objects. The data formats are described
in the sections <a href="#Nodes">Nodes</a> and <a href="#Edges">Edges</a>.
Example:
<pre class="prettyprint lang-js">
var data = {
nodes: [...],
edges: [...]
};
</pre>
</li>
<li>
<span style="font-weight: bold;">A property <code>dot</code></span>,
containing a string with data in the
<a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
DOT support is described in section <a href="#DOT_language">DOT_language</a>.
Example:
<pre class="prettyprint lang-js">
var data = {
dot: '...'
};
</pre>
</li>
<li>
<span style="font-weight: bold;">A property <code>options</code></span>,
containing an object with global options.
Options can be provided as third parameter in the graph constructor
as well. Section <a href="#Configuration_Options">Configuration Options</a>
describes the available options.
</li>
</ul>
<h3 id="Nodes">Nodes</h3>
<p>
Nodes typically have an <code>id</code> and <code>text</code>.
@ -169,8 +215,8 @@ The constructor accepts three parameters:
<pre class="prettyprint lang-js">
var nodes = [
{
'id': 1,
'text': 'Node 1'
id: 1,
text: 'Node 1'
},
// ... more nodes
];
@ -205,7 +251,7 @@ var nodes = [
<tr>
<td>group</td>
<td>*</td>
<td>Number | String</td>
<td>no</td>
<td>A group number or name. The type can be <code>number</code>,
<code>string</code>, or an other type. All nodes with the same group get
@ -242,7 +288,7 @@ var nodes = [
<tr>
<td>id</td>
<td>*</td>
<td>Number | String</td>
<td>yes</td>
<td>A unique id for this node.
Nodes may not have duplicate id's.
@ -345,7 +391,7 @@ var nodes = [
</table>
<h3>Edges</h3>
<h3 id="Edges">Edges</h3>
<p>
Edges are connections between nodes.
@ -360,8 +406,8 @@ var nodes = [
<pre class="prettyprint lang-js">
var edges = [
{
'from': 1,
'to': 3
from: 1,
to: 3
},
// ... more edges
];
@ -395,7 +441,7 @@ var edges = [
<td>color</td>
<td>string</td>
<td>no</td>
<td>A HTML color for the link.</td>
<td>A HTML color for the edge.</td>
</tr>
<tr>
@ -418,7 +464,7 @@ var edges = [
<td>fontColor</td>
<td>String</td>
<td>"black"</td>
<td>Font color for the text label of the link.
<td>Font color for the text label of the edge.
Only applicable when "text" is defined.</td>
</tr>
@ -426,7 +472,7 @@ var edges = [
<td>fontFace</td>
<td>String</td>
<td>"sans"</td>
<td>Font face for the text label of the link,
<td>Font face for the text label of the edge,
for example "verdana" or "arial".
Only applicable when "text" is defined.</td>
</tr>
@ -435,15 +481,15 @@ var edges = [
<td>fontSize</td>
<td>Number</td>
<td>14</td>
<td>Font size in pixels for the text label of the link.
<td>Font size in pixels for the text label of the edge.
Only applicable when "text" is defined.</td>
</tr>
<tr>
<td>from</td>
<td>*</td>
<td>Number | String</td>
<td>yes</td>
<td>The id of a node where the link starts. The type must correspond with
<td>The id of a node where the edge starts. The type must correspond with
the type of the node id's. This is normally a number, but can be any
type.</td>
</tr>
@ -452,14 +498,14 @@ var edges = [
<td>length</td>
<td>number</td>
<td>no</td>
<td>The length of the link in pixels.</td>
<td>The length of the edge in pixels.</td>
</tr>
<tr>
<td>style</td>
<td>string</td>
<td>no</td>
<td>Define a drawing style for the link.
<td>Define a drawing style for the edge.
Choose from <code>line</code> (default), <code>arrow</code>,
<code>arrow-end</code>, or <code>dash-line</code>.
</td>
@ -469,22 +515,22 @@ var edges = [
<td>text</td>
<td>string</td>
<td>no</td>
<td>Text to be displayed halfway the link.</td>
<td>Text to be displayed halfway the edge.</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>no</td>
<td>Title to be displayed when the user hovers over the link.
<td>Title to be displayed when the user hovers over the edge.
The title can contain HTML code.</td>
</tr>
<tr>
<td>to</td>
<td>*</td>
<td>Number | String</td>
<td>yes</td>
<td>The id of a node where the link ends. The type must correspond with
<td>The id of a node where the edge ends. The type must correspond with
the type of the node id's. This is normally a number, but can be any
type.</td>
</tr>
@ -492,10 +538,10 @@ var edges = [
<td>value</td>
<td>number</td>
<td>no</td>
<td>A value for the link.
<td>A value for the edge.
The width of the edges will be scaled automatically from minimum to
maximum value.
If a <code>width</code> is provided for the link too, it will override the
If a <code>width</code> is provided for the edge too, it will override the
width calculated from the value.</td>
</tr>
@ -510,58 +556,33 @@ var edges = [
</table>
<h2><a name="Data_Import"></a>Data Import</h2>
<h3 id="DOT_language">DOT language</h3>
<p>
Graph contains parser to import data in the
Graph supports data in the
<a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
There following methods are available:
To provide data in the DOT language, the <code>data</code> object must contain
a property <code>dot</code> with a String containing the data.
</p>
<table>
<tr>
<th>Method</th>
<th>Return Type</th>
<th>Description</th>
</tr>
<tr>
<td>vis.util.parseDOT(data)</td>
<td>Object</td>
<td>
Parse a string containing data in DOT language into a JSON object.
The returned object contains two arrays, <code>nodes</code>,
<code>edges</code>, containing the parsed nodes and edges.
</td>
</tr>
<tr>
<td>vis.util.DOTToGraph(data)</td>
<td>Object</td>
<td>
Convert a string containing a graph in DOT language into a map
containing with nodes and edges in the format of Graph.
The returned object contains parameters <code>nodes</code>,
<code>edges</code>, and <code>options</code>, which can be used
directly to draw a graph using <code>setData(data)</code>.
</td>
</tr>
</table>
<p>
Example usage:
</p>
<pre class="prettyprint lang-js">
// parse data in DOT-notation
var dot = 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }';
var data = vis.util.DOTToGraph(dot);
// provide data in the DOT language
var data = {
dot: 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
};
// create a graph
var graph = new vis.Graph(container, data);
// create a graph
var graph = new vis.Graph(container, data);
</pre>
<h2><a name="Configuration_Options"></a>Configuration Options</h2>
<h2 id="Configuration_Options">Configuration Options</h2>
<p>
Options can be used to customize the graph. Options are defined as a JSON object.
@ -570,11 +591,11 @@ var edges = [
<pre class="prettyprint lang-js">
var options = {
'width': '100%',
'height': '400px',
'edges': {
'color': 'red',
'width': 2
width: '100%',
height: '400px',
edges: {
color: 'red',
width: 2
}
};
</pre>
@ -652,7 +673,7 @@ var options = {
<td>edges.color</td>
<td>String</td>
<td>"#2B7CE9"</td>
<td>The default color of a link.</td>
<td>The default color of a edge.</td>
</tr>
<tr>
@ -675,13 +696,13 @@ var options = {
<td>edges.length</td>
<td>Number</td>
<td>100</td>
<td>The default length of a link.</td>
<td>The default length of a edge.</td>
</tr>
<tr>
<td>edges.style</td>
<td>String</td>
<td>"line"</td>
<td>The default style of a link.
<td>The default style of a edge.
Choose from <code>line</code> (default), <code>arrow</code>,
<code>arrow-end</code>, <code>dash-line</code>.</td>
</tr>
@ -689,7 +710,7 @@ var options = {
<td>edges.width</td>
<td>Number</td>
<td>1</td>
<td>The default width of a link.</td>
<td>The default width of a edge.</td>
</tr>
<tr>
@ -813,7 +834,7 @@ var options = {
<br>
<h3><a name="Groups"></a>Groups</h3>
<h3 id="Groups">Groups</h3>
<p>It is possible to specify custom styles for groups of nodes.
Each node having assigned to this group gets the specified style.
@ -924,7 +945,7 @@ var nodes = [
</table>
<h2><a name="Methods"></a>Methods</h2>
<h2 id="Methods">Methods</h2>
<p>
Graph supports the following methods.
</p>
@ -988,7 +1009,7 @@ var nodes = [
</table>
<h2><a name="Events"></a>Events</h2>
<h2 id="Events">Events</h2>
<p>
Graph fires events after one or multiple nodes are selected.
The event can be catched by creating a listener.
@ -1042,7 +1063,7 @@ vis.events.addListener(graph, 'select', onselect);
</table>
<h2><a name="Data_Policy"></a>Data Policy</h2>
<h2 id="Data_Policy">Data Policy</h2>
<p>
All code and data are processed and rendered in the browser. No data is sent to any server.
</p>

+ 3
- 3
docs/index.html View File

@ -16,12 +16,12 @@
<h1>vis.js documentation</h1>
<p>The following pages are available:</p>
<p>Vis.js contains the following components:</p>
<ul>
<li><a href="timeline.html">Timeline</a></li>
<li><a href="graph.html">Graph</a></li>
<li><a href="dataset.html">DataSet</a></li>
<li><a href="graph.html">Graph</a></li>
<li><a href="timeline.html">Timeline</a></li>
</ul>
</div>

+ 10
- 5
docs/timeline.html View File

@ -183,6 +183,12 @@ var items = [
<td>yes</td>
<td>The contents of the item. This can be plain text or html code.</td>
</tr>
<tr>
<td>type</td>
<td>String</td>
<td>'box'</td>
<td>The type of the item. Can be 'box' (default), 'range', or 'point'.</td>
</tr>
<tr>
<td>group</td>
<td>any type</td>
@ -244,7 +250,7 @@ var options = {
<td>align</td>
<td>String</td>
<td>"center"</td>
<td>Alignment of items with style 'box'. Available values are
<td>Alignment of items with type 'box'. Available values are
'center' (default), 'left', or 'right').</td>
</tr>
@ -379,12 +385,11 @@ var options = {
</tr>
<tr>
<td>style</td>
<td>type</td>
<td>String</td>
<td>'box'</td>
<td>Specifies the style for the timeline items. Choose from 'dot' or 'box'.
Note that the content of the items can override this global style,
and can contain additional html formatting.
<td>Specifies the type for the timeline items. Choose from 'dot' or 'point'.
Note that individual items can override this global type.
</td>
</tr>

+ 4
- 10
examples/graph/19_dot_language.html View File

@ -18,18 +18,12 @@
<div id="mygraph"></div>
<script type="text/javascript">
// parse data in DOT-notation
var dot = 'digraph {node[shape=circle]; 1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }';
var data = vis.util.DOTToGraph(dot);
// create a graph
// create a graph, provide a DOT language file as data
var container = document.getElementById('mygraph');
var graph = new vis.Graph(container, data);
// resize the network when window resizes
window.onresize = function () {
graph.redraw()
var data = {
dot: 'digraph {node[shape=circle]; 1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
};
var graph = new vis.Graph(container, data);
</script>
</body>
</html>

+ 4
- 2
examples/graph/20_dot_language_playground.html View File

@ -92,8 +92,10 @@
try {
txtError.innerHTML = '';
// parse the data from DOT-notation
data = vis.util.DOTToGraph(txtData.value);
// Provide a string with data in DOT language
data = {
dot: txtData.value
};
// create a graph
var container = document.getElementById('mygraph');

+ 1
- 2
examples/timeline/01_basic.html View File

@ -24,8 +24,7 @@
{id: 5, content: 'item 5', start: '2013-04-25'},
{id: 6, content: 'item 6', start: '2013-04-27'}
];
var options = {
};
var options = {};
var timeline = new vis.Timeline(container, items, options);
</script>
</body>

+ 8
- 2
src/graph/Edge.js View File

@ -179,6 +179,7 @@ Edge.prototype.isOverlappingWith = function(obj) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawLine = function(ctx) {
// set style
@ -266,6 +267,7 @@ Edge.prototype._circle = function (ctx, x, y, radius) {
* @param {String} text
* @param {Number} x
* @param {Number} y
* @private
*/
Edge.prototype._text = function (ctx, text, x, y) {
if (text) {
@ -295,6 +297,7 @@ Edge.prototype._text = function (ctx, text, x, y) {
* @date 2012-08-08
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawDashLine = function(ctx) {
// set style
@ -361,6 +364,7 @@ Edge.prototype._pointOnCircle = function (x, y, radius, percentage) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawArrow = function(ctx) {
var point;
@ -436,6 +440,7 @@ Edge.prototype._drawArrow = function(ctx) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawArrowEnd = function(ctx) {
// set style
@ -481,12 +486,12 @@ Edge.prototype._drawArrowEnd = function(ctx) {
}
else {
// draw circle
var radius = this.length / 2 / Math.PI;
var x, y, arrow;
var node = this.from;
var x, y, arrow;
if (!node.width) {
node.resize(ctx);
}
var radius = (this.length + node.width) / 4;
if (node.width > node.height) {
x = node.x + node.width / 2;
y = node.y - radius;
@ -537,6 +542,7 @@ Edge.prototype._drawArrowEnd = function(ctx) {
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @private
*/
Edge._dist = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is the point
var px = x2-x1,

+ 84
- 23
src/graph/Graph.js View File

@ -87,17 +87,37 @@ function Graph (container, data, options) {
* Set nodes and edges, and optionally options as well.
*
* @param {Object} data Object containing parameters:
* {Array} nodes Array with nodes
* {Array} edges Array with edges
* {Array} [nodes] Array with nodes.
* Required when format is 'vis'
* {Array} [edges] Array with edges
* Required when format is 'vis'
* {String} [dot] String containing data in DOT
* format.
* {Options} [options] Object with options
*/
Graph.prototype.setData = function(data) {
if (data && data.dot && (data.nodes || data.edges)) {
throw new SyntaxError('Data must contain either parameter "dot" or ' +
' parameter pair "nodes" and "edges", but not both.');
}
// set options
this.setOptions(data && data.options);
// set all data
this._setNodes(data && data.nodes);
this._setEdges(data && data.edges);
if (data && data.dot) {
// parse DOT file
if(data && data.dot) {
var dotData = vis.util.DOTToGraph(data.dot);
this.setData(dotData);
return;
}
}
else {
this._setNodes(data && data.nodes);
this._setEdges(data && data.edges);
}
// find a stable position or start animating to a stable position
if (this.stabilize) {
@ -177,22 +197,17 @@ Graph.prototype.setOptions = function (options) {
this._setSize(this.width, this.height);
this._setTranslation(0, 0);
this._setScale(1.0);
this._setScale(1);
};
/**
* fire an event
* @param {String} event The name of an event, for example "select"
* @param {Object} params Optional object with event parameters
* @private
*/
Graph.prototype.trigger = function (event, params) {
// trigger the edges event bus
Graph.prototype._trigger = function (event, params) {
events.trigger(this, event, params);
// trigger the google event bus
if (typeof google !== 'undefined' && google.visualization && google.visualization.events) {
google.visualization.events.trigger(this, event, params);
}
};
@ -201,6 +216,7 @@ Graph.prototype.trigger = function (event, params) {
* This function is executed once when a Graph object is created. The frame
* contains a canvas, and this canvas contains all objects like the axis and
* nodes.
* @private
*/
Graph.prototype._create = function () {
// remove all elements from the container element.
@ -244,6 +260,7 @@ Graph.prototype._create = function () {
/**
* Set the background and border styling for the graph
* @param {String | Object} backgroundColor
* @private
*/
Graph.prototype._setBackgroundColor = function(backgroundColor) {
var fill = "white";
@ -268,6 +285,7 @@ Graph.prototype._setBackgroundColor = function(backgroundColor) {
}
this.frame.style.boxSizing = 'border-box';
this.frame.style.MozBoxSizing = 'border-box';
this.frame.style.backgroundColor = fill;
this.frame.style.borderColor = stroke;
this.frame.style.borderWidth = strokeWidth + "px";
@ -277,6 +295,7 @@ Graph.prototype._setBackgroundColor = function(backgroundColor) {
/**
* handle on mouse down event
* @private
*/
Graph.prototype._onMouseDown = function (event) {
event = event || window.event;
@ -367,6 +386,8 @@ Graph.prototype._onMouseDown = function (event) {
/**
* handle on mouse move event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseMove = function (event) {
event = event || window.event;
@ -433,6 +454,8 @@ Graph.prototype._onMouseMove = function (event) {
/**
* handle on mouse up event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseUp = function (event) {
event = event || window.event;
@ -498,7 +521,8 @@ Graph.prototype._onMouseUp = function (event) {
/**
* Event handler for mouse wheel event, used to zoom the timeline
* Code from http://adomas.org/javascript-mouse-wheel/
* @param {event} event The event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseWheel = function(event) {
event = event || window.event;
@ -559,6 +583,8 @@ Graph.prototype._onMouseWheel = function(event) {
/**
* Mouse move handler for checking whether the title moves over a node with a title.
* @param {Event} event
* @private
*/
Graph.prototype._onMouseMoveTitle = function (event) {
event = event || window.event;
@ -597,6 +623,7 @@ Graph.prototype._onMouseMoveTitle = function (event) {
*
* @param {number} x
* @param {number} y
* @private
*/
Graph.prototype._checkShowPopup = function (x, y) {
var obj = {
@ -661,6 +688,7 @@ Graph.prototype._checkShowPopup = function (x, y) {
* longer hovering on the object
* @param {number} x
* @param {number} y
* @private
*/
Graph.prototype._checkHidePopup = function (x, y) {
var obj = {
@ -680,6 +708,8 @@ Graph.prototype._checkHidePopup = function (x, y) {
/**
* Event handler for touchstart event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchStart = function(event) {
vis.util.preventDefault(event);
@ -705,6 +735,8 @@ Graph.prototype._onTouchStart = function(event) {
/**
* Event handler for touchmove event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchMove = function(event) {
vis.util.preventDefault(event);
@ -713,6 +745,8 @@ Graph.prototype._onTouchMove = function(event) {
/**
* Event handler for touchend event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchEnd = function(event) {
vis.util.preventDefault(event);
@ -740,6 +774,7 @@ Graph.prototype._onTouchEnd = function(event) {
* @param {Boolean} triggerSelect If true (default), the select event
* is triggered when nodes are unselected
* @return {Boolean} changed True if the selection is changed
* @private
*/
Graph.prototype._unselectNodes = function(selection, triggerSelect) {
var changed = false;
@ -775,7 +810,7 @@ Graph.prototype._unselectNodes = function(selection, triggerSelect) {
if (changed && (triggerSelect == true || triggerSelect == undefined)) {
// fire the select event
this.trigger('select');
this._trigger('select');
}
return changed;
@ -788,6 +823,7 @@ Graph.prototype._unselectNodes = function(selection, triggerSelect) {
* @param {boolean} append If true, the new selection will be appended to the
* current selection (except for duplicate entries)
* @return {Boolean} changed True if the selection is changed
* @private
*/
Graph.prototype._selectNodes = function(selection, append) {
var changed = false;
@ -838,7 +874,7 @@ Graph.prototype._selectNodes = function(selection, append) {
if (changed) {
// fire the select event
this.trigger('select');
this._trigger('select');
}
return changed;
@ -849,6 +885,7 @@ Graph.prototype._selectNodes = function(selection, append) {
* @param {Object} obj An object with parameters left, top, right, bottom
* @return {Object[]} An array with selection objects containing
* the parameter row.
* @private
*/
Graph.prototype._getNodesOverlappingWith = function (obj) {
var overlappingNodes = [];
@ -921,6 +958,7 @@ Graph.prototype.setSelection = function(selection) {
* to call them connected. Optional, 1 by default
* @return {Number[]} connectioncount array with the connection count
* for each node
* @private
*/
Graph.prototype._getConnectionCount = function(level) {
var conn = this.edges;
@ -999,6 +1037,7 @@ Graph.prototype._getConnectionCount = function(level) {
* or "50%")
* @param {string} height Height in pixels or percentage (for example "400px"
* or "30%")
* @private
*/
Graph.prototype._setSize = function(width, height) {
this.frame.style.width = width;
@ -1054,6 +1093,7 @@ Graph.prototype._setNodes = function(nodes) {
* The properties can contain a property "action", which can have values
* "create", "update", or "delete"
* @param {Object} properties An object with properties
* @private
*/
Graph.prototype._createNode = function(properties) {
var action = properties.action ? properties.action : "update";
@ -1151,9 +1191,10 @@ Graph.prototype._createNode = function(properties) {
/**
* Find a node by its id
* @param {Number} id Id of the node
* @return {Number} index Index of the node in the array this.nodes, or
* undefined when not found. *
* @param {Number} id Id of the node
* @return {Number | undefined} index Index of the node in the array
* this.nodes, or undefined when not found
* @private
*/
Graph.prototype._findNode = function (id) {
var nodes = this.nodes;
@ -1171,6 +1212,7 @@ Graph.prototype._findNode = function (id) {
* @param {Number} row Row number of the node
* @return {Node} node     The node with the given row number, or
*                            undefined when not found.
* @private
*/
Graph.prototype._findNodeByRow = function (row) {
return this.nodes[row];
@ -1180,6 +1222,7 @@ Graph.prototype._findNodeByRow = function (row) {
* Load edges by reading the data table
* @param {Array} edges The data containing the edges.
* @private
* @private
*/
Graph.prototype._setEdges = function(edges) {
this.edges = [];
@ -1218,6 +1261,7 @@ Graph.prototype._setEdges = function(edges) {
* The properties can contain a property "action", which can have values
* "create", "update", or "delete"
* @param {Object} properties An object with properties
* @private
*/
Graph.prototype._createEdge = function(properties) {
var action = properties.action ? properties.action : "create";
@ -1296,6 +1340,7 @@ Graph.prototype._createEdge = function(properties) {
* Update the references to oldNode in all edges.
* @param {Node} oldNode
* @param {Node} newNode
* @private
*/
// TODO: start utilizing this method _updateNodeReferences
Graph.prototype._updateNodeReferences = function(oldNode, newNode) {
@ -1313,9 +1358,10 @@ Graph.prototype._updateNodeReferences = function(oldNode, newNode) {
/**
* Find a edge by its id
* @param {Number} id Id of the edge
* @return {Number} index Index of the edge in the array this.edges, or
* undefined when not found. *
* @param {Number} id Id of the edge
* @return {Number | undefined} index Index of the edge in the array
* this.edges, or undefined when not found
* @private
*/
Graph.prototype._findEdge = function (id) {
var edges = this.edges;
@ -1331,7 +1377,8 @@ Graph.prototype._findEdge = function (id) {
/**
* Find a edge by its row
* @param {Number} row Row of the edge
* @return {Edge} the found edge, or undefined when not found
* @return {Edge | undefined} the found edge, or undefined when not found
* @private
*/
Graph.prototype._findEdgeByRow = function (row) {
return this.edges[row];
@ -1343,6 +1390,7 @@ Graph.prototype._findEdgeByRow = function (row) {
* @param {Array} array. An array with objects like Edges or Nodes
* The objects must have a method getValue() and
* setValueRange(min, max).
* @private
*/
Graph.prototype._updateValueRange = function(array) {
var count = array.length;
@ -1379,6 +1427,7 @@ Graph.prototype.redraw = function() {
/**
* Redraw the graph with the current data
* @private
*/
Graph.prototype._redraw = function() {
var ctx = this.frame.canvas.getContext("2d");
@ -1404,6 +1453,7 @@ Graph.prototype._redraw = function() {
* Set the translation of the graph
* @param {Number} offsetX Horizontal offset
* @param {Number} offsetY Vertical offset
* @private
*/
Graph.prototype._setTranslation = function(offsetX, offsetY) {
if (this.translation === undefined) {
@ -1424,6 +1474,7 @@ Graph.prototype._setTranslation = function(offsetX, offsetY) {
/**
* Get the translation of the graph
* @return {Object} translation An object with parameters x and y, both a number
* @private
*/
Graph.prototype._getTranslation = function() {
return {
@ -1435,6 +1486,7 @@ Graph.prototype._getTranslation = function() {
/**
* Scale the graph
* @param {Number} scale Scaling factor 1.0 is unscaled
* @private
*/
Graph.prototype._setScale = function(scale) {
this.scale = scale;
@ -1442,6 +1494,7 @@ Graph.prototype._setScale = function(scale) {
/**
* Get the current scale of the graph
* @return {Number} scale Scaling factor 1.0 is unscaled
* @private
*/
Graph.prototype._getScale = function() {
return this.scale;
@ -1469,6 +1522,7 @@ Graph.prototype._canvasToY = function(y) {
* Get a node by its id
* @param {number} id
* @return {Node} node, or null if not found
* @private
*/
Graph.prototype._getNode = function(id) {
for (var i = 0; i < this.nodes.length; i++) {
@ -1483,6 +1537,7 @@ Graph.prototype._getNode = function(id) {
* Redraw all nodes
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Graph.prototype._drawNodes = function(ctx) {
// first draw the unselected nodes
@ -1507,6 +1562,7 @@ Graph.prototype._drawNodes = function(ctx) {
* Redraw all edges
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Graph.prototype._drawEdges = function(ctx) {
var edges = this.edges;
@ -1517,6 +1573,7 @@ Graph.prototype._drawEdges = function(ctx) {
/**
* Recalculate the best positions for all nodes
* @private
*/
Graph.prototype._reposition = function() {
// TODO: implement function reposition
@ -1577,6 +1634,7 @@ Graph.prototype._reposition = function() {
/**
* Find a stable position for all nodes
* @private
*/
Graph.prototype._doStabilize = function() {
var start = new Date();
@ -1600,8 +1658,9 @@ Graph.prototype._doStabilize = function() {
/**
* Calculate the external forces acting on the nodes
* Forces are caused by: edges, repulsing forces between nodes, gravity
* @private
*/
Graph.prototype._calculateForces = function(nodeId) {
Graph.prototype._calculateForces = function() {
// create a local edge to the nodes and edges, that is faster
var nodes = this.nodes,
edges = this.edges;
@ -1738,6 +1797,7 @@ Graph.prototype._calculateForces = function(nodeId) {
* Check if any of the nodes is still moving
* @param {number} vmin the minimum velocity considered as "moving"
* @return {boolean} true if moving, false if non of the nodes is moving
* @private
*/
Graph.prototype._isMoving = function(vmin) {
// TODO: ismoving does not work well: should check the kinetic energy, not its velocity
@ -1753,6 +1813,7 @@ Graph.prototype._isMoving = function(vmin) {
/**
* Perform one discrete step for all nodes
* @private
*/
Graph.prototype._discreteStepNodes = function() {
var interval = this.refreshRate / 1000.0; // in seconds

+ 2
- 0
src/graph/Node.js View File

@ -197,6 +197,7 @@ Node.prototype.unselect = function() {
/**
* Reset the calculated size of the node, forces it to recalculate its size
* @private
*/
Node.prototype._reset = function() {
this.width = undefined;
@ -268,6 +269,7 @@ Node.prototype._setForce = function(fx, fy) {
* Add forces acting on the node
* @param {number} fx Force in horizontal direction
* @param {number} fy Force in vertical direction
* @private
*/
Node.prototype._addForce = function(fx, fy) {
this.fx += fx;

+ 16
- 13
src/graph/dotparser.js View File

@ -118,18 +118,20 @@ util.parseDOT = function (data) {
}
// cast string to number or boolean
var number = Number(name);
if (!isNaN(number)) {
name = number;
}
else if (name == 'true') {
name = true;
}
else if (name == 'false') {
name = false;
}
else if (name == 'null') {
name = null;
if (name.length) {
var number = Number(name);
if (!isNaN(number)) {
name = number;
}
else if (name == 'true') {
name = true;
}
else if (name == 'false') {
name = false;
}
else if (name == 'null') {
name = null;
}
}
}
@ -318,12 +320,13 @@ util.parseDOT = function (data) {
while (c && c != '}') {
// parse node id and optional node attributes
var id = parseString();
if (id == undefined) {
if (id == undefined || id === '') {
throw new SyntaxError('String with id expected ' + pos());
}
var attr = parseAttributes();
addNode(id, attr);
// TODO: parse global attributes
// TODO: parse global attributes "graph", "node", "edge"
// parse arrow

+ 4
- 3
src/timeline/component/ItemSet.js View File

@ -19,7 +19,7 @@ function ItemSet(parent, depends, options) {
// one options object is shared by this itemset and all its items
this.options = options || {};
this.defaultOptions = {
style: 'box',
type: 'box',
align: 'center',
orientation: 'bottom',
margin: {
@ -75,8 +75,8 @@ ItemSet.types = {
* @param {Object} [options] The following options are available:
* {String | function} [className]
* class name for the itemset
* {String} [style]
* Default style for the items. Choose from 'box'
* {String} [type]
* Default type for the items. Choose from 'box'
* (default), 'point', or 'range'. The default
* Style can be overwritten by individual items.
* {String} align
@ -211,6 +211,7 @@ ItemSet.prototype.repaint = function repaint() {
if (itemData) {
var type = itemData.type ||
(itemData.start && itemData.end && 'range') ||
options.type ||
'box';
var constructor = ItemSet.types[type];

+ 115
- 42
vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 0.0.8
* @date 2013-06-03
* @date 2013-06-04
*
* @license
* Copyright (C) 2011-2013 Almende B.V, http://almende.com
@ -4652,7 +4652,7 @@ function ItemSet(parent, depends, options) {
// one options object is shared by this itemset and all its items
this.options = options || {};
this.defaultOptions = {
style: 'box',
type: 'box',
align: 'center',
orientation: 'bottom',
margin: {
@ -4708,8 +4708,8 @@ ItemSet.types = {
* @param {Object} [options] The following options are available:
* {String | function} [className]
* class name for the itemset
* {String} [style]
* Default style for the items. Choose from 'box'
* {String} [type]
* Default type for the items. Choose from 'box'
* (default), 'point', or 'range'. The default
* Style can be overwritten by individual items.
* {String} align
@ -4844,6 +4844,7 @@ ItemSet.prototype.repaint = function repaint() {
if (itemData) {
var type = itemData.type ||
(itemData.start && itemData.end && 'range') ||
options.type ||
'box';
var constructor = ItemSet.types[type];
@ -6925,18 +6926,20 @@ util.parseDOT = function (data) {
}
// cast string to number or boolean
var number = Number(name);
if (!isNaN(number)) {
name = number;
}
else if (name == 'true') {
name = true;
}
else if (name == 'false') {
name = false;
}
else if (name == 'null') {
name = null;
if (name.length) {
var number = Number(name);
if (!isNaN(number)) {
name = number;
}
else if (name == 'true') {
name = true;
}
else if (name == 'false') {
name = false;
}
else if (name == 'null') {
name = null;
}
}
}
@ -7125,12 +7128,13 @@ util.parseDOT = function (data) {
while (c && c != '}') {
// parse node id and optional node attributes
var id = parseString();
if (id == undefined) {
if (id == undefined || id === '') {
throw new SyntaxError('String with id expected ' + pos());
}
var attr = parseAttributes();
addNode(id, attr);
// TODO: parse global attributes
// TODO: parse global attributes "graph", "node", "edge"
// parse arrow
@ -7683,6 +7687,7 @@ Node.prototype.unselect = function() {
/**
* Reset the calculated size of the node, forces it to recalculate its size
* @private
*/
Node.prototype._reset = function() {
this.width = undefined;
@ -7754,6 +7759,7 @@ Node.prototype._setForce = function(fx, fy) {
* Add forces acting on the node
* @param {number} fx Force in horizontal direction
* @param {number} fy Force in vertical direction
* @private
*/
Node.prototype._addForce = function(fx, fy) {
this.fx += fx;
@ -8275,6 +8281,7 @@ Edge.prototype.isOverlappingWith = function(obj) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawLine = function(ctx) {
// set style
@ -8362,6 +8369,7 @@ Edge.prototype._circle = function (ctx, x, y, radius) {
* @param {String} text
* @param {Number} x
* @param {Number} y
* @private
*/
Edge.prototype._text = function (ctx, text, x, y) {
if (text) {
@ -8391,6 +8399,7 @@ Edge.prototype._text = function (ctx, text, x, y) {
* @date 2012-08-08
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawDashLine = function(ctx) {
// set style
@ -8457,6 +8466,7 @@ Edge.prototype._pointOnCircle = function (x, y, radius, percentage) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawArrow = function(ctx) {
var point;
@ -8532,6 +8542,7 @@ Edge.prototype._drawArrow = function(ctx) {
* Draw this edge in the given canvas
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Edge.prototype._drawArrowEnd = function(ctx) {
// set style
@ -8577,12 +8588,12 @@ Edge.prototype._drawArrowEnd = function(ctx) {
}
else {
// draw circle
var radius = this.length / 2 / Math.PI;
var x, y, arrow;
var node = this.from;
var x, y, arrow;
if (!node.width) {
node.resize(ctx);
}
var radius = (this.length + node.width) / 4;
if (node.width > node.height) {
x = node.x + node.width / 2;
y = node.y - radius;
@ -8633,6 +8644,7 @@ Edge.prototype._drawArrowEnd = function(ctx) {
* @param {number} y2
* @param {number} x3
* @param {number} y3
* @private
*/
Edge._dist = function (x1,y1, x2,y2, x3,y3) { // x3,y3 is the point
var px = x2-x1,
@ -8978,17 +8990,37 @@ function Graph (container, data, options) {
* Set nodes and edges, and optionally options as well.
*
* @param {Object} data Object containing parameters:
* {Array} nodes Array with nodes
* {Array} edges Array with edges
* {Array} [nodes] Array with nodes.
* Required when format is 'vis'
* {Array} [edges] Array with edges
* Required when format is 'vis'
* {String} [dot] String containing data in DOT
* format.
* {Options} [options] Object with options
*/
Graph.prototype.setData = function(data) {
if (data && data.dot && (data.nodes || data.edges)) {
throw new SyntaxError('Data must contain either parameter "dot" or ' +
' parameter pair "nodes" and "edges", but not both.');
}
// set options
this.setOptions(data && data.options);
// set all data
this._setNodes(data && data.nodes);
this._setEdges(data && data.edges);
if (data && data.dot) {
// parse DOT file
if(data && data.dot) {
var dotData = vis.util.DOTToGraph(data.dot);
this.setData(dotData);
return;
}
}
else {
this._setNodes(data && data.nodes);
this._setEdges(data && data.edges);
}
// find a stable position or start animating to a stable position
if (this.stabilize) {
@ -9068,22 +9100,17 @@ Graph.prototype.setOptions = function (options) {
this._setSize(this.width, this.height);
this._setTranslation(0, 0);
this._setScale(1.0);
this._setScale(1);
};
/**
* fire an event
* @param {String} event The name of an event, for example "select"
* @param {Object} params Optional object with event parameters
* @private
*/
Graph.prototype.trigger = function (event, params) {
// trigger the edges event bus
Graph.prototype._trigger = function (event, params) {
events.trigger(this, event, params);
// trigger the google event bus
if (typeof google !== 'undefined' && google.visualization && google.visualization.events) {
google.visualization.events.trigger(this, event, params);
}
};
@ -9092,6 +9119,7 @@ Graph.prototype.trigger = function (event, params) {
* This function is executed once when a Graph object is created. The frame
* contains a canvas, and this canvas contains all objects like the axis and
* nodes.
* @private
*/
Graph.prototype._create = function () {
// remove all elements from the container element.
@ -9135,6 +9163,7 @@ Graph.prototype._create = function () {
/**
* Set the background and border styling for the graph
* @param {String | Object} backgroundColor
* @private
*/
Graph.prototype._setBackgroundColor = function(backgroundColor) {
var fill = "white";
@ -9159,6 +9188,7 @@ Graph.prototype._setBackgroundColor = function(backgroundColor) {
}
this.frame.style.boxSizing = 'border-box';
this.frame.style.MozBoxSizing = 'border-box';
this.frame.style.backgroundColor = fill;
this.frame.style.borderColor = stroke;
this.frame.style.borderWidth = strokeWidth + "px";
@ -9168,6 +9198,7 @@ Graph.prototype._setBackgroundColor = function(backgroundColor) {
/**
* handle on mouse down event
* @private
*/
Graph.prototype._onMouseDown = function (event) {
event = event || window.event;
@ -9258,6 +9289,8 @@ Graph.prototype._onMouseDown = function (event) {
/**
* handle on mouse move event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseMove = function (event) {
event = event || window.event;
@ -9324,6 +9357,8 @@ Graph.prototype._onMouseMove = function (event) {
/**
* handle on mouse up event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseUp = function (event) {
event = event || window.event;
@ -9389,7 +9424,8 @@ Graph.prototype._onMouseUp = function (event) {
/**
* Event handler for mouse wheel event, used to zoom the timeline
* Code from http://adomas.org/javascript-mouse-wheel/
* @param {event} event The event
* @param {Event} event
* @private
*/
Graph.prototype._onMouseWheel = function(event) {
event = event || window.event;
@ -9450,6 +9486,8 @@ Graph.prototype._onMouseWheel = function(event) {
/**
* Mouse move handler for checking whether the title moves over a node with a title.
* @param {Event} event
* @private
*/
Graph.prototype._onMouseMoveTitle = function (event) {
event = event || window.event;
@ -9488,6 +9526,7 @@ Graph.prototype._onMouseMoveTitle = function (event) {
*
* @param {number} x
* @param {number} y
* @private
*/
Graph.prototype._checkShowPopup = function (x, y) {
var obj = {
@ -9552,6 +9591,7 @@ Graph.prototype._checkShowPopup = function (x, y) {
* longer hovering on the object
* @param {number} x
* @param {number} y
* @private
*/
Graph.prototype._checkHidePopup = function (x, y) {
var obj = {
@ -9571,6 +9611,8 @@ Graph.prototype._checkHidePopup = function (x, y) {
/**
* Event handler for touchstart event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchStart = function(event) {
vis.util.preventDefault(event);
@ -9596,6 +9638,8 @@ Graph.prototype._onTouchStart = function(event) {
/**
* Event handler for touchmove event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchMove = function(event) {
vis.util.preventDefault(event);
@ -9604,6 +9648,8 @@ Graph.prototype._onTouchMove = function(event) {
/**
* Event handler for touchend event on mobile devices
* @param {Event} event
* @private
*/
Graph.prototype._onTouchEnd = function(event) {
vis.util.preventDefault(event);
@ -9631,6 +9677,7 @@ Graph.prototype._onTouchEnd = function(event) {
* @param {Boolean} triggerSelect If true (default), the select event
* is triggered when nodes are unselected
* @return {Boolean} changed True if the selection is changed
* @private
*/
Graph.prototype._unselectNodes = function(selection, triggerSelect) {
var changed = false;
@ -9666,7 +9713,7 @@ Graph.prototype._unselectNodes = function(selection, triggerSelect) {
if (changed && (triggerSelect == true || triggerSelect == undefined)) {
// fire the select event
this.trigger('select');
this._trigger('select');
}
return changed;
@ -9679,6 +9726,7 @@ Graph.prototype._unselectNodes = function(selection, triggerSelect) {
* @param {boolean} append If true, the new selection will be appended to the
* current selection (except for duplicate entries)
* @return {Boolean} changed True if the selection is changed
* @private
*/
Graph.prototype._selectNodes = function(selection, append) {
var changed = false;
@ -9729,7 +9777,7 @@ Graph.prototype._selectNodes = function(selection, append) {
if (changed) {
// fire the select event
this.trigger('select');
this._trigger('select');
}
return changed;
@ -9740,6 +9788,7 @@ Graph.prototype._selectNodes = function(selection, append) {
* @param {Object} obj An object with parameters left, top, right, bottom
* @return {Object[]} An array with selection objects containing
* the parameter row.
* @private
*/
Graph.prototype._getNodesOverlappingWith = function (obj) {
var overlappingNodes = [];
@ -9812,6 +9861,7 @@ Graph.prototype.setSelection = function(selection) {
* to call them connected. Optional, 1 by default
* @return {Number[]} connectioncount array with the connection count
* for each node
* @private
*/
Graph.prototype._getConnectionCount = function(level) {
var conn = this.edges;
@ -9890,6 +9940,7 @@ Graph.prototype._getConnectionCount = function(level) {
* or "50%")
* @param {string} height Height in pixels or percentage (for example "400px"
* or "30%")
* @private
*/
Graph.prototype._setSize = function(width, height) {
this.frame.style.width = width;
@ -9945,6 +9996,7 @@ Graph.prototype._setNodes = function(nodes) {
* The properties can contain a property "action", which can have values
* "create", "update", or "delete"
* @param {Object} properties An object with properties
* @private
*/
Graph.prototype._createNode = function(properties) {
var action = properties.action ? properties.action : "update";
@ -10042,9 +10094,10 @@ Graph.prototype._createNode = function(properties) {
/**
* Find a node by its id
* @param {Number} id Id of the node
* @return {Number} index Index of the node in the array this.nodes, or
* undefined when not found. *
* @param {Number} id Id of the node
* @return {Number | undefined} index Index of the node in the array
* this.nodes, or undefined when not found
* @private
*/
Graph.prototype._findNode = function (id) {
var nodes = this.nodes;
@ -10062,6 +10115,7 @@ Graph.prototype._findNode = function (id) {
* @param {Number} row Row number of the node
* @return {Node} node     The node with the given row number, or
*                            undefined when not found.
* @private
*/
Graph.prototype._findNodeByRow = function (row) {
return this.nodes[row];
@ -10071,6 +10125,7 @@ Graph.prototype._findNodeByRow = function (row) {
* Load edges by reading the data table
* @param {Array} edges The data containing the edges.
* @private
* @private
*/
Graph.prototype._setEdges = function(edges) {
this.edges = [];
@ -10109,6 +10164,7 @@ Graph.prototype._setEdges = function(edges) {
* The properties can contain a property "action", which can have values
* "create", "update", or "delete"
* @param {Object} properties An object with properties
* @private
*/
Graph.prototype._createEdge = function(properties) {
var action = properties.action ? properties.action : "create";
@ -10187,6 +10243,7 @@ Graph.prototype._createEdge = function(properties) {
* Update the references to oldNode in all edges.
* @param {Node} oldNode
* @param {Node} newNode
* @private
*/
// TODO: start utilizing this method _updateNodeReferences
Graph.prototype._updateNodeReferences = function(oldNode, newNode) {
@ -10204,9 +10261,10 @@ Graph.prototype._updateNodeReferences = function(oldNode, newNode) {
/**
* Find a edge by its id
* @param {Number} id Id of the edge
* @return {Number} index Index of the edge in the array this.edges, or
* undefined when not found. *
* @param {Number} id Id of the edge
* @return {Number | undefined} index Index of the edge in the array
* this.edges, or undefined when not found
* @private
*/
Graph.prototype._findEdge = function (id) {
var edges = this.edges;
@ -10222,7 +10280,8 @@ Graph.prototype._findEdge = function (id) {
/**
* Find a edge by its row
* @param {Number} row Row of the edge
* @return {Edge} the found edge, or undefined when not found
* @return {Edge | undefined} the found edge, or undefined when not found
* @private
*/
Graph.prototype._findEdgeByRow = function (row) {
return this.edges[row];
@ -10234,6 +10293,7 @@ Graph.prototype._findEdgeByRow = function (row) {
* @param {Array} array. An array with objects like Edges or Nodes
* The objects must have a method getValue() and
* setValueRange(min, max).
* @private
*/
Graph.prototype._updateValueRange = function(array) {
var count = array.length;
@ -10270,6 +10330,7 @@ Graph.prototype.redraw = function() {
/**
* Redraw the graph with the current data
* @private
*/
Graph.prototype._redraw = function() {
var ctx = this.frame.canvas.getContext("2d");
@ -10295,6 +10356,7 @@ Graph.prototype._redraw = function() {
* Set the translation of the graph
* @param {Number} offsetX Horizontal offset
* @param {Number} offsetY Vertical offset
* @private
*/
Graph.prototype._setTranslation = function(offsetX, offsetY) {
if (this.translation === undefined) {
@ -10315,6 +10377,7 @@ Graph.prototype._setTranslation = function(offsetX, offsetY) {
/**
* Get the translation of the graph
* @return {Object} translation An object with parameters x and y, both a number
* @private
*/
Graph.prototype._getTranslation = function() {
return {
@ -10326,6 +10389,7 @@ Graph.prototype._getTranslation = function() {
/**
* Scale the graph
* @param {Number} scale Scaling factor 1.0 is unscaled
* @private
*/
Graph.prototype._setScale = function(scale) {
this.scale = scale;
@ -10333,6 +10397,7 @@ Graph.prototype._setScale = function(scale) {
/**
* Get the current scale of the graph
* @return {Number} scale Scaling factor 1.0 is unscaled
* @private
*/
Graph.prototype._getScale = function() {
return this.scale;
@ -10360,6 +10425,7 @@ Graph.prototype._canvasToY = function(y) {
* Get a node by its id
* @param {number} id
* @return {Node} node, or null if not found
* @private
*/
Graph.prototype._getNode = function(id) {
for (var i = 0; i < this.nodes.length; i++) {
@ -10374,6 +10440,7 @@ Graph.prototype._getNode = function(id) {
* Redraw all nodes
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Graph.prototype._drawNodes = function(ctx) {
// first draw the unselected nodes
@ -10398,6 +10465,7 @@ Graph.prototype._drawNodes = function(ctx) {
* Redraw all edges
* The 2d context of a HTML canvas can be retrieved by canvas.getContext("2d");
* @param {CanvasRenderingContext2D} ctx
* @private
*/
Graph.prototype._drawEdges = function(ctx) {
var edges = this.edges;
@ -10408,6 +10476,7 @@ Graph.prototype._drawEdges = function(ctx) {
/**
* Recalculate the best positions for all nodes
* @private
*/
Graph.prototype._reposition = function() {
// TODO: implement function reposition
@ -10468,6 +10537,7 @@ Graph.prototype._reposition = function() {
/**
* Find a stable position for all nodes
* @private
*/
Graph.prototype._doStabilize = function() {
var start = new Date();
@ -10491,8 +10561,9 @@ Graph.prototype._doStabilize = function() {
/**
* Calculate the external forces acting on the nodes
* Forces are caused by: edges, repulsing forces between nodes, gravity
* @private
*/
Graph.prototype._calculateForces = function(nodeId) {
Graph.prototype._calculateForces = function() {
// create a local edge to the nodes and edges, that is faster
var nodes = this.nodes,
edges = this.edges;
@ -10629,6 +10700,7 @@ Graph.prototype._calculateForces = function(nodeId) {
* Check if any of the nodes is still moving
* @param {number} vmin the minimum velocity considered as "moving"
* @return {boolean} true if moving, false if non of the nodes is moving
* @private
*/
Graph.prototype._isMoving = function(vmin) {
// TODO: ismoving does not work well: should check the kinetic energy, not its velocity
@ -10644,6 +10716,7 @@ Graph.prototype._isMoving = function(vmin) {
/**
* Perform one discrete step for all nodes
* @private
*/
Graph.prototype._discreteStepNodes = function() {
var interval = this.refreshRate / 1000.0; // in seconds

+ 6
- 6
vis.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save