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.

2312 lines
72 KiB

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