vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2165 lines
67 KiB

11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | graph documentation</title>
  5. <link href="css/prettify.css" type="text/css" rel="stylesheet" />
  6. <link href='css/style.css' type='text/css' rel='stylesheet'>
  7. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  8. </head>
  9. <body onload="prettyPrint();">
  10. <div id="container">
  11. <h1>Graph documentation</h1>
  12. <h2 id="Overview">Overview</h2>
  13. <p>
  14. Graph is a visualization to display graphs and networks consisting of nodes
  15. and edges. The visualization is easy to use and supports custom shapes,
  16. styles, colors, sizes, images, and more.
  17. </p>
  18. <p>
  19. The graph visualization works smooth on any modern browser for up to a
  20. few thousand nodes and edges. To handle a larger amount of nodes, Graph
  21. has <a href="#Clustering">clustering</a> support.
  22. </p>
  23. <p>
  24. Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, graph has a special option
  25. that the user can use to explore which settings may be good for you. Use configurePhysics as described in the <u><a href="#PhysicsConfiguration">Physics</a></u> section or by
  26. <u><a href="../examples/graph/25_physics_configuration.html">example 25</a></u>.
  27. </p>
  28. <p>
  29. To get started with Graph, install or download the
  30. <a href="http://visjs.org" target="_blank">vis.js</a> library.
  31. </p>
  32. <h2><a name="Contents"></a>Contents</h2>
  33. <ul>
  34. <li><a href="#Overview">Overview</a></li>
  35. <li><a href="#Example">Example</a></li>
  36. <li><a href="#Loading">Loading</a></li>
  37. <li>
  38. <a href="#Data_format">Data format</a>
  39. <ul>
  40. <li><a href="#Nodes">Nodes</a></li>
  41. <li><a href="#Edges">Edges</a></li>
  42. <li><a href="#DOT_language">DOT language</a></li>
  43. </ul>
  44. </li>
  45. <li>
  46. <a href="#Configuration_options">Configuration options</a>
  47. <ul>
  48. <li><a href="#Nodes_configuration">Nodes</a></li>
  49. <li><a href="#Edges_configuration">Edges</a></li>
  50. <li><a href="#Groups_configuration">Groups</a></li>
  51. <li><a href="#Physics">Physics</a></li>
  52. <li><a href="#Data_manipulation">Data manipulation</a></li>
  53. <li><a href="#Clustering">Clustering</a></li>
  54. <li><a href="#Navigation_controls">Navigation controls</a></li>
  55. <li><a href="#Keyboard_navigation">Keyboard navigation</a></li>
  56. <li><a href="#Hierarchical_layout">Hierarchical layout</a></li>
  57. <li><a href="#Localization">Localization</a></li>
  58. <li><a href="#Tooltips">Tooltips</a></li>
  59. </ul>
  60. </li>
  61. <li><a href="#Methods">Methods</a></li>
  62. <li><a href="#Events">Events</a></li>
  63. <li><a href="#Data_policy">Data policy</a></li>
  64. </ul>
  65. <h2 id="Example">Example</h2>
  66. <p>
  67. Here a basic graph example. Note that unlike the
  68. <a href="timeline.html">Timeline</a>, the Graph does not need the vis.css
  69. file.
  70. </p>
  71. <p>
  72. More examples can be found in the
  73. <a href="../examples" target="_blank">examples directory</a>.
  74. </p>
  75. <pre class="prettyprint lang-html">&lt;!doctype html&gt;
  76. &lt;html&gt;
  77. &lt;head&gt;
  78. &lt;title&gt;Graph | Basic usage&lt;/title&gt;
  79. &lt;script type="text/javascript" src="../../dist/vis.js"&gt;&lt;/script&gt;
  80. &lt;/head&gt;
  81. &lt;body&gt;
  82. &lt;div id="mygraph"&gt;&lt;/div&gt;
  83. &lt;script type="text/javascript"&gt;
  84. // create an array with nodes
  85. var nodes = [
  86. {id: 1, label: 'Node 1'},
  87. {id: 2, label: 'Node 2'},
  88. {id: 3, label: 'Node 3'},
  89. {id: 4, label: 'Node 4'},
  90. {id: 5, label: 'Node 5'}
  91. ];
  92. // create an array with edges
  93. var edges = [
  94. {from: 1, to: 2},
  95. {from: 1, to: 3},
  96. {from: 2, to: 4},
  97. {from: 2, to: 5}
  98. ];
  99. // create a graph
  100. var container = document.getElementById('mygraph');
  101. var data= {
  102. nodes: nodes,
  103. edges: edges,
  104. };
  105. var options = {
  106. width: '400px',
  107. height: '400px'
  108. };
  109. var graph = new vis.Graph(container, data, options);
  110. &lt;/script&gt;
  111. &lt;/body&gt;
  112. &lt;/html&gt;
  113. </pre>
  114. <h2 id="Loading">Loading</h2>
  115. <p>
  116. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  117. in a subfolder of your project. Include the library script in the head of your html code:
  118. </p>
  119. <pre class="prettyprint lang-html">
  120. &lt;script type="text/javascript" src="vis/dist/vis.js"&gt;&lt;/script&gt;
  121. </pre>
  122. The constructor of the Graph is <code>vis.Graph</code>.
  123. <pre class="prettyprint lang-js">var graph = new vis.Graph(container, data, options);</pre>
  124. The constructor accepts three parameters:
  125. <ul>
  126. <li>
  127. <code>container</code> is the DOM element in which to create the graph.
  128. </li>
  129. <li>
  130. <code>data</code> is an Object containing properties <code>nodes</code> and
  131. <code>edges</code>, which both contain an array with objects.
  132. Optionally, data may contain an <code>options</code> object.
  133. The parameter <code>data</code> is optional, data can also be set using
  134. the method <code>setData</code>. Section <a href="#Data_Format">Data Format</a>
  135. describes the data object.
  136. </li>
  137. <li>
  138. <code>options</code> is an optional Object containing a name-value map
  139. with options. Options can also be set using the method
  140. <code>setOptions</code>.
  141. Section <a href="#Configuration_Options">Configuration Options</a>
  142. describes the available options.
  143. </li>
  144. </ul>
  145. <h2 id="Data_format">Data format</h2>
  146. <p>
  147. The <code>data</code> parameter of the Graph constructor is an object
  148. which can contain different types of data.
  149. The following properties are supported in the <code>data</code> object:
  150. </p>
  151. <ul>
  152. <li>
  153. <span style="font-weight: bold;">A property pair <code>nodes</code> and <code>edges</code></span>,
  154. both containing an Array with objects. The data formats are described
  155. in the sections <a href="#Nodes">Nodes</a> and <a href="#Edges">Edges</a>.
  156. Example:
  157. <pre class="prettyprint lang-js">
  158. var data = {
  159. nodes: [...],
  160. edges: [...]
  161. };
  162. </pre>
  163. </li>
  164. <li>
  165. <span style="font-weight: bold;">A property <code>dot</code></span>,
  166. containing a string with data in the
  167. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  168. DOT support is described in section <a href="#DOT_language">DOT_language</a>.
  169. Example:
  170. <pre class="prettyprint lang-js">
  171. var data = {
  172. dot: '...'
  173. };
  174. </pre>
  175. </li>
  176. <li>
  177. <span style="font-weight: bold;">A property <code>options</code></span>,
  178. containing an object with global options.
  179. Options can be provided as third parameter in the graph constructor
  180. as well. Section <a href="#Configuration_Options">Configuration Options</a>
  181. describes the available options.
  182. </li>
  183. </ul>
  184. <h3 id="Nodes">Nodes</h3>
  185. <p>
  186. Nodes typically have an <code>id</code> and <code>label</code>.
  187. A node must contain at least a property <code>id</code>.
  188. Nodes can have extra properties, used to define the shape and style of the
  189. nodes.
  190. </p>
  191. <p>
  192. A JavaScript Array with nodes is constructed like:
  193. </p>
  194. <pre class="prettyprint lang-js">
  195. var nodes = [
  196. {
  197. id: 1,
  198. label: 'Node 1'
  199. },
  200. // ... more nodes
  201. ];
  202. </pre>
  203. <p>
  204. Nodes support the following properties:
  205. </p>
  206. <table>
  207. <tr>
  208. <th>Name</th>
  209. <th>Type</th>
  210. <th>Required</th>
  211. <th>Description</th>
  212. </tr>
  213. <tr>
  214. <td>color</td>
  215. <td>String | Object</td>
  216. <td>no</td>
  217. <td>Color for the node.</td>
  218. </tr>
  219. <tr>
  220. <td>color.background</td>
  221. <td>String</td>
  222. <td>no</td>
  223. <td>Background color for the node.</td>
  224. </tr>
  225. <tr>
  226. <td>color.border</td>
  227. <td>String</td>
  228. <td>no</td>
  229. <td>Border color for the node.</td>
  230. </tr>
  231. <tr>
  232. <td>color.highlight</td>
  233. <td>String | Object</td>
  234. <td>no</td>
  235. <td>Color of the node when selected.</td>
  236. </tr>
  237. <tr>
  238. <td>color.highlight.background</td>
  239. <td>String</td>
  240. <td>no</td>
  241. <td>Background color of the node when selected.</td>
  242. </tr>
  243. <tr>
  244. <td>color.highlight.border</td>
  245. <td>String</td>
  246. <td>no</td>
  247. <td>Border color of the node when selected.</td>
  248. </tr>
  249. <tr>
  250. <td>group</td>
  251. <td>Number | String</td>
  252. <td>no</td>
  253. <td>A group number or name. The type can be <code>number</code>,
  254. <code>string</code>, or an other type. All nodes with the same group get
  255. the same color schema.</td>
  256. </tr>
  257. <tr>
  258. <td>allowedToMoveX</td>
  259. <td>Boolean</td>
  260. <td>false</td>
  261. <td>If allowedToMoveX is false, then the node will not move from its supplied position.
  262. If an X position has been supplied, it is fixed in the X-direction.
  263. If no X value has been supplied, this argument will not do anything.</td>
  264. </tr>
  265. <tr>
  266. <td>allowedToMoveY</td>
  267. <td>Boolean</td>
  268. <td>false</td>
  269. <td>If allowedToMoveY is false, then the node will not move from its supplied position.
  270. If an Y position has been supplied, it is fixed in the Y-direction.
  271. If no Y value has been supplied, this argument will not do anything.</td>
  272. </tr>
  273. <tr>
  274. <td>fontColor</td>
  275. <td>String</td>
  276. <td>no</td>
  277. <td>Font color for label in the node.</td>
  278. </tr>
  279. <tr>
  280. <td>fontFace</td>
  281. <td>String</td>
  282. <td>no</td>
  283. <td>Font face for label in the node, for example "verdana" or "arial".</td>
  284. </tr>
  285. <tr>
  286. <td>fontSize</td>
  287. <td>Number</td>
  288. <td>no</td>
  289. <td>Font size in pixels for label in the node.</td>
  290. </tr>
  291. <tr>
  292. <td>id</td>
  293. <td>Number | String</td>
  294. <td>yes</td>
  295. <td>A unique id for this node.
  296. Nodes may not have duplicate id's.
  297. Id's do not need to be consecutive.
  298. An id is normally a number, but may be any type.</td>
  299. </tr>
  300. <tr>
  301. <td>image</td>
  302. <td>string</td>
  303. <td>no</td>
  304. <td>Url of an image. Only applicable when the shape of the node is
  305. <code>image</code>.</td>
  306. </tr>
  307. <tr>
  308. <td>mass</td>
  309. <td>number</td>
  310. <td>1</td>
  311. <td>When using the Barnes Hut simulation method (which is selected by default),
  312. the mass of a node determines the gravitational repulsion during the simulation. Higher mass will push other nodes further away.</td>
  313. </tr>
  314. <tr>
  315. <td>level</td>
  316. <td>number</td>
  317. <td>-1</td>
  318. <td>This level is used in the hierarchical layout. If this is not selected, the level does not do anything.</td>
  319. </tr>
  320. <tr>
  321. <td>radius</td>
  322. <td>number</td>
  323. <td>no</td>
  324. <td>Radius for the node. Applicable for all shapes except <code>box</code>,
  325. <code>circle</code>, <code>ellipse</code> and <code>database</code>.
  326. The value of <code>radius</code> will override a value in
  327. property <code>value</code>.</td>
  328. </tr>
  329. <tr>
  330. <td>shape</td>
  331. <td>string</td>
  332. <td>no</td>
  333. <td>Define the shape for the node.
  334. Choose from
  335. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  336. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  337. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  338. <br><br>
  339. In case of <code>image</code>, a property with name <code>image</code> must
  340. be provided, containing image urls.
  341. <br><br>
  342. The shapes <code>dot</code>, <code>star</code>, <code>triangle</code>,
  343. <code>triangleDown</code>, and <code>square</code>, are scalable.
  344. The size is determined by the properties <code>radius</code> or
  345. <code>value</code>.
  346. <br><br>
  347. When a property <code>label</code> is provided,
  348. this label will be displayed inside the shape in case of shapes
  349. <code>box</code>, <code>circle</code>, <code>ellipse</code>,
  350. and <code>database</code>.
  351. For all other shapes, the label will be displayed right below the shape.
  352. </td>
  353. </tr>
  354. <tr>
  355. <td>label</td>
  356. <td>string</td>
  357. <td>no</td>
  358. <td>Text label to be displayed in the node or under the image of the node.
  359. Multiple lines can be separated by a newline character <code>\n</code> .</td>
  360. </tr>
  361. <tr>
  362. <td>title</td>
  363. <td>string | function</td>
  364. <td>no</td>
  365. <td>Title to be displayed when the user hovers over the node.
  366. The title can contain HTML code. If using a function, returning <code>undefined</code>
  367. will prevent the tooltip from being displayed.</td>
  368. </tr>
  369. <tr>
  370. <td>value</td>
  371. <td>number</td>
  372. <td>no</td>
  373. <td>A value for the node.
  374. The radius of the nodes will be scaled automatically from minimum to
  375. maximum value.
  376. Only applicable when the shape of the node is <code>dot</code>.
  377. If a <code>radius</code> is provided for the node too, it will override the
  378. radius calculated from the value.</td>
  379. </tr>
  380. <tr>
  381. <td>x</td>
  382. <td>number</td>
  383. <td>no</td>
  384. <td>Horizontal position in pixels.
  385. The horizontal position of the node will be fixed.
  386. The vertical position y may remain undefined.</td>
  387. </tr>
  388. <tr>
  389. <td>y</td>
  390. <td>number</td>
  391. <td>no</td>
  392. <td>Vertical position in pixels.
  393. The vertical position of the node will be fixed.
  394. The horizontal position x may remain undefined.</td>
  395. </tr>
  396. </table>
  397. <h3 id="Edges">Edges</h3>
  398. <p>
  399. Edges are connections between nodes.
  400. An edge must at least contain properties <code>from</code> and
  401. <code>to</code>, both referring to the <code>id</code> of a node.
  402. Edges can have extra properties, used to define the type and style.
  403. </p>
  404. <p>
  405. A JavaScript Array with edges is constructed as:
  406. </p>
  407. <pre class="prettyprint lang-js">
  408. var edges = [
  409. {
  410. from: 1,
  411. to: 3
  412. },
  413. // ... more edges
  414. ];
  415. </pre>
  416. <p>
  417. Edges support the following properties:
  418. </p>
  419. <table>
  420. <tr>
  421. <th>Name</th>
  422. <th>Type</th>
  423. <th>Required</th>
  424. <th>Description</th>
  425. </tr>
  426. <tr>
  427. <td>color</td>
  428. <td>String | Object</td>
  429. <td>no</td>
  430. <td>Color for the edge.</td>
  431. </tr>
  432. <tr>
  433. <td>color.color</td>
  434. <td>String</td>
  435. <td>no</td>
  436. <td>Color of the edge when not selected.</td>
  437. </tr>
  438. <tr>
  439. <td>color.highlight</td>
  440. <td>String</td>
  441. <td>no</td>
  442. <td>Color of the edge when selected.</td>
  443. </tr>
  444. <tr>
  445. <td>dash</td>
  446. <td>Object</td>
  447. <td>no</td>
  448. <td>
  449. Object containing properties for dashed lines.
  450. Available properties: <code>length</code>, <code>gap</code>,
  451. <code>altLength</code>.
  452. </td>
  453. </tr>
  454. <tr>
  455. <td>dash.altLength</td>
  456. <td>number</td>
  457. <td>no</td>
  458. <td>Length of the alternated dash in pixels on a dashed line.
  459. Specifying <code>dash.altLength</code> allows for creating
  460. a dashed line with a dash-dot style, for example when
  461. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  462. See also the option <code>dahs.length</code>.
  463. Only applicable when the line style is <code>dash-line</code>.</td>
  464. </tr>
  465. <tr>
  466. <td>dash.length</td>
  467. <td>number</td>
  468. <td>no</td>
  469. <td>Length of a dash in pixels on a dashed line.
  470. Only applicable when the line style is <code>dash-line</code>.</td>
  471. </tr>
  472. <tr>
  473. <td>dash.gap</td>
  474. <td>number</td>
  475. <td>no</td>
  476. <td>Length of a gap in pixels on a dashed line.
  477. Only applicable when the line style is <code>dash-line</code>.</td>
  478. </tr>
  479. <tr>
  480. <td>fontColor</td>
  481. <td>String</td>
  482. <td>no</td>
  483. <td>Font color for the text label of the edge.
  484. Only applicable when property <code>label</code> is defined.</td>
  485. </tr>
  486. <tr>
  487. <td>fontFace</td>
  488. <td>String</td>
  489. <td>no</td>
  490. <td>Font face for the text label of the edge,
  491. for example "verdana" or "arial".
  492. Only applicable when property <code>label</code> is defined.</td>
  493. </tr>
  494. <tr>
  495. <td>fontSize</td>
  496. <td>Number</td>
  497. <td>no</td>
  498. <td>Font size in pixels for the text label of the edge.
  499. Only applicable when property <code>label</code> is defined.</td>
  500. </tr>
  501. <tr>
  502. <td>fontFill</td>
  503. <td>string</td>
  504. <td>no</td>
  505. <td>Font fill for the background color of the text label of the edge.
  506. Only applicable when property <code>label</code> is defined.</td>
  507. </tr>
  508. <tr>
  509. <td>from</td>
  510. <td>Number | String</td>
  511. <td>yes</td>
  512. <td>The id of a node where the edge starts. The type must correspond with
  513. the type of the node id's. This is normally a number, but can be any
  514. type.</td>
  515. </tr>
  516. <tr>
  517. <td>style</td>
  518. <td>string</td>
  519. <td>no</td>
  520. <td>Define a line style for the edge.
  521. Choose from <code>line</code> (default), <code>arrow</code>,
  522. <code>arrow-center</code>, or <code>dash-line</code>.
  523. </td>
  524. </tr>
  525. <tr>
  526. <td>label</td>
  527. <td>string</td>
  528. <td>no</td>
  529. <td>Text label to be displayed halfway the edge.</td>
  530. </tr>
  531. <tr>
  532. <td>length</td>
  533. <td>number</td>
  534. <td>physics.[method].springLength</td>
  535. <td>The resting length of the edge when modeled as a spring. By default the springLength determined by the physics is used. By using this setting you can make certain edges have different resting lengths.</td>
  536. </tr>
  537. <tr>
  538. <td>title</td>
  539. <td>string | function</td>
  540. <td>no</td>
  541. <td>Title to be displayed when the user hovers over the edge.
  542. The title can contain HTML code. If using a function, returning <code>undefined</code>
  543. will prevent the tooltip from being displayed.</td>
  544. </tr>
  545. <tr>
  546. <td>to</td>
  547. <td>Number | String</td>
  548. <td>yes</td>
  549. <td>The id of a node where the edge ends. The type must correspond with
  550. the type of the node id's. This is normally a number, but can be any
  551. type.</td>
  552. </tr>
  553. <tr>
  554. <td>value</td>
  555. <td>number</td>
  556. <td>no</td>
  557. <td>A value for the edge.
  558. The width of the edges will be scaled automatically from minimum to
  559. maximum value.
  560. If a <code>width</code> is provided for the edge too, it will override the
  561. width calculated from the value.</td>
  562. </tr>
  563. <tr>
  564. <td>width</td>
  565. <td>number</td>
  566. <td>no</td>
  567. <td>Width of the line in pixels. The <code>width</code> will
  568. override a specified <code>value</code>, if a <code>value</code> is
  569. specified too.</td>
  570. </tr>
  571. </table>
  572. <h3 id="DOT_language">DOT language</h3>
  573. <p>
  574. Graph supports data in the
  575. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  576. To provide data in the DOT language, the <code>data</code> object must contain
  577. a property <code>dot</code> with a String containing the data.
  578. </p>
  579. <p>
  580. Example usage:
  581. </p>
  582. <pre class="prettyprint lang-js">
  583. // provide data in the DOT language
  584. var data = {
  585. dot: 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
  586. };
  587. // create a graph
  588. var graph = new vis.Graph(container, data);
  589. </pre>
  590. <h2 id="Configuration_options">Configuration options</h2>
  591. <p>
  592. Options can be used to customize the graph. Options are defined as a JSON object.
  593. All options are optional.
  594. </p>
  595. <pre class="prettyprint lang-js">
  596. var options = {
  597. width: '100%',
  598. height: '400px',
  599. edges: {
  600. color: 'red',
  601. width: 2
  602. }
  603. };
  604. </pre>
  605. <p>
  606. The following options are available.
  607. </p>
  608. <table>
  609. <tr>
  610. <th>Name</th>
  611. <th>Type</th>
  612. <th>Default</th>
  613. <th>Description</th>
  614. </tr>
  615. <tr>
  616. <td><a href="#Physics">physics</a></td>
  617. <td>Object</td>
  618. <td>none</td>
  619. <td>
  620. Configuration of the physics system governing the simulation of the nodes and edges.
  621. Barnes-Hut nBody simulation is used by default. See section <a href="#Physics">Physics</a> for an overview of the available options.
  622. </td>
  623. </tr>
  624. <tr>
  625. <td><a href="#Physics">configurePhysics</a></td>
  626. <td>Boolean</td>
  627. <td>false</td>
  628. <td>
  629. Enabling this setting will create a physics configuration div above the graph. You can use this to fine tune the physics system to suit your needs.
  630. Because of the many possible configurations, there is not a one-size-fits-all setting. By using this tool, you can adapt the physics to your dataset.
  631. </td>
  632. </tr>
  633. <tr>
  634. <td><a href="#Data_manipulation">dataManipulation</a></td>
  635. <td>Object</td>
  636. <td>none</td>
  637. <td>
  638. Settings for manipulating the Dataset. See section <a href="#Data_manipulation">Data manipulation</a> for an overview of the available options.
  639. </td>
  640. </tr>
  641. <tr>
  642. <td><a href="#Clustering">clustering</a></td>
  643. <td>Object</td>
  644. <td>none</td>
  645. <td>
  646. Clustering configuration. Clustering is turned off by default. See section <a href="#Clustering">Clustering</a> for an overview of the available options.
  647. </td>
  648. </tr>
  649. <tr>
  650. <td><a href="#Edges_configuration">edges</a></td>
  651. <td>Object</td>
  652. <td>none</td>
  653. <td>
  654. Configuration options applied to all edges. See section <a href="#Edges_configuration">Edges configuration</a> for an overview of the available options.
  655. </td>
  656. </tr>
  657. <tr>
  658. <td>freezeForStabilization</a></td>
  659. <td>Boolean</td>
  660. <td>false</td>
  661. <td>
  662. With the advent of the storePosition() function, the positions of the nodes can be saved after they are stabilized. The smoothCurves require support nodes and those positions are not stored. In order
  663. to speed up the initialization of the graph by using storePosition() and loading the nodes with the stored positions, the freezeForStabilization option freezes all nodes that have been supplied with
  664. an x and y position in place during the stabilization. That way only the support nodes for the smooth curves have to stabilize, greatly speeding up the stabilization process with cached positions.
  665. </td>
  666. </tr>
  667. <tr>
  668. <td><a href="#Groups_configuration">groups</a></td>
  669. <td>Object</td>
  670. <td>none</td>
  671. <td>It is possible to specify custom styles for groups.
  672. Each node assigned a group gets the specified style.
  673. See <a href="#Groups_configuration">Groups configuration</a> for an overview of the available styles
  674. and an example.
  675. </td>
  676. </tr>
  677. <tr>
  678. <td>height</td>
  679. <td>String</td>
  680. <td>"400px"</td>
  681. <td>The height of the graph in pixels or as a percentage.</td>
  682. </tr>
  683. <tr>
  684. <td><a href="#Keyboard_navigation">keyboard</a></td>
  685. <td>Object</td>
  686. <td>none</td>
  687. <td>
  688. Configuration options for shortcuts keys. Sortcut keys are turned off by default. See section <a href="#Keyboard_navigation">Keyboard navigation</a> for an overview of the available options.
  689. </td>
  690. </tr>
  691. <tr>
  692. <td><a href="#Navigation_controls">navigation</a></td>
  693. <td>Object</td>
  694. <td>none</td>
  695. <td>
  696. Configuration options for the navigation controls. See section <a href="#Navigation_controls">Navigation controls</a> for an overview of the available options.
  697. </td>
  698. </tr>
  699. <tr>
  700. <td><a href="#Nodes_configuration">nodes</a></td>
  701. <td>Object</td>
  702. <td>none</td>
  703. <td>
  704. Configuration options applied to all nodes. See section <a href="#Nodes_configuration">Nodes configuration</a> for an overview of the available options.
  705. </td>
  706. </tr>
  707. <tr>
  708. <td>smoothCurves</td>
  709. <td>Boolean</td>
  710. <td>true</td>
  711. <td>If true, edges are drawn as smooth curves. This is more computationally intensive since the edge now is a quadratic Bezier curve with control points on both nodes and an invisible node in the center of the edge. This support node is also handed by the physics simulation.</td>
  712. </tr>
  713. <tr>
  714. <td>selectable</td>
  715. <td>Boolean</td>
  716. <td>true</td>
  717. <td>If true, nodes in the graph can be selected by clicking them.
  718. Long press can be used to select multiple nodes.</td>
  719. </tr>
  720. <tr>
  721. <td>stabilize</td>
  722. <td>Boolean</td>
  723. <td>true</td>
  724. <td>If true, the graph is stabilized before displaying it. If false,
  725. the nodes move to a stabe position visibly in an animated way.</td>
  726. </tr>
  727. <tr>
  728. <td>stabilizationIterations</td>
  729. <td>Number</td>
  730. <td>1000</td>
  731. <td>If stabilize is set to true, this number is the (maximum) amount of physics steps the stabilization process takes
  732. before showing the result. If your simulation takes too long to stabilize, this number can be reduced. On the other hand, if your graph is not stabilized after loading, this number can be increased.</td>
  733. </tr>
  734. <tr>
  735. <td>width</td>
  736. <td>String</td>
  737. <td>"400px"</td>
  738. <td>The width of the graph in pixels or as a percentage.</td>
  739. </tr>
  740. </table>
  741. <br>
  742. <h3 id="Nodes_configuration">Nodes configuration</h3>
  743. <p>
  744. Nodes can be configured with different styles and shapes. To configure nodes, provide an object named <code>nodes</code> in the <code>options</code> for the Graph.
  745. </p>
  746. <p>
  747. For example to give the nodes a custom color, shape, and size:
  748. </p>
  749. <pre class="prettyprint lang-js">
  750. var options = {
  751. // ...
  752. nodes: {
  753. color: {
  754. background: 'white',
  755. border: 'red',
  756. highlight: {
  757. background: 'pink',
  758. border: 'red'
  759. }
  760. },
  761. shape: 'star',
  762. radius: 24
  763. }
  764. };
  765. </pre>
  766. <p>
  767. The following options are available for nodes. These options must be created
  768. inside an object <code>nodes</code> in the graphs options object.</p>
  769. <table>
  770. <tr>
  771. <td>color</td>
  772. <td>String | Object</td>
  773. <td>Object</td>
  774. <td>Default color of the nodes. When color is a string, the color is applied
  775. to both background as well as the border of the node.</td>
  776. </tr>
  777. <tr>
  778. <td>color.background</td>
  779. <td>String</td>
  780. <td>"#97C2FC"</td>
  781. <td>Default background color of the nodes</td>
  782. </tr>
  783. <tr>
  784. <td>color.border</td>
  785. <td>String</td>
  786. <td>"#2B7CE9"</td>
  787. <td>Default border color of the nodes</td>
  788. </tr>
  789. <tr>
  790. <td>color.highlight</td>
  791. <td>String | Object</td>
  792. <td>Object</td>
  793. <td>Default color of the node when the node is selected. In case of a string, the color is applied to
  794. both border and background of the node.</td>
  795. </tr>
  796. <tr>
  797. <td>color.highlight.background</td>
  798. <td>String</td>
  799. <td>"#D2E5FF"</td>
  800. <td>Default background color of the node when selected.</td>
  801. </tr>
  802. <tr>
  803. <td>color.highlight.border</td>
  804. <td>String</td>
  805. <td>"#2B7CE9"</td>
  806. <td>Default border color of the node when selected.</td>
  807. </tr>
  808. <tr>
  809. <td>allowedToMoveX</td>
  810. <td>Boolean</td>
  811. <td>false</td>
  812. <td>If allowedToMoveX is false, then the node will not move from its supplied position.
  813. If an X position has been supplied, it is fixed in the X-direction.
  814. If no X value has been supplied, this argument will not do anything.</td>
  815. </tr>
  816. <tr>
  817. <td>allowedToMoveY</td>
  818. <td>Boolean</td>
  819. <td>false</td>
  820. <td>If allowedToMoveY is false, then the node will not move from its supplied position.
  821. If an Y position has been supplied, it is fixed in the Y-direction.
  822. If no Y value has been supplied, this argument will not do anything.</td>
  823. </tr>
  824. <tr>
  825. <td>fontColor</td>
  826. <td>String</td>
  827. <td>"black"</td>
  828. <td>Default font color for the text label in the nodes.</td>
  829. </tr>
  830. <tr>
  831. <td>fontFace</td>
  832. <td>String</td>
  833. <td>"sans"</td>
  834. <td>Default font face for the text label in the nodes, for example "verdana" or "arial".</td>
  835. </tr>
  836. <tr>
  837. <td>fontSize</td>
  838. <td>Number</td>
  839. <td>14</td>
  840. <td>Default font size in pixels for the text label in the nodes.</td>
  841. </tr>
  842. <tr>
  843. <td>group</td>
  844. <td>String</td>
  845. <td>none</td>
  846. <td>Default group for the nodes.</td>
  847. </tr>
  848. <tr>
  849. <td>image</td>
  850. <td>String</td>
  851. <td>none</td>
  852. <td>Default image url for the nodes. only applicable to shape <code>image</code>.</td>
  853. </tr>
  854. <tr>
  855. <td>mass</td>
  856. <td>number</td>
  857. <td>1</td>
  858. <td>When using the Barnes Hut simulation method (which is selected by default),
  859. the mass of a node determines the gravitational repulsion during the simulation. Higher mass will push other nodes further away.</td>
  860. </tr>
  861. <tr>
  862. <td>level</td>
  863. <td>number</td>
  864. <td>-1</td>
  865. <td>This level is used in the hierarchical layout. If this is not selected, the level does not do anything.</td>
  866. </tr>
  867. <tr>
  868. <td>widthMin</td>
  869. <td>Number</td>
  870. <td>16</td>
  871. <td>The minimum width for a scaled image. Only applicable to shape <code>image</code>.</td>
  872. </tr>
  873. <tr>
  874. <td>widthMax</td>
  875. <td>Number</td>
  876. <td>64</td>
  877. <td>The maximum width for a scaled image. Only applicable to shape <code>image</code>.</td>
  878. </tr>
  879. <tr>
  880. <td>shape</td>
  881. <td>String</td>
  882. <td>"ellipse"</td>
  883. <td>The default shape for all nodes.
  884. Choose from
  885. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  886. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  887. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  888. This shape can be overridden by a group shape, or by a shape of an individual node.</td>
  889. </tr>
  890. <tr>
  891. <td>radius</td>
  892. <td>Number</td>
  893. <td>5</td>
  894. <td>The default radius for a node. Only applicable to shapes <code>dot</code>,
  895. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  896. </tr>
  897. <tr>
  898. <td>radiusMin</td>
  899. <td>Number</td>
  900. <td>5</td>
  901. <td>The minimum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  902. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  903. </tr>
  904. <tr>
  905. <td>radiusMax</td>
  906. <td>Number</td>
  907. <td>20</td>
  908. <td>The maximum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  909. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  910. </tr>
  911. </table>
  912. <h3 id="Edges_configuration">Edges configuration</h3>
  913. <p>
  914. Edges can be configured with different length and styling. To configure edges, provide an object named <code>edges</code> in the <code>options</code> for the Graph.
  915. </p>
  916. <p>
  917. For example to set the width of all edges to 2 pixels and give them a red color:
  918. </p>
  919. <pre class="prettyprint lang-js">
  920. var options = {
  921. // ...
  922. edges: {
  923. color: 'red',
  924. width: 2
  925. }
  926. };
  927. </pre>
  928. <p>
  929. The following options are available for edges. These options must be created
  930. inside an object <code>edges</code> in the graphs options object.
  931. </p>
  932. <table>
  933. <tr>
  934. <th>Name</th>
  935. <th>Type</th>
  936. <th>Default</th>
  937. <th>Description</th>
  938. </tr>
  939. <tr>
  940. <td>color</td>
  941. <td>String | Object</td>
  942. <td>Object</td>
  943. <td>Colors of the edge. This object contains both colors for the selected and unselected state.</td>
  944. </tr>
  945. <tr>
  946. <td>color.color</td>
  947. <td>String</td>
  948. <td>"#848484"</td>
  949. <td>Color of the edge when not selected.</td>
  950. </tr>
  951. <tr>
  952. <td>color.highlight</td>
  953. <td>String</td>
  954. <td>"#848484"</td>
  955. <td>Color of the edge when selected.</td>
  956. </tr>
  957. <tr>
  958. <td>dash</td>
  959. <td>Object</td>
  960. <td>Object</td>
  961. <td>
  962. Object containing default properties for dashed lines.
  963. Available properties: <code>length</code>, <code>gap</code>,
  964. <code>altLength</code>.
  965. </td>
  966. </tr>
  967. <tr>
  968. <td>dash.altLength</td>
  969. <td>number</td>
  970. <td>none</td>
  971. <td>Default length of the alternated dash in pixels on a dashed line.
  972. Specifying <code>dash.altLength</code> allows for creating
  973. a dashed line with a dash-dot style, for example when
  974. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  975. See also the option <code>dahs.length</code>.
  976. Only applicable when the line style is <code>dash-line</code>.</td>
  977. </tr>
  978. <tr>
  979. <td>dash.length</td>
  980. <td>number</td>
  981. <td>10</td>
  982. <td>Default length of a dash in pixels on a dashed line.
  983. Only applicable when the line style is <code>dash-line</code>.</td>
  984. </tr>
  985. <tr>
  986. <td>dash.gap</td>
  987. <td>number</td>
  988. <td>5</td>
  989. <td>Default length of a gap in pixels on a dashed line.
  990. Only applicable when the line style is <code>dash-line</code>.</td>
  991. </tr>
  992. <tr>
  993. <td>length</td>
  994. <td>number</td>
  995. <td>physics.[method].springLength</td>
  996. <td>The resting length of the edge when modeled as a spring. By default the springLength determined by the physics is used. By using this setting you can make certain edges have different resting lengths.</td>
  997. </tr>
  998. <tr>
  999. <td>style</td>
  1000. <td>String</td>
  1001. <td>"line"</td>
  1002. <td>The default style of a edge.
  1003. Choose from <code>line</code> (default), <code>arrow</code>,
  1004. <code>arrow-center</code>, <code>dash-line</code>.</td>
  1005. </tr>
  1006. <tr>
  1007. <td>width</td>
  1008. <td>Number</td>
  1009. <td>1</td>
  1010. <td>The default width of a edge.</td>
  1011. </tr>
  1012. </table>
  1013. <h3 id="Groups_configuration">Groups configuration</h3>
  1014. <p>It is possible to specify custom styles for groups of nodes.
  1015. Each node having assigned to this group gets the specified style.
  1016. The options <code>groups</code> is an object containing one or multiple groups,
  1017. identified by a unique string, the groupname.
  1018. </p>
  1019. <p>
  1020. A group can have the following styles:
  1021. </p>
  1022. <pre class="prettyprint lang-js">
  1023. var options = {
  1024. // ...
  1025. groups: {
  1026. mygroup: {
  1027. shape: 'circle',
  1028. color: {
  1029. border: 'black',
  1030. background: 'white',
  1031. highlight: {
  1032. border: 'yellow',
  1033. background: 'orange'
  1034. }
  1035. }
  1036. fontColor: 'red',
  1037. fontSize: 18
  1038. }
  1039. // add more groups here
  1040. }
  1041. };
  1042. var nodes = [
  1043. {id: 1, label: 'Node 1'}, // will get the default style
  1044. {id: 2, label: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  1045. // ... more nodes
  1046. ];
  1047. </pre>
  1048. <p>The following styles are available for groups:</p>
  1049. <table>
  1050. <tr>
  1051. <th>Name</th>
  1052. <th>Type</th>
  1053. <th>Default</th>
  1054. <th>Description</th>
  1055. </tr>
  1056. <tr>
  1057. <td>color</td>
  1058. <td>String | Object</td>
  1059. <td>Object</td>
  1060. <td>Color of the node</td>
  1061. </tr>
  1062. <tr>
  1063. <td>color.border</td>
  1064. <td>String</td>
  1065. <td>"#2B7CE9"</td>
  1066. <td>Border color of the node</td>
  1067. </tr>
  1068. <tr>
  1069. <td>color.background</td>
  1070. <td>String</td>
  1071. <td>"#97C2FC"</td>
  1072. <td>Background color of the node</td>
  1073. </tr>
  1074. <tr>
  1075. <td>color.highlight</td>
  1076. <td>String | Object</td>
  1077. <td>"#D2E5FF"</td>
  1078. <td>Default color of the node when the node is selected. In case of a string, the color is applied to
  1079. both border and background of the node.</td>
  1080. </tr>
  1081. <tr>
  1082. <td>color.highlight.background</td>
  1083. <td>String</td>
  1084. <td>"#D2E5FF"</td>
  1085. <td>Background color of the node when selected.</td>
  1086. </tr>
  1087. <tr>
  1088. <td>color.highlight.border</td>
  1089. <td>String</td>
  1090. <td>"#D2E5FF"</td>
  1091. <td>Border color of the node when selected.</td>
  1092. </tr>
  1093. <tr>
  1094. <td>image</td>
  1095. <td>String</td>
  1096. <td>none</td>
  1097. <td>Default image for the nodes. Only applicable in combination with
  1098. shape <code>image</code>.</td>
  1099. </tr>
  1100. <tr>
  1101. <td>fontColor</td>
  1102. <td>String</td>
  1103. <td>"black"</td>
  1104. <td>Font color of the node.</td>
  1105. </tr>
  1106. <tr>
  1107. <td>fontFace</td>
  1108. <td>String</td>
  1109. <td>"sans"</td>
  1110. <td>Font name of the node, for example "verdana" or "arial".</td>
  1111. </tr>
  1112. <tr>
  1113. <td>fontSize</td>
  1114. <td>Number</td>
  1115. <td>14</td>
  1116. <td>Font size for the node in pixels.</td>
  1117. </tr>
  1118. <tr>
  1119. <td>shape</td>
  1120. <td>String</td>
  1121. <td>"ellipse"</td>
  1122. <td>Choose from
  1123. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  1124. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  1125. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  1126. In case of image, a property with name image must be provided, containing
  1127. image urls.</td>
  1128. </tr>
  1129. <tr>
  1130. <td>radius</td>
  1131. <td>Number</td>
  1132. <td>5</td>
  1133. <td>Default radius for the node. Only applicable in combination with
  1134. shapes <code>box</code> and <code>dot</code>.</td>
  1135. </tr>
  1136. </table>
  1137. <h3 id="Physics">Physics</h3>
  1138. <p>
  1139. The original simulation method was based on particel physics with a repulsion field (potential) around each node,
  1140. and the edges were modelled as springs. The new system employed the <a href="http://en.wikipedia.org/wiki/Barnes%E2%80%93Hut_simulation">Barnes-Hut</a> gravitational simulation model. The edges are still modelled as springs.
  1141. To unify the physics system, the damping, repulsion distance and edge length have been combined in an physics option. To retain good behaviour, both the old repulsion model and the Barnes-Hut model have their own parameters.
  1142. If no options for the physics system are supplied, the Barnes-Hut method will be used with the default parameters. If you want to customize the physics system easily, you can use the configurePhysics option.
  1143. <p class="important_note">Note: if the behaviour of your graph is not the way you want it, use configurePhysics as described <u><a href="#PhysicsConfiguration">below</a></u> or by <u><a href="../examples/graph/25_physics_configuration.html">example 25</a></u>.</p>
  1144. </p>
  1145. <pre class="prettyprint">
  1146. // These variables must be defined in an options object named physics.
  1147. // If a variable is not supplied, the default value is used.
  1148. var options = {
  1149. physics: {
  1150. barnesHut: {
  1151. enabled: true,
  1152. gravitationalConstant: -2000,
  1153. centralGravity: 0.1,
  1154. springLength: 95,
  1155. springConstant: 0.04,
  1156. damping: 0.09
  1157. },
  1158. repulsion: {
  1159. centralGravity: 0.1,
  1160. springLength: 50,
  1161. springConstant: 0.05,
  1162. nodeDistance: 100,
  1163. damping: 0.09
  1164. },
  1165. }
  1166. </pre>
  1167. <h5>barnesHut:</h5>
  1168. <table>
  1169. <tr>
  1170. <th>Name</th>
  1171. <th>Type</th>
  1172. <th>Default</th>
  1173. <th>Description</th>
  1174. </tr>
  1175. <tr>
  1176. <td>enabled</td>
  1177. <td>Boolean</td>
  1178. <td>true</td>
  1179. <td>This switches the Barnes-Hut simulation on or off. If it is turned off, the old repulsion model is used. Barnes-Hut is generally faster and yields better results.</td>
  1180. </tr>
  1181. <tr>
  1182. <td>gravitationalConstant</td>
  1183. <td>Number</td>
  1184. <td>-2000</td>
  1185. <td>This is the gravitational constand used to calculate the gravity forces. More information is available <a href="http://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation" target="_blank">here</a>.</td>
  1186. </tr>
  1187. <tr>
  1188. <td>centralGravity</td>
  1189. <td>Number</td>
  1190. <td>0.1</td>
  1191. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1192. </tr>
  1193. <tr>
  1194. <td>springLength</td>
  1195. <td>Number</td>
  1196. <td>95</td>
  1197. <td>In the previous versions this was a property of the edges, called length. This is the length of the springs when they are at rest. During the simulation they will be streched by the gravitational fields.
  1198. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1199. </tr>
  1200. <tr>
  1201. <td>springConstant</td>
  1202. <td>Number</td>
  1203. <td>0.04</td>
  1204. <td>This is the spring constant used to calculate the spring forces based on Hooke&prime;s Law. More information is available <a href="http://en.wikipedia.org/wiki/Hooke's_law" target="_blank">here</a>.</td>
  1205. </tr>
  1206. <tr>
  1207. <td>damping</td>
  1208. <td>Number</td>
  1209. <td>0.09</td>
  1210. <td>This is the damping constant. It is used to dissipate energy from the system to have it settle in an equilibrium. More information is available <a href="http://en.wikipedia.org/wiki/Damping" target="_blank">here</a>.</td>
  1211. </tr>
  1212. </table>
  1213. <h5>repulsion:</h5>
  1214. <table>
  1215. <tr>
  1216. <th>Name</th>
  1217. <th>Type</th>
  1218. <th>Default</th>
  1219. <th>Description</th>
  1220. </tr>
  1221. <tr>
  1222. <td>centralGravity</td>
  1223. <td>Number</td>
  1224. <td>0.1</td>
  1225. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1226. </tr>
  1227. <tr>
  1228. <td>springLength</td>
  1229. <td>Number</td>
  1230. <td>50</td>
  1231. <td>In the previous versions this was a property of the edges, called length. This is the length of the springs when they are at rest. During the simulation they will be streched by the gravitational fields.
  1232. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1233. </tr>
  1234. <tr>
  1235. <td>nodeDistance</td>
  1236. <td>Number</td>
  1237. <td>100</td>
  1238. <td>This parameter is used to define the distance of influence of the repulsion field of the nodes. Below half this distance, the repulsion is maximal and beyond twice this distance the repulsion is zero.</td>
  1239. </tr>
  1240. <tr>
  1241. <td>springConstant</td>
  1242. <td>Number</td>
  1243. <td>0.05</td>
  1244. <td>This is the spring constant used to calculate the spring forces based on Hooke&prime;s Law. More information is available <a href="http://en.wikipedia.org/wiki/Hooke's_law" target="_blank">here</a>.</td>
  1245. </tr>
  1246. <tr>
  1247. <td>damping</td>
  1248. <td>Number</td>
  1249. <td>0.09</td>
  1250. <td>This is the damping constant. It is used to dissipate energy from the system to have it settle in an equilibrium. More information is available <a href="http://en.wikipedia.org/wiki/Damping" target="_blank">here</a>.</td>
  1251. </tr>
  1252. </table>
  1253. <h4 id="PhysicsConfiguration">Configuration:</h4>
  1254. Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, graph has a special option
  1255. that the user can use to explore which settings may be good for him or her. This is ment to be used during the development phase when you are implementing vis.js. Once you have found
  1256. settings you are happy with, you can supply them to graph using the physics options as described above.
  1257. On start, the default settings will be loaded. Keep in mind that selecting the hierarchical simulation mode <b>disables</b> smooth curves. These will not be enabled again afterwards.
  1258. <pre class="prettyprint">
  1259. var options = {
  1260. configurePhysics:true
  1261. }
  1262. </pre>
  1263. <h3 id="Data_manipulation">Data manipulation</h3>
  1264. <p>
  1265. By using the data manipulation feature of the graph you can dynamically create nodes, connect nodes with edges, edit nodes or delete nodes and edges.
  1266. The toolbar is fully HTML and CSS so the user can style this to their preference. To control the behaviour of the data manipulation, users can insert custom functions
  1267. into the data manipulation process. For example, an injected function can show an detailed pop-up when a user wants to add a node. In <a href="../examples/graph/21_data_manipulation.html">example 21</a>,
  1268. two functions have been injected into the add and edit functionality. This is described in more detail in the next subsection. To correctly display the manipulation icons, the <b>vis.css</b> file must be included.
  1269. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1270. </p>
  1271. <pre class="prettyprint">
  1272. // These variables must be defined in an options object named dataManipulation.
  1273. // If a variable is not supplied, the default value is used.
  1274. var options = {
  1275. dataManipulation: {
  1276. enabled: false,
  1277. initiallyVisible: false
  1278. }
  1279. }
  1280. // OR to just load the module with default values:
  1281. var options: {
  1282. dataManipulation: true
  1283. }
  1284. </pre>
  1285. <table>
  1286. <tr>
  1287. <th>Name</th>
  1288. <th>Type</th>
  1289. <th>Default</th>
  1290. <th>Description</th>
  1291. </tr>
  1292. <tr>
  1293. <td>enabled</td>
  1294. <td>Boolean</td>
  1295. <td>false</td>
  1296. <td>Enabling or disabling of the data manipulation toolbar. If it is initially hidden, an edit button appears in the top left corner.</td>
  1297. </tr>
  1298. <tr>
  1299. <td>initiallyVisible</td>
  1300. <td>Boolean</td>
  1301. <td>false</td>
  1302. <td>Initially hide or show the data manipulation toolbar.</td>
  1303. </tr>
  1304. </table>
  1305. <h4 id="Data_manipulation_custom">Data manipulation: custom functionality</h4>
  1306. <p>
  1307. Users can insert custom functions into the add node, edit node, connect nodes, and delete selected operations. This is done by supplying them in the options.
  1308. If the callback is NOT called, nothing happens. <a href="../examples/graph/21_data_manipulation.html">Example 21</a> has two working examples
  1309. for the add and edit functions. The data the user is supplied with in these functions has been described in the code below.
  1310. For the add data, you can add any and all options that are accepted for node creation as described above. The same goes for edit, however only the fields described
  1311. in the code below contain information on the selected node. The callback for connect accepts any options that are used for edge creation. Only the callback for delete selected
  1312. requires the same data structure that is supplied to the user. <br /><br />
  1313. <b>If there is no injected function supplied for the edit operation, the button will not be shown in the toolbar.</b>
  1314. </p>
  1315. <pre class="prettyprint">
  1316. // If a variable is not supplied, the default value is used.
  1317. var options: {
  1318. dataManipulation: true,
  1319. onAdd: function(data,callback) {
  1320. /** data = {id: random unique id,
  1321. * label: new,
  1322. * x: x position of click (canvas space),
  1323. * y: y position of click (canvas space),
  1324. * allowedToMoveX: true,
  1325. * allowedToMoveY: true
  1326. * };
  1327. */
  1328. var newData = {..}; // alter the data as you want.
  1329. // all fields normally accepted by a node can be used.
  1330. callback(newData); // call the callback to add a node.
  1331. },
  1332. onEdit: function(data,callback) {
  1333. /** data = {id:...,
  1334. * label: ...,
  1335. * group: ...,
  1336. * shape: ...,
  1337. * color: {
  1338. * background:...,
  1339. * border:...,
  1340. * highlight: {
  1341. * background:...,
  1342. * border:...
  1343. * }
  1344. * }
  1345. * };
  1346. */
  1347. var newData = {..}; // alter the data as you want.
  1348. // all fields normally accepted by a node can be used.
  1349. callback(newData); // call the callback with the new data to edit the node.
  1350. }
  1351. onConnect: function(data,callback) {
  1352. // data = {from: nodeId1, to: nodeId2};
  1353. var newData = {..}; // check or alter data as you see fit.
  1354. callback(newData); // call the callback to connect the nodes.
  1355. },
  1356. onDelete: function(data,callback) {
  1357. // data = {nodes: [selectedNodeIds], edges: [selectedEdgeIds]};
  1358. var newData = {..}; // alter the data as you want.
  1359. // the same data structure is required.
  1360. callback(newData); // call the callback to delete the objects.
  1361. }
  1362. };
  1363. </pre>
  1364. <p>
  1365. Because the interface elements are CSS and HTML, the user will have to correct for size changes of the canvas. To facilitate this, a new event has been added called resize.
  1366. A function can be bound to this event. This function is supplied with the new widht and height of the canvas. The CSS can then be updated accordingly.
  1367. An code snippet from example 21 is shown below.
  1368. </p>
  1369. <pre class="prettyprint">
  1370. graph.on("resize", function(params) {console.log(params.width,params.height)});
  1371. </pre>
  1372. <h3 id="Clustering">Clustering</h3>
  1373. <p>
  1374. The graph now supports dynamic clustering of nodes. This allows a user to view a very large dataset (> 50.000 nodes) without
  1375. sacrificing performance. When loading a large dataset, the nodes are clustered initially (this may take a small while) to have a
  1376. responsive visualization to work with. The clustering is both outside-in and inside-out. Outside-in means that nodes with only one
  1377. connection will be contained, or clustered, in the node it is connected to. Inside-out clustering first determines which nodes are hubs.
  1378. Hubs are defined as the nodes with the top 3% highest amount of connections (assuming normal distribution). These hubs then "grow", meaning
  1379. they contain the nodes they are connected to within themselves. The edges that were connected to the nodes that are absorbed will be reconnected to the cluster.
  1380. <br />
  1381. <br />
  1382. A cluster is just a node that has references to the nodes and edges it contains. It has an internal counter to keep track of its size, which is then used
  1383. to calculate the required forces. The contained nodes are removed from the global nodes index, greatly speeding up the system.
  1384. <br />
  1385. <br />
  1386. The clustering has the following user-configurable settings. The default values have been tested with the Graph examples and work well.
  1387. The default state for clustering is <b>off</b>.
  1388. </p>
  1389. <pre class="prettyprint">
  1390. // These variables must be defined in an options object named clustering.
  1391. // If a variable is not supplied, the default value is used.
  1392. var options = {
  1393. clustering: {
  1394. initialMaxNodes: 100,
  1395. clusterThreshold:500,
  1396. reduceToNodes:300,
  1397. chainThreshold: 0.4,
  1398. clusterEdgeThreshold: 20,
  1399. sectorThreshold: 100,
  1400. screenSizeThreshold: 0.2,
  1401. fontSizeMultiplier: 4.0,
  1402. maxFontSize: 1000,
  1403. forceAmplification: 0.1,
  1404. distanceAmplification: 0.1,
  1405. edgeGrowth: 20,
  1406. nodeScaling: {width: 1,
  1407. height: 1,
  1408. radius: 1},
  1409. maxNodeSizeIncrements: 600,
  1410. activeAreaBoxSize: 100,
  1411. clusterLevelDifference: 2
  1412. }
  1413. }
  1414. // OR to just load the module with default values:
  1415. var options: {
  1416. clustering: true
  1417. }
  1418. </pre>
  1419. <table>
  1420. <tr>
  1421. <th>Name</th>
  1422. <th>Type</th>
  1423. <th>Default</th>
  1424. <th>Description</th>
  1425. </tr>
  1426. <tr>
  1427. <td>initialMaxNodes</td>
  1428. <td>Number</td>
  1429. <td>100</td>
  1430. <td>If the initial amount of nodes is larger than this value, clustering starts until the total number of nodes is less than this value.</td>
  1431. </tr>
  1432. <tr>
  1433. <td>clusterThreshold</td>
  1434. <td>Number</td>
  1435. <td>500</td>
  1436. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1437. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continuously fluid.</td>
  1438. </tr>
  1439. <tr>
  1440. <td>reduceToNodes</td>
  1441. <td>Number</td>
  1442. <td>300</td>
  1443. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1444. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  1445. </tr>
  1446. <tr>
  1447. <td>chainThreshold</td>
  1448. <td>Number</td>
  1449. <td>0.4</td>
  1450. <td>Because of the clustering methods used, long chains of nodes can be formed. To reduce these chains, this threshold is used.
  1451. A <code>chainThreshold</code> of 0.4 means that no more than 40% of all nodes are allowed to be a chain node (two connections).
  1452. If there are more, they are clustered together.</td>
  1453. </tr>
  1454. <tr>
  1455. <td>clusterEdgeThreshold</td>
  1456. <td>Number</td>
  1457. <td>20</td>
  1458. <td>This is the absolute edge length threshold in pixels. If the edge is smaller on screen (that means zooming out reduces this length)
  1459. the node will be clustered. This is triggered when zooming out.</td>
  1460. </tr>
  1461. <tr>
  1462. <td>sectorThreshold</td>
  1463. <td>Integer</td>
  1464. <td>50</td>
  1465. <td>If a cluster larger than <code>sectorThreshold</code> is opened, a seperate instance called a sector, will be created. All the simulation of
  1466. nodes outside of this instance will be paused. This is to maintain performance and clarity when examining large clusters.
  1467. A sector is collapsed when zooming out far enough. Also, when opening a cluster, if this cluster is smaller than this value, it is fully unpacked.</td>
  1468. </tr>
  1469. <tr>
  1470. <td>screenSizeThreshold</td>
  1471. <td>Number</td>
  1472. <td>0.2</td>
  1473. <td>When zooming in, the clusters become bigger. A <code>screenSizeThreshold</code> of 0.2 means that if the width or height of this cluster
  1474. becomes bigger than 20% of the width or height of the canvas, the cluster is opened. If a sector has been created, if the sector is smaller than
  1475. 20%, we collapse this sector.</td>
  1476. </tr>
  1477. <tr>
  1478. <td>fontSizeMultiplier</td>
  1479. <td>Number</td>
  1480. <td>4.0</td>
  1481. <td>This parameter denotes the increase in fontSize of the cluster when a single node is added to it.</td>
  1482. </tr>
  1483. <tr>
  1484. <td>maxFontSize</td>
  1485. <td>Number</td>
  1486. <td>1000</td>
  1487. <td>This parameter denotes the largest allowed font size. If the font becomes too large, some browsers experience problems displaying this.</td>
  1488. </tr>
  1489. <tr>
  1490. <td>forceAmplification</td>
  1491. <td>Number</td>
  1492. <td>0.6</td>
  1493. <td>This factor is used to calculate the increase of the repulsive force of a cluster. It is calculated by the following
  1494. formula: <code>repulsingForce *= 1 + (clusterSize * forceAmplification)</code>.</td>
  1495. </tr>
  1496. <tr>
  1497. <td>distanceAmplification</td>
  1498. <td>Number</td>
  1499. <td>0.2</td>
  1500. <td>This factor is used to calculate the increase in effective range of the repulsive force of the cluster.
  1501. A larger cluster has a longer range. It is calculated by the following
  1502. formula: <code>minDistance *= 1 + (clusterSize * distanceAmplification)</code>.</td>
  1503. </tr>
  1504. <tr>
  1505. <td>edgeGrowth</td>
  1506. <td>Number</td>
  1507. <td>20</td>
  1508. <td>This factor determines the elongation of edges connected to a cluster.</td>
  1509. </tr>
  1510. <tr>
  1511. <td>nodeScaling.width</td>
  1512. <td>Number</td>
  1513. <td>10</td>
  1514. <td>This factor determines how much the width of a cluster increases in pixels per added node.</td>
  1515. </tr>
  1516. <tr>
  1517. <td>nodeScaling.height</td>
  1518. <td>Number</td>
  1519. <td>10</td>
  1520. <td>This factor determines how much the height of a cluster increases in pixels per added node.</td>
  1521. </tr>
  1522. <tr>
  1523. <td>nodeScaling.radius</td>
  1524. <td>Number</td>
  1525. <td>10</td>
  1526. <td>This factor determines how much the radius of a cluster increases in pixels per added node.</td>
  1527. </tr>
  1528. <tr>
  1529. <td>maxNodeSizeIncrements</td>
  1530. <td>Number</td>
  1531. <td>600</td>
  1532. <td>This limits the size clusters can grow to. The default value, 600, implies that if a cluster contains more than 600 nodes, it will no longer grow.</td>
  1533. </tr>
  1534. <tr>
  1535. <td>activeAreaBoxSize</td>
  1536. <td>Number</td>
  1537. <td>100</td>
  1538. <td>Imagine a square with an edge length of <code>activeAreaBoxSize</code> pixels around your cursor.
  1539. If a cluster is in this box as you zoom in, the cluster can be opened in a seperate sector.
  1540. This is regardless of the zoom level.</td>
  1541. </tr>
  1542. <tr>
  1543. <td>clusterLevelDifference</td>
  1544. <td>Number</td>
  1545. <td>2</td>
  1546. <td>At every clustering session, Graph will check if the difference between cluster levels is
  1547. acceptable. When a cluster is formed when zooming out, that is one cluster level.
  1548. If you zoom out further and it encompasses more nodes, that is another level. For example:
  1549. If the highest level of your graph at any given time is 3, nodes that have not clustered or
  1550. have clustered only once will join their neighbour with the lowest cluster level.</td>
  1551. </tr>
  1552. </table>
  1553. <h3 id="Navigation_controls">Navigation controls</h3>
  1554. <p>
  1555. Graph has a menu with navigation controls, which is disabled by default.
  1556. It can be configured with the following settings. To correctly display the navigation icons, the <b>vis.css</b> file must be included.
  1557. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1558. </p>
  1559. <pre class="prettyprint">
  1560. // use of navigation controls
  1561. var options: {
  1562. navigation: true
  1563. }
  1564. </pre>
  1565. <h3 id="Keyboard_navigation">Keyboard navigation</h3>
  1566. <p>
  1567. The graph can be navigated using shortcut keys.
  1568. The default state for the keyboard navigation is <b>off</b>. The predefined keys can be found in the example <a href="../examples/graph/20_navigation.html">20_navigation.html</a>.
  1569. </p>
  1570. <pre class="prettyprint">
  1571. // simple use of keyboard controls
  1572. var options: {
  1573. keyboard: true
  1574. }
  1575. // advanced configuration for keyboard controls
  1576. var options: {
  1577. keyboard: {
  1578. speed: {
  1579. x: 10,
  1580. y: 10,
  1581. zoom: 0.02
  1582. }
  1583. }
  1584. }
  1585. </pre>
  1586. <table>
  1587. <tr>
  1588. <th>Name</th>
  1589. <th>Type</th>
  1590. <th>Default</th>
  1591. <th>Description</th>
  1592. </tr>
  1593. <tr>
  1594. <td>speed.x</td>
  1595. <td>Number</td>
  1596. <td>10</td>
  1597. <td>This defines the speed of the camera movement in the x direction when using the keyboard navigation.
  1598. </td>
  1599. </tr>
  1600. <tr>
  1601. <td>speed.y</td>
  1602. <td>Number</td>
  1603. <td>10</td>
  1604. <td>This defines the speed of the camera movement in the y direction when using the keyboard navigation.</td>
  1605. </tr>
  1606. <tr>
  1607. <td>speed.zoom</td>
  1608. <td>Number</td>
  1609. <td>0.02</td>
  1610. <td>This defines the zoomspeed when using the keyboard navigation.</td>
  1611. </tr>
  1612. </table>
  1613. <h3 id="Hierarchical_layout">Hierarchical layout</h3>
  1614. <p>
  1615. The graph can be used to display nodes in a hierarchical way. This can be determined automatically, based on the amount of edges connected to each node, or defined by the user.
  1616. If the user wants to manually determine the hierarchy, each node has to be supplied with a level (from 0 being heighest to n). The automatic method
  1617. is shown in <a href="../examples/graph/23_hierarchical_layout.html">example 23</a> and the user-defined method is shown in <a href="../examples/graph/24_hierarchical_layout_userdefined.html">example 24</a>.
  1618. This layout method does not support smooth curves or clustering. It automatically turns these features off.
  1619. </p>
  1620. <pre class="prettyprint">
  1621. // simple use of the hierarchical layout
  1622. var options: {
  1623. hierarchicalLayout: true
  1624. }
  1625. // advanced configuration for hierarchical layout
  1626. var options: {
  1627. hierarchicalLayout: {
  1628. enabled:false,
  1629. levelSeparation: 150,
  1630. nodeSpacing: 100,
  1631. direction: "UD"
  1632. }
  1633. }
  1634. // partial configuration automatically sets enabled to true
  1635. var options: {
  1636. hierarchicalLayout: {
  1637. nodeSpacing: 100,
  1638. direction: "UD"
  1639. }
  1640. }
  1641. </pre>
  1642. <table>
  1643. <tr>
  1644. <th>Name</th>
  1645. <th>Type</th>
  1646. <th>Default</th>
  1647. <th>Description</th>
  1648. </tr>
  1649. <tr>
  1650. <td>enabled</td>
  1651. <td>Boolean</td>
  1652. <td>false</td>
  1653. <td>Enable or disable the hierarchical layout.
  1654. </td>
  1655. </tr>
  1656. <tr>
  1657. <td>levelSeparation</td>
  1658. <td>Number</td>
  1659. <td>150</td>
  1660. <td>This defines the space between levels (in the Y-direction, considering UP-DOWN direction).</td>
  1661. </tr>
  1662. <tr>
  1663. <td>nodeSpacing</td>
  1664. <td>Number</td>
  1665. <td>100</td>
  1666. <td>This defines the space between nodes in the same level (in the X-direction, considering UP-DOWN direction).
  1667. This is only relevant during the initial placing of nodes.</td>
  1668. </tr>
  1669. <tr>
  1670. <td>direction</td>
  1671. <td>String</td>
  1672. <td>UD</td>
  1673. <td>This defines the direction the graph is drawn in. The supported directions are: Up-Down (UD), Down-Up (DU), Left-Right (LR) and Right-Left (RL).
  1674. These need to be supplied by the acronyms in parentheses.</td>
  1675. </tr>
  1676. </table>
  1677. <h3 id="Localization">Localization</h3>
  1678. <p>
  1679. When using vis.js in other languages, one can use the localization option to overwrite the labels used in the data manipulation interface.
  1680. </p>
  1681. <pre class="prettyprint">
  1682. var options: {
  1683. labels:{
  1684. add:"Add Node",
  1685. edit:"Edit",
  1686. link:"Add Link",
  1687. delete:"Delete selected",
  1688. editNode:"Edit Node",
  1689. back:"Back",
  1690. addDescription:"Click in an empty space to place a new node.",
  1691. linkDescription:"Click on a node and drag the edge to another
  1692. node to connect them.",
  1693. addError:"The function for add does not support two arguments
  1694. (data,callback).",
  1695. linkError:"The function for connect does not support two arguments
  1696. (data,callback).",
  1697. editError:"The function for edit does not support two arguments
  1698. (data, callback).",
  1699. editBoundError:"No edit function has been bound to this button.",
  1700. deleteError:"The function for delete does not support two arguments
  1701. (data, callback).",
  1702. deleteClusterError:"Clusters cannot be deleted."
  1703. }
  1704. }
  1705. </pre>
  1706. <table>
  1707. <tr>
  1708. <th>Name</th>
  1709. <th>Type</th>
  1710. <th>Default</th>
  1711. <th>Description</th>
  1712. </tr>
  1713. <tr>
  1714. <td>labels</td>
  1715. <td>object</td>
  1716. <td>(shown above)</td>
  1717. <td>Overwrite one or all labels used in the datamanipulation interface with localized strings.
  1718. </td>
  1719. </tr>
  1720. </table>
  1721. <h3 id="Tooltips">Tooltips</h3>
  1722. <p>
  1723. The behaviour and style of the tooltips used to display node and edge title attributes can be customized.
  1724. </p>
  1725. <pre class="prettyprint">
  1726. // tooltip behaviour and style options
  1727. var options: {
  1728. tooltip: {
  1729. delay: 300,
  1730. fontColor: "black",
  1731. fontSize: 14, // px
  1732. fontFace: "verdana",
  1733. color: {
  1734. border: "#666",
  1735. background: "#FFFFC6"
  1736. }
  1737. }
  1738. }
  1739. </pre>
  1740. <table>
  1741. <tr>
  1742. <th>Name</th>
  1743. <th>Type</th>
  1744. <th>Default</th>
  1745. <th>Description</th>
  1746. </tr>
  1747. <tr>
  1748. <td>delay</td>
  1749. <td>Number</td>
  1750. <td>300</td>
  1751. <td>Time in milliseconds a user must hover over a node or edge before a tooltip appears.</td>
  1752. </tr>
  1753. <tr>
  1754. <td>fontColor</td>
  1755. <td>String</td>
  1756. <td>"black"</td>
  1757. <td>Default color for tooltip text.</td>
  1758. </tr>
  1759. <tr>
  1760. <td>fontSize</td>
  1761. <td>Number</td>
  1762. <td>14</td>
  1763. <td>Size in pixels of tooltip text.</td>
  1764. </tr>
  1765. <tr>
  1766. <td>fontFace</td>
  1767. <td>String</td>
  1768. <td>"verdana"</td>
  1769. <td>Font family to used for tooltip text.</td>
  1770. </tr>
  1771. <tr>
  1772. <td>color.background</td>
  1773. <td>String</td>
  1774. <td>"#FFFFC6"</td>
  1775. <td>Background color for the node.</td>
  1776. </tr>
  1777. <tr>
  1778. <td>color.border</td>
  1779. <td>String</td>
  1780. <td>"#666"</td>
  1781. <td>Border color for the node.</td>
  1782. </tr>
  1783. </table>
  1784. <h2 id="Methods">Methods</h2>
  1785. <p>
  1786. Graph supports the following methods.
  1787. </p>
  1788. <table>
  1789. <tr>
  1790. <th>Method</th>
  1791. <th>Return Type</th>
  1792. <th>Description</th>
  1793. </tr>
  1794. <tr>
  1795. <td>getSelection()</td>
  1796. <td>Array of ids</td>
  1797. <td>Returns an array with the ids of the selected nodes.
  1798. Returns an empty array if no nodes are selected.
  1799. The selections are not ordered.
  1800. </td>
  1801. </tr>
  1802. <tr>
  1803. <td>storePosition()</td>
  1804. <td>none</td>
  1805. <td>This will put the X and Y positions of all nodes in the dataset. It will also include allowedToMoveX and allowedToMoveY with the correct values.
  1806. 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.
  1807. </td>
  1808. </tr>
  1809. <tr>
  1810. <td>on(event, callback)</td>
  1811. <td>none</td>
  1812. <td>Create an event listener. The callback function is invoked every time the event is triggered. Avialable events: <code>select</code>. The callback function is invoked as <code>callback(properties)</code>, where <code>properties</code> is an object containing event specific properties. See section <a href="#Events">Events</a> for more information.</td>
  1813. </tr>
  1814. <tr>
  1815. <td>off(event, callback)</td>
  1816. <td>none</td>
  1817. <td>Remove an event listener created before via function <code>on(event, callback)</code>. See section <a href="#Events">Events</a> for more information.</td>
  1818. </tr>
  1819. <tr>
  1820. <td>redraw()</td>
  1821. <td>none</td>
  1822. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  1823. </tr>
  1824. <tr>
  1825. <td>setData(data,[disableStart])</td>
  1826. <td>none</td>
  1827. <td>Loads data. Parameter <code>data</code> is an object containing
  1828. nodes, edges, and options. Parameters nodes, edges are an Array.
  1829. Options is a name-value map and is optional. Parameter <code>disableStart</code> is
  1830. an optional Boolean and can disable the start of the simulation that would begin at the end
  1831. of this function by default.
  1832. </td>
  1833. </tr>
  1834. <tr>
  1835. <td>setOptions(options)</td>
  1836. <td>none</td>
  1837. <td>Set options for the graph. The available options are described in
  1838. the section <a href="#Configuration_options">Configuration Options</a>.
  1839. </td>
  1840. </tr>
  1841. <tr>
  1842. <td>setSelection(selection)</td>
  1843. <td>none</td>
  1844. <td>Select nodes.
  1845. <code>selection</code> is an array with ids of nodes to be selected.
  1846. The array <code>selection</code> can contain zero or multiple ids.
  1847. Example usage: <code>graph.setSelection([3, 5]);</code> will select
  1848. nodes with id 3 and 5.
  1849. </td>
  1850. </tr>
  1851. <tr>
  1852. <td>setSize(width, height)</td>
  1853. <td>none</td>
  1854. <td>Parameters <code>width</code> and <code>height</code> are strings,
  1855. containing a new size for the visualization. Size can be provided in pixels
  1856. or in percentages.</td>
  1857. </tr>
  1858. <tr>
  1859. <td>zoomExtent()</td>
  1860. <td>none</td>
  1861. <td>Scales the graph so all the nodes are in center view.</td>
  1862. </tr>
  1863. </table>
  1864. <h2 id="Events">Events</h2>
  1865. <p>
  1866. Graph fires events after one or multiple nodes are selected or deselected.
  1867. The event can be catched by creating a listener.
  1868. </p>
  1869. <p>
  1870. Here an example on how to catch a <code>select</code> event.
  1871. </p>
  1872. <pre class="prettyprint lang-js">
  1873. graph.on('select', function (properties) {
  1874. alert('selected nodes: ' + properties.nodes);
  1875. });
  1876. </pre>
  1877. <p>
  1878. A listener can be removed via the function <code>off</code>:
  1879. </p>
  1880. <pre class="prettyprint lang-js">
  1881. function onSelect (properties) {
  1882. alert('selected nodes: ' + properties.nodes);
  1883. }
  1884. // add event listener
  1885. graph.on('select', onSelect);
  1886. // do stuff...
  1887. // remove event listener
  1888. graph.off('select', onSelect);
  1889. </pre>
  1890. <p>
  1891. The following events are available.
  1892. </p>
  1893. <table>
  1894. <tr>
  1895. <th>name</th>
  1896. <th>Description</th>
  1897. <th>Properties</th>
  1898. </tr>
  1899. <tr>
  1900. <td>select</td>
  1901. <td>Fired after the user selects or deselects a node by clicking it.
  1902. Not fired when the method <code>setSelection</code>is executed.
  1903. </td>
  1904. <td>
  1905. <ul>
  1906. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1907. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1908. </ul>
  1909. </td>
  1910. </tr>
  1911. <tr>
  1912. <td>click</td>
  1913. <td>Fired after the user clicks or taps on a touchscreen.</td>
  1914. <td>
  1915. <ul>
  1916. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1917. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1918. </ul>
  1919. </td>
  1920. </tr>
  1921. <tr>
  1922. <td>doubleClick</td>
  1923. <td>Fired after the user double clicks or double taps on a touchscreen.</td>
  1924. <td>
  1925. <ul>
  1926. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1927. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1928. </ul>
  1929. </td>
  1930. </tr>
  1931. <tr>
  1932. <td>resize</td>
  1933. <td>Fired when the size of the canvas has been updated (not neccecarily changed) by the setSize() function or by the setOptions() function.</td>
  1934. <td>
  1935. <ul>
  1936. <li><code>width</code>: the new width of the canvas</li>
  1937. <li><code>height</code>: the new height of the canvas</li>
  1938. </ul>
  1939. </td>
  1940. </tr>
  1941. <tr>
  1942. <td>stabilized</td>
  1943. <td>Fired when the graph has been stabilized after initialization. This event can be used to trigger the .storePosition() function after stabilization.</td>
  1944. <td>
  1945. <ul>
  1946. <li><code>iterations</code>: number of iterations used to stabilize</li>
  1947. </ul>
  1948. </td>
  1949. </tr>
  1950. </table>
  1951. <h2 id="Data_policy">Data policy</h2>
  1952. <p>
  1953. All code and data is processed and rendered in the browser.
  1954. No data is sent to any server.
  1955. </p>
  1956. </div>
  1957. </body>
  1958. </html>