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.

2560 lines
84 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | network 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. <style>td.greenField {
  8. background-color: #c9ffc7;
  9. }</style>
  10. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  11. </head>
  12. <body onload="prettyPrint();">
  13. <div id="container">
  14. <h1>Network documentation</h1>
  15. <h2 id="Overview">Overview</h2>
  16. <p>
  17. Network is a visualization to display networks and networks consisting of nodes
  18. and edges. The visualization is easy to use and supports custom shapes,
  19. styles, colors, sizes, images, and more.
  20. </p>
  21. <p>
  22. The network visualization works smooth on any modern browser for up to a
  23. few thousand nodes and edges. To handle a larger amount of nodes, Network
  24. has <a href="#Clustering">clustering</a> support. Network uses
  25. <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Canvas">HTML canvas</a>
  26. for rendering.
  27. </p>
  28. <p>
  29. Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, network has a special option
  30. 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
  31. <u><a href="../examples/network/25_physics_configuration.html">example 25</a></u>.
  32. </p>
  33. <p>
  34. To get started with Network, install or download the
  35. <a href="http://visjs.org" target="_blank">vis.js</a> library.
  36. </p>
  37. <h2><a name="Contents"></a>Contents</h2>
  38. <ul>
  39. <li><a href="#Overview">Overview</a></li>
  40. <li><a href="#Example">Example</a></li>
  41. <li><a href="#Loading">Loading</a></li>
  42. <li>
  43. <a href="#Data_format">Data format</a>
  44. <ul>
  45. <li><a href="#Nodes">Nodes</a></li>
  46. <li><a href="#Edges">Edges</a></li>
  47. <li><a href="#DOT_language">DOT language</a></li>
  48. <li><a href="#Gephi_import">Gephi import</a></li>
  49. </ul>
  50. </li>
  51. <li>
  52. <a href="#Configuration_options">Configuration options</a>
  53. <ul>
  54. <li><a href="#Nodes_configuration">Nodes</a></li>
  55. <li><a href="#Edges_configuration">Edges</a></li>
  56. <li><a href="#Groups_configuration">Groups</a></li>
  57. <li><a href="#Physics">Physics</a></li>
  58. <li><a href="#Data_manipulation">Data manipulation</a></li>
  59. <li><a href="#Clustering">Clustering</a></li>
  60. <li><a href="#Navigation_controls">Navigation controls</a></li>
  61. <li><a href="#Keyboard_navigation">Keyboard navigation</a></li>
  62. <li><a href="#Hierarchical_layout">Hierarchical layout</a></li>
  63. <li><a href="#Localization">Localization</a></li>
  64. <li><a href="#Tooltips">Tooltips</a></li>
  65. </ul>
  66. </li>
  67. <li><a href="#Methods">Methods</a></li>
  68. <li><a href="#Events">Events</a></li>
  69. <li><a href="#Data_policy">Data policy</a></li>
  70. </ul>
  71. <h2 id="Example">Example</h2>
  72. <p>
  73. Here a basic network example. Note that unlike the
  74. <a href="timeline.html">Timeline</a>, the Network does not need the vis.css
  75. file.
  76. </p>
  77. <p>
  78. More examples can be found in the
  79. <a href="../examples" target="_blank">examples directory</a>.
  80. </p>
  81. <pre class="prettyprint lang-html">&lt;!doctype html&gt;
  82. &lt;html&gt;
  83. &lt;head&gt;
  84. &lt;title&gt;Network | Basic usage&lt;/title&gt;
  85. &lt;script type="text/javascript" src="../../dist/vis.js"&gt;&lt;/script&gt;
  86. &lt;/head&gt;
  87. &lt;body&gt;
  88. &lt;div id="mynetwork"&gt;&lt;/div&gt;
  89. &lt;script type="text/javascript"&gt;
  90. // create an array with nodes
  91. var nodes = [
  92. {id: 1, label: 'Node 1'},
  93. {id: 2, label: 'Node 2'},
  94. {id: 3, label: 'Node 3'},
  95. {id: 4, label: 'Node 4'},
  96. {id: 5, label: 'Node 5'}
  97. ];
  98. // create an array with edges
  99. var edges = [
  100. {from: 1, to: 2},
  101. {from: 1, to: 3},
  102. {from: 2, to: 4},
  103. {from: 2, to: 5}
  104. ];
  105. // create a network
  106. var container = document.getElementById('mynetwork');
  107. var data= {
  108. nodes: nodes,
  109. edges: edges,
  110. };
  111. var options = {
  112. width: '400px',
  113. height: '400px'
  114. };
  115. var network = new vis.Network(container, data, options);
  116. &lt;/script&gt;
  117. &lt;/body&gt;
  118. &lt;/html&gt;
  119. </pre>
  120. <h2 id="Loading">Loading</h2>
  121. <p>
  122. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  123. in a subfolder of your project. Include the library script in the head of your html code:
  124. </p>
  125. <pre class="prettyprint lang-html">
  126. &lt;script type="text/javascript" src="vis/dist/vis.js"&gt;&lt;/script&gt;
  127. </pre>
  128. The constructor of the Network is <code>vis.Network</code>.
  129. <pre class="prettyprint lang-js">var network = new vis.Network(container, data, options);</pre>
  130. The constructor accepts three parameters:
  131. <ul>
  132. <li>
  133. <code>container</code> is the DOM element in which to create the network.
  134. </li>
  135. <li>
  136. <code>data</code> is an Object containing properties <code>nodes</code> and
  137. <code>edges</code>, which both contain an array with objects.
  138. Optionally, data may contain an <code>options</code> object.
  139. The parameter <code>data</code> is optional, data can also be set using
  140. the method <code>setData</code>. Section <a href="#Data_Format">Data Format</a>
  141. describes the data object.
  142. </li>
  143. <li>
  144. <code>options</code> is an optional Object containing a name-value map
  145. with options. Options can also be set using the method
  146. <code>setOptions</code>.
  147. Section <a href="#Configuration_Options">Configuration Options</a>
  148. describes the available options.
  149. </li>
  150. </ul>
  151. <h2 id="Data_format">Data format</h2>
  152. <p>
  153. The <code>data</code> parameter of the Network constructor is an object
  154. which can contain different types of data.
  155. The following properties are supported in the <code>data</code> object:
  156. </p>
  157. <ul>
  158. <li>
  159. <span style="font-weight: bold;">A property pair <code>nodes</code> and <code>edges</code></span>,
  160. both containing an Array with objects. The data formats are described
  161. in the sections <a href="#Nodes">Nodes</a> and <a href="#Edges">Edges</a>.
  162. Example:
  163. <pre class="prettyprint lang-js">
  164. var data = {
  165. nodes: [...],
  166. edges: [...]
  167. };
  168. </pre>
  169. </li>
  170. <li>
  171. <span style="font-weight: bold;">A property <code>dot</code></span>,
  172. containing a string with data in the
  173. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  174. DOT support is described in section <a href="#DOT_language">DOT_language</a>.
  175. Example:
  176. <pre class="prettyprint lang-js">
  177. var data = {
  178. dot: '...'
  179. };
  180. </pre>
  181. </li>
  182. <li>
  183. <span style="font-weight: bold;">A property <code>options</code></span>,
  184. containing an object with global options.
  185. Options can be provided as third parameter in the network constructor
  186. as well. Section <a href="#Configuration_Options">Configuration Options</a>
  187. describes the available options.
  188. </li>
  189. </ul>
  190. <h3 id="Nodes">Nodes</h3>
  191. <p>
  192. Nodes typically have an <code>id</code> and <code>label</code>.
  193. A node must contain at least a property <code>id</code>.
  194. Nodes can have extra properties, used to define the shape and style of the
  195. nodes.
  196. </p>
  197. <p>
  198. A JavaScript Array with nodes is constructed like:
  199. </p>
  200. <pre class="prettyprint lang-js">
  201. var nodes = [
  202. {
  203. id: 1,
  204. label: 'Node 1'
  205. },
  206. // ... more nodes
  207. ];
  208. </pre>
  209. Alternatively, a vis DataSet can also be used:
  210. <pre class="prettyprint lang-js">
  211. var nodes = new vis.DataSet();
  212. nodes.add([
  213. {id: '1', label: 'Node 1'},
  214. {id: '2', label: 'Node 2'},
  215. {id: '3', label: 'Node 3'},
  216. {id: '4', label: 'Node 4'},
  217. // ... more nodes
  218. ]);
  219. </pre>
  220. When using a DataSet, the network is automatically updating to changes in the DataSet.
  221. <p>
  222. Nodes support the properties listed below. Each node can be configured individually using
  223. the properties highlighted in green over at the <a href="#Nodes_configuration">Nodes configuration</a>.
  224. </p>
  225. <table>
  226. <tr>
  227. <th>Name</th>
  228. <th>Type</th>
  229. <th>Required</th>
  230. <th>Description</th>
  231. </tr>
  232. <tr>
  233. <td>group</td>
  234. <td>Number | String</td>
  235. <td>no</td>
  236. <td>A group number or name. The type can be <code>number</code>,
  237. <code>string</code>, or an other type. All nodes with the same group get
  238. the same color schema.</td>
  239. </tr>
  240. <tr>
  241. <td>allowedToMoveX</td>
  242. <td>Boolean</td>
  243. <td>no</td>
  244. <td>If allowedToMoveX is false, then the node will not move in the X direction from its position.</td>
  245. </tr>
  246. <tr>
  247. <td>allowedToMoveY</td>
  248. <td>Boolean</td>
  249. <td>no</td>
  250. <td>If allowedToMoveY is false, then the node will not move in the Y direction from its position.</td>
  251. </tr>
  252. <tr>
  253. <td>id</td>
  254. <td>Number | String</td>
  255. <td>yes</td>
  256. <td>A unique id for this node.
  257. Nodes may not have duplicate id's.
  258. Id's do not need to be consecutive.
  259. An id is normally a number, but may be any type.</td>
  260. </tr>
  261. <tr>
  262. <td>level</td>
  263. <td>number</td>
  264. <td>no</td>
  265. <td>This level is used in the hierarchical layout. If this is not selected, the level does not do anything. This must be a postive number (min value: 0).
  266. Fractions are possible but only integers are supported.</td>
  267. </tr>
  268. <tr>
  269. <td>label</td>
  270. <td>string</td>
  271. <td>no</td>
  272. <td>Text label to be displayed in the node or under the image of the node.
  273. Multiple lines can be separated by a newline character <code>\n</code> .</td>
  274. </tr>
  275. <tr>
  276. <td>title</td>
  277. <td>string | function | Element</td>
  278. <td>no</td>
  279. <td>Title to be displayed when the user hovers over the node.
  280. The title can be an HTML element or a string containing plain text or HTML.
  281. When title is a function, the returned result is displayed as tooltip, and returning <code>undefined</code>
  282. will prevent the tooltip from being displayed.</td>
  283. </tr>
  284. <tr>
  285. <td>value</td>
  286. <td>number</td>
  287. <td>no</td>
  288. <td>A value for the node.
  289. The radius of the nodes will be scaled automatically from minimum to
  290. maximum value.
  291. Only applicable when the shape of the node is <code>dot</code>.
  292. If a <code>radius</code> is provided for the node too, it will override the
  293. radius calculated from the value.</td>
  294. </tr>
  295. <tr>
  296. <td>x</td>
  297. <td>number</td>
  298. <td>no</td>
  299. <td>Horizontal position in pixels.
  300. The horizontal position of the node will be fixed unless combined with the allowedToMoveX:true option.
  301. The vertical position y may remain undefined. This does not work with hierarchical layout.</td>
  302. </tr>
  303. <tr>
  304. <td>y</td>
  305. <td>number</td>
  306. <td>no</td>
  307. <td>Vertical position in pixels.
  308. The vertical position of the node will be fixed unless combined with the allowedToMoveY:true option.
  309. The horizontal position x may remain undefined. This does not work with hierarchical layout.</td>
  310. </tr>
  311. </table>
  312. <h3 id="Edges">Edges</h3>
  313. <p>
  314. Edges are connections between nodes.
  315. An edge must at least contain properties <code>from</code> and
  316. <code>to</code>, both referring to the <code>id</code> of a node.
  317. Edges can have extra properties, used to define the type and style.
  318. </p>
  319. <p>
  320. A JavaScript Array with edges is constructed as:
  321. </p>
  322. <pre class="prettyprint lang-js">
  323. var edges = [
  324. {
  325. from: 1,
  326. to: 3
  327. },
  328. // ... more edges
  329. ];
  330. </pre>
  331. Alternatively, a vis DataSet can also be used:
  332. <pre class="prettyprint lang-js">
  333. var edges = new vis.DataSet();
  334. edges.add([
  335. {from: '1', to: '2'},
  336. {from: '1', to: '3'},
  337. {from: '2', to: '4'},
  338. {from: '2', to: '5'},
  339. // ... more edges
  340. ]);
  341. </pre>
  342. When using a DataSet, the network is automatically updating to changes in the DataSet.
  343. <p>
  344. Edges support properties listed below. Each edge can be configured individually using
  345. the properties highlighted in green over at the <a href="#Edges_configuration">Edges configuration</a>.
  346. </p>
  347. <table>
  348. <tr>
  349. <th>Name</th>
  350. <th>Type</th>
  351. <th>Required</th>
  352. <th>Description</th>
  353. </tr>
  354. <tr>
  355. <td>from</td>
  356. <td>Number | String</td>
  357. <td>yes</td>
  358. <td>The id of a node where the edge starts. The type must correspond with
  359. the type of the node id's. This is normally a number, but can be any
  360. type.</td>
  361. </tr>
  362. <tr>
  363. <td>label</td>
  364. <td>string</td>
  365. <td>no</td>
  366. <td>Text label to be displayed halfway the edge.</td>
  367. </tr>
  368. <tr>
  369. <td>length</td>
  370. <td>number</td>
  371. <td>no</td>
  372. <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>
  373. </tr>
  374. <tr>
  375. <td>title</td>
  376. <td>string | function</td>
  377. <td>no</td>
  378. <td>Title to be displayed when the user hovers over the edge.
  379. The title can be an HTML element or a string containing plain text or HTML.
  380. When title is a function, the returned result is displayed as tooltip, and returning <code>undefined</code>
  381. will prevent the tooltip from being displayed.</td>
  382. </tr>
  383. <tr>
  384. <td>to</td>
  385. <td>Number | String</td>
  386. <td>yes</td>
  387. <td>The id of a node where the edge ends. The type must correspond with
  388. the type of the node id's. This is normally a number, but can be any
  389. type.</td>
  390. </tr>
  391. <tr>
  392. <td>value</td>
  393. <td>number</td>
  394. <td>no</td>
  395. <td>A value for the edge.
  396. The width of the edges will be scaled automatically from minimum to
  397. maximum value.
  398. If a <code>width</code> is provided for the edge too, it will override the
  399. width calculated from the value.</td>
  400. </tr>
  401. </table>
  402. <h3 id="DOT_language">DOT language</h3>
  403. <p>
  404. Network supports data in the
  405. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  406. To provide data in the DOT language, the <code>data</code> object must contain
  407. a property <code>dot</code> with a String containing the data.
  408. </p>
  409. <p>
  410. Example usage:
  411. </p>
  412. <pre class="prettyprint lang-js">
  413. // provide data in the DOT language
  414. var data = {
  415. dot: 'dinetwork {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
  416. };
  417. // create a network
  418. var network = new vis.Network(container, data);
  419. </pre>
  420. <h3 id="Gephi_import">Gephi import (JSON)</h3>
  421. <p>
  422. network can import data straight from an exported json file from gephi. You can get the JSON exporter here:
  423. <a href="https://marketplace.gephi.org/plugin/json-exporter/" target="_blank">https://marketplace.gephi.org/plugin/json-exporter/</a>.
  424. An example exists showing how to get a JSON file into Vis: <a href="../examples/network/30_importing_from_gephi.html">30_importing_from_gephi</a>.
  425. </p>
  426. <p>
  427. Example usage:
  428. </p>
  429. <pre class="prettyprint lang-js">
  430. // load the JSON file containing the Gephi network.
  431. var gephiJSON = loadJSON("./data/WorldCup2014.json"); // code in example 30
  432. // create a data object with the gephi key:
  433. var data = {
  434. gephi: gephiJSON
  435. };
  436. // create a network
  437. var network = new vis.Network(container, data);
  438. </pre>
  439. Alternatively you can use the parser manually:
  440. <pre class="prettyprint lang-js">
  441. // load the JSON file containing the Gephi network.
  442. var gephiJSON = loadJSON("./data/WorldCup2014.json"); // code in example 30
  443. // parse the gephi file to receive an object
  444. // containing nodes and edges in vis format.
  445. var parsed = vis.network.gephiParser.parseGephi(gephiJSON);
  446. // provide data in the normal fashion
  447. var data = {
  448. nodes: parsed.nodes,
  449. edged: parsed.edges
  450. };
  451. // create a network
  452. var network = new vis.Network(container, data);
  453. </pre>
  454. <h4>Gephi parser options</h4>
  455. There are a few options you can use to tell Vis what to do with the data from Gephi.
  456. <pre class="prettyprint lang-js">
  457. var parserOptions = {
  458. allowedToMove: false,
  459. parseColor: false
  460. }
  461. var parsed = vis.network.gephiParser.parseGephi(gephiJSON, parserOptions);
  462. </pre>
  463. <table>
  464. <tr>
  465. <th>Name</th>
  466. <th>Type</th>
  467. <th>Default</th>
  468. <th>Description</th>
  469. </tr>
  470. <tr>
  471. <td>allowedToMove</td>
  472. <td>Boolean</td>
  473. <td>false</td>
  474. <td>
  475. If true, the nodes will move according to the physics model after import. If false, the nodes do not move at all.
  476. </td>
  477. </tr>
  478. <tr>
  479. <td>parseColor</td>
  480. <td>Boolean</td>
  481. <td>false</td>
  482. <td>
  483. If true, the color will be parsed by the vis parser, generating extra colors for the borders, highlighs and hover. If false, the node will be the supplied color.
  484. </td>
  485. </tr>
  486. </table>
  487. <h2 id="Configuration_options">Configuration options</h2>
  488. <p>
  489. Options can be used to customize the network. Options are defined as a JSON object.
  490. All options are optional.
  491. </p>
  492. <pre class="prettyprint lang-js">
  493. var options = {
  494. width: '100%',
  495. height: '400px',
  496. edges: {
  497. color: 'red',
  498. width: 2
  499. }
  500. };
  501. </pre>
  502. <p>
  503. The following options are available.
  504. </p>
  505. <table>
  506. <tr>
  507. <th>Name</th>
  508. <th>Type</th>
  509. <th>Default</th>
  510. <th>Description</th>
  511. </tr>
  512. <tr>
  513. <td>clickToUse</td>
  514. <td>boolean</td>
  515. <td>false</td>
  516. <td>When a Network is configured to be <code>clickToUse</code>, it will react to mouse, touch, and keyboard events only when active.
  517. When active, a blue shadow border is displayed around the Network. The Network is set active by clicking on it, and is changed to inactive again by clicking outside the Network or by pressing the ESC key.</td>
  518. </tr>
  519. <tr>
  520. <td><a href="#Physics">physics</a></td>
  521. <td>Object</td>
  522. <td>none</td>
  523. <td>
  524. Configuration of the physics system governing the simulation of the nodes and edges.
  525. Barnes-Hut nBody simulation is used by default. See section <a href="#Physics">Physics</a> for an overview of the available options.
  526. </td>
  527. </tr>
  528. <tr>
  529. <td><a href="#Physics">configurePhysics</a></td>
  530. <td>Boolean</td>
  531. <td>false</td>
  532. <td>
  533. Enabling this setting will create a physics configuration div above the network. You can use this to fine tune the physics system to suit your needs.
  534. 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.
  535. </td>
  536. </tr>
  537. <tr>
  538. <td><a href="#Data_manipulation">dataManipulation</a></td>
  539. <td>Object</td>
  540. <td>none</td>
  541. <td>
  542. Settings for manipulating the Dataset. See section <a href="#Data_manipulation">Data manipulation</a> for an overview of the available options.
  543. </td>
  544. </tr>
  545. <tr>
  546. <td><a href="#Clustering">clustering</a></td>
  547. <td>Object</td>
  548. <td>none</td>
  549. <td>
  550. Clustering configuration. Clustering is turned off by default. See section <a href="#Clustering">Clustering</a> for an overview of the available options.
  551. </td>
  552. </tr>
  553. <tr>
  554. <td><a href="#Edges_configuration">edges</a></td>
  555. <td>Object</td>
  556. <td>none</td>
  557. <td>
  558. Configuration options applied to all edges. See section <a href="#Edges_configuration">Edges configuration</a> for an overview of the available options.
  559. </td>
  560. </tr>
  561. <tr>
  562. <td>freezeForStabilization</a></td>
  563. <td>Boolean</td>
  564. <td>false</td>
  565. <td>
  566. With the advent of the storePositions() 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
  567. to speed up the initialization of the network by using storePositions() and loading the nodes with the stored positions, the freezeForStabilization option freezes all nodes that have been supplied with
  568. 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.
  569. </td>
  570. </tr>
  571. <tr>
  572. <td><a href="#Groups_configuration">groups</a></td>
  573. <td>Object</td>
  574. <td>none</td>
  575. <td>It is possible to specify custom styles for groups.
  576. Each node assigned a group gets the specified style.
  577. See <a href="#Groups_configuration">Groups configuration</a> for an overview of the available styles
  578. and an example.
  579. </td>
  580. </tr>
  581. <tr>
  582. <td>height</td>
  583. <td>String</td>
  584. <td>"400px"</td>
  585. <td>The height of the network in pixels or as a percentage.</td>
  586. </tr>
  587. <tr>
  588. <td>hover</td>
  589. <td>Boolean</td>
  590. <td>false</td>
  591. <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>
  592. </tr>
  593. <tr>
  594. <td><a href="#Keyboard_navigation">keyboard</a></td>
  595. <td>Object</td>
  596. <td>none</td>
  597. <td>
  598. Configuration options for shortcuts keys. Shortcut keys are turned off by default. See section <a href="#Keyboard_navigation">Keyboard navigation</a> for an overview of the available options.
  599. </td>
  600. </tr>
  601. <tr>
  602. <td>dragNetwork</td>
  603. <td>Boolean</td>
  604. <td>true</td>
  605. <td>
  606. Toggle if the network can be dragged. This will not affect the dragging of nodes.
  607. </td>
  608. </tr>
  609. <tr>
  610. <td>dragNodes</td>
  611. <td>Boolean</td>
  612. <td>true</td>
  613. <td>
  614. Toggle if the nodes can be dragged. This will not affect the dragging of the network.
  615. </td>
  616. </tr>
  617. <tr>
  618. <td>hideNodesOnDrag</td>
  619. <td>Boolean</td>
  620. <td>false</td>
  621. <td>
  622. Toggle if the nodes are drawn during a drag. This can greatly improve performance if you have many nodes.
  623. </td>
  624. </tr>
  625. <tr>
  626. <td>hideEdgesOnDrag</td>
  627. <td>Boolean</td>
  628. <td>false</td>
  629. <td>
  630. Toggle if the edges are drawn during a drag. This can greatly improve performance if you have many edges.
  631. </td>
  632. </tr>
  633. <tr>
  634. <td><a href="#Navigation_controls">navigation</a></td>
  635. <td>Object</td>
  636. <td>none</td>
  637. <td>
  638. Configuration options for the navigation controls. See section <a href="#Navigation_controls">Navigation controls</a> for an overview of the available options.
  639. </td>
  640. </tr>
  641. <tr>
  642. <td><a href="#Nodes_configuration">nodes</a></td>
  643. <td>Object</td>
  644. <td>none</td>
  645. <td>
  646. Configuration options applied to all nodes. See section <a href="#Nodes_configuration">Nodes configuration</a> for an overview of the available options.
  647. </td>
  648. </tr>
  649. <tr>
  650. <td>smoothCurves</td>
  651. <td>Boolean || object</td>
  652. <td>object</td>
  653. <td>If true, edges are drawn as smooth curves. This is more computationally intensive since the edge now is a quadratic Bezier curve. This can be further configured by the options below.</td>
  654. </tr>
  655. <tr>
  656. <td>smoothCurves.dynamic</td>
  657. <td>Boolean</td>
  658. <td>true</td>
  659. <td>By default, the edges are dynamic. This means there are support nodes placed in the middle of the edge. This support node is also handed by the physics simulation. If false, the smoothness will be based on the
  660. relative positions of the to and from nodes. This is computationally cheaper but there is no self organisation.</td>
  661. </tr>
  662. <tr>
  663. <td>smoothCurves.type</td>
  664. <td>String</td>
  665. <td>"continuous"</td>
  666. <td>This option only affects NONdynamic smooth curves. The supported types are: <code>continuous, discrete, diagonalCross, straightCross, horizontal, vertical</code>. The effects of these types
  667. are shown in examples <a href="../examples/network/26_staticSmoothCurves.html">26</a> and <a href="../examples/network/27_world_cup_network.html">27</a></td>
  668. </tr>
  669. <tr>
  670. <td>smoothCurves.roundness</td>
  671. <td>Number</td>
  672. <td>0.5</td>
  673. <td>This only affects NONdynamic smooth curves. The roundness can be tweaked with the parameter. The value range is from 0 to 1 with a maximum roundness at 0.5.</td>
  674. </tr>
  675. <tr>
  676. <td>selectable</td>
  677. <td>Boolean</td>
  678. <td>true</td>
  679. <td>If true, nodes in the network can be selected by clicking them.
  680. Long press can be used to select multiple nodes.</td>
  681. </tr>
  682. <tr>
  683. <td>stabilize</td>
  684. <td>Boolean</td>
  685. <td>true</td>
  686. <td>If true, the network is stabilized before displaying it. If false,
  687. the nodes move to a stabe position visibly in an animated way.</td>
  688. </tr>
  689. <tr>
  690. <td>stabilizationIterations</td>
  691. <td>Number</td>
  692. <td>1000</td>
  693. <td>If stabilize is set to true, this number is the (maximum) amount of physics steps the stabilization process takes
  694. before showing the result. If your simulation takes too long to stabilize, this number can be reduced. On the other hand, if your network is not stabilized after loading, this number can be increased.</td>
  695. </tr>
  696. <tr>
  697. <td>zoomExtentOnStabilize</td>
  698. <td>Boolean</td>
  699. <td>true</td>
  700. <td>When the internal stabilize function is called because the stabilize option is set to true OR the hierarchical system (re)initializes, a call to zoomExtent is done by default. By setting this to false, you can avoid this call.</td>
  701. </tr>
  702. <tr>
  703. <td>width</td>
  704. <td>String</td>
  705. <td>"400px"</td>
  706. <td>The width of the network in pixels or as a percentage.</td>
  707. </tr>
  708. <tr>
  709. <td>zoomable</td>
  710. <td>Boolean</td>
  711. <td>true</td>
  712. <td>
  713. Toggle if the network can be zoomed.
  714. </td>
  715. </tr>
  716. </table>
  717. <br>
  718. <h3 id="Nodes_configuration">Nodes configuration</h3>
  719. <p>
  720. 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 Network.
  721. </p>
  722. <p>
  723. For example to give the nodes a custom color, shape, and size:
  724. </p>
  725. <pre class="prettyprint lang-js">
  726. var options = {
  727. // ...
  728. nodes: {
  729. color: {
  730. background: 'white',
  731. border: 'red',
  732. highlight: {
  733. background: 'pink',
  734. border: 'red'
  735. }
  736. },
  737. shape: 'star',
  738. radius: 24
  739. }
  740. };
  741. </pre>
  742. <p>
  743. The following options are available for nodes. These options must be created
  744. inside an object <code>nodes</code> in the networks options object.</p> All options in green boxes can be defined per-node as well.
  745. All options defined per-node override these global settings.
  746. <table>
  747. <tr>
  748. <td class="greenField">borderWidth</td>
  749. <td>Number</td>
  750. <td>1</td>
  751. <td>The width of the border of the node when it is not selected, automatically limited by the width of the node.</td>
  752. </tr>
  753. <tr>
  754. <td class="greenField">borderWidthSelected</td>
  755. <td>Number</td>
  756. <td>undefined</td>
  757. <td>The width of the border of the node when it is selected. If left at undefined, double the borderWidth will be used.</td>
  758. </tr>
  759. <tr>
  760. <td class="greenField">color</td>
  761. <td>String | Object</td>
  762. <td>Object</td>
  763. <td>Color for the node.</td>
  764. </tr>
  765. <tr>
  766. <td class="greenField">color.background</td>
  767. <td>String</td>
  768. <td>#97C2FC</td>
  769. <td>Background color for the node.</td>
  770. </tr>
  771. <tr>
  772. <td class="greenField">color.border</td>
  773. <td>String</td>
  774. <td>#2B7CE9</td>
  775. <td>Border color for the node.</td>
  776. </tr>
  777. <tr>
  778. <td class="greenField">color.highlight</td>
  779. <td>String | Object</td>
  780. <td>Object</td>
  781. <td>Color of the node when selected.</td>
  782. </tr>
  783. <tr>
  784. <td class="greenField">color.highlight.background</td>
  785. <td>String</td>
  786. <td>#D2E5FF</td>
  787. <td>Background color of the node when selected.</td>
  788. </tr>
  789. <tr>
  790. <td class="greenField">color.highlight.border</td>
  791. <td>String</td>
  792. <td>#2B7CE9</td>
  793. <td>Border color of the node when selected.</td>
  794. </tr>
  795. <tr>
  796. <td class="greenField">color.hover.background</td>
  797. <td>String</td>
  798. <td>#D2E5FF</td>
  799. <td>Background color of the node when the node is hovered over and the hover option is enabled.</td>
  800. </tr>
  801. <tr>
  802. <td class="greenField">color.hover.border</td>
  803. <td>String</td>
  804. <td>#2B7CE9</td>
  805. <td>Border color of the node when the node is hovered over and the hover option is enabled.</td>
  806. </tr>
  807. <tr>
  808. <td class="greenField">fontColor</td>
  809. <td>String</td>
  810. <td>black</td>
  811. <td>Font color for label in the node.</td>
  812. </tr>
  813. <tr>
  814. <td class="greenField">fontFace</td>
  815. <td>String</td>
  816. <td>verdana</td>
  817. <td>Font face for label in the node, for example "verdana" or "arial".</td>
  818. </tr>
  819. <tr>
  820. <td class="greenField">fontSize</td>
  821. <td>Number</td>
  822. <td>14</td>
  823. <td>Font size in pixels for label in the node.</td>
  824. </tr>
  825. <tr>
  826. <td class="greenField">fontFill</td>
  827. <td>String</td>
  828. <td>undefined</td>
  829. <td>If a color is supplied, there will be a background color behind the label. If left undefined, no background color is shown.</td>
  830. </tr>
  831. <tr>
  832. <td class="greenField">fontStrokeWidth</td>
  833. <td>Number</td>
  834. <td>0</td>
  835. <td>The width of the label stroke (border around label's text) in pixels.</td>
  836. </tr>
  837. <tr>
  838. <td class="greenField">fontStrokeColor</td>
  839. <td>String</td>
  840. <td>'white'</td>
  841. <td>The color of the label stroke.</td>
  842. </tr>
  843. <tr>
  844. <td class="greenField">shape</td>
  845. <td>string</td>
  846. <td>'ellipse'</td>
  847. <td>Define the shape for the node.
  848. Choose from
  849. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  850. <code>database</code>, <code>image</code>, <code>circularImage</code>, <code>label</code>, <code>dot</code>,
  851. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  852. <br><br>
  853. In case of <code>image</code> and <code>circularImage</code>, a property with name <code>image</code> must
  854. be provided, containing image urls.
  855. <br><br>
  856. The shapes <code>dot</code>, <code>star</code>, <code>triangle</code>,
  857. <code>triangleDown</code>, and <code>square</code>, are scalable.
  858. The size is determined by the properties <code>radius</code> or
  859. <code>value</code>.
  860. <br><br>
  861. When a property <code>label</code> is provided,
  862. this label will be displayed inside the shape in case of shapes
  863. <code>box</code>, <code>circle</code>, <code>ellipse</code>,
  864. and <code>database</code>.
  865. For all other shapes, the label will be displayed right below the shape.
  866. This shape can be overridden by a group shape, or by a shape of an individual node.
  867. </td>
  868. </tr>
  869. <tr>
  870. <td class="greenField">image</td>
  871. <td>String</td>
  872. <td>undefined</td>
  873. <td>Default image url for the nodes. only applicable to shape <code>image</code>.</td>
  874. </tr>
  875. <tr>
  876. <td class="greenField">brokenImage</td>
  877. <td>String</td>
  878. <td>undefined</td>
  879. <td>Image url to use in the event that the url specified in the <code>image</code> property fails to load. only applicable to shape <code>image</code>.</td>
  880. </tr>
  881. <tr>
  882. <td class="greenField">mass</td>
  883. <td>number</td>
  884. <td>1</td>
  885. <td>When using the Barnes Hut simulation method (which is selected by default),
  886. the mass of a node determines the gravitational repulsion during the simulation. Higher mass will push other nodes further away. Preferably use the physics configuration to
  887. alter the simulation.</td>
  888. </tr>
  889. <tr>
  890. <td>widthMin</td>
  891. <td>Number</td>
  892. <td>16</td>
  893. <td>The minimum width for a scaled image. Only applicable to shape <code>image</code>. This only does something if you supply a value.</td>
  894. </tr>
  895. <tr>
  896. <td>widthMax</td>
  897. <td>Number</td>
  898. <td>64</td>
  899. <td>The maximum width for a scaled image. Only applicable to shape <code>image</code>. This only does something if you supply a value.</td>
  900. </tr>
  901. <tr>
  902. <td class="greenField">radius</td>
  903. <td>Number</td>
  904. <td>10</td>
  905. <td>The default radius for a node. Only applicable to shapes <code>dot</code>,
  906. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  907. </tr>
  908. <tr>
  909. <td>radiusMin</td>
  910. <td>Number</td>
  911. <td>10</td>
  912. <td>The minimum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  913. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>. This only does something if you supply a value.</td>
  914. </tr>
  915. <tr>
  916. <td>radiusMax</td>
  917. <td>Number</td>
  918. <td>30</td>
  919. <td>The maximum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  920. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>. This only does something if you supply a value.</td>
  921. </tr>
  922. </table>
  923. <h3 id="Edges_configuration">Edges configuration</h3>
  924. <p>
  925. 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 Network.
  926. Because the length of an edge is a property of the physics simulation, you can change the length of the edge by changing the springLength in your selected physics solver.
  927. To change the edge length of individual edges, you can use the <code>length</code> property in the <a href="#Edges">edge definition</a>.
  928. </p>
  929. <p>
  930. For example to set the width of all edges to 2 pixels and give them a red color:
  931. </p>
  932. <pre class="prettyprint lang-js">
  933. var options = {
  934. // ...
  935. edges: {
  936. color: 'red',
  937. width: 2
  938. }
  939. };
  940. </pre>
  941. <p>
  942. The following options are available for edges. These options must be created
  943. inside an object <code>edges</code> in the networks options object. All options in green boxes can be defined per-edge as well.
  944. All options defined per-edge override these global settings.
  945. </p>
  946. <table>
  947. <tr>
  948. <th>Name</th>
  949. <th>Type</th>
  950. <th>Default</th>
  951. <th>Description</th>
  952. </tr>
  953. <tr>
  954. <td class="greenField">arrowScaleFactor</td>
  955. <td>Number</td>
  956. <td>1</td>
  957. <td>If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1.</td>
  958. </tr>
  959. <tr>
  960. <td class="greenField">color</td>
  961. <td>String | Object</td>
  962. <td>Object</td>
  963. <td>Color for the edge.</td>
  964. </tr>
  965. <tr>
  966. <td class="greenField">color.color</td>
  967. <td>String</td>
  968. <td>#848484</td>
  969. <td>Color of the edge when not selected.</td>
  970. </tr>
  971. <tr>
  972. <td class="greenField">color.highlight</td>
  973. <td>String</td>
  974. <td>#848484</td>
  975. <td>Color of the edge when selected.</td>
  976. </tr>
  977. <tr>
  978. <td class="greenField">color.hover</td>
  979. <td>String</td>
  980. <td>#848484</td>
  981. <td>Color of the edge when the edge is hovered over and the hover option is enabled.</td>
  982. </tr>
  983. <tr>
  984. <td class="greenField">hoverWidth</td>
  985. <td>Number</td>
  986. <td>1.5</td>
  987. <td>This determines the thickness of the edge if it is hovered over. This will only manifest when the hover option is enabled.</td>
  988. </tr>
  989. <tr>
  990. <td class="greenField">dash</td>
  991. <td>Object</td>
  992. <td>Object</td>
  993. <td>
  994. Object containing properties for dashed lines.
  995. Available properties: <code>length</code>, <code>gap</code>,
  996. <code>altLength</code>.
  997. </td>
  998. </tr>
  999. <tr>
  1000. <td class="greenField">dash.altLength</td>
  1001. <td>number</td>
  1002. <td>undefined</td>
  1003. <td>Length of the alternated dash in pixels on a dashed line.
  1004. Specifying <code>dash.altLength</code> allows for creating
  1005. a dashed line with a dash-dot style, for example when
  1006. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  1007. See also the option <code>dahs.length</code>.
  1008. Only applicable when the line style is <code>dash-line</code>.</td>
  1009. </tr>
  1010. <tr>
  1011. <td class="greenField">dash.length</td>
  1012. <td>number</td>
  1013. <td>10</td>
  1014. <td>Length of a dash in pixels on a dashed line.
  1015. Only applicable when the line style is <code>dash-line</code>.</td>
  1016. </tr>
  1017. <tr>
  1018. <td class="greenField">dash.gap</td>
  1019. <td>number</td>
  1020. <td>5</td>
  1021. <td>Length of a gap in pixels on a dashed line.
  1022. Only applicable when the line style is <code>dash-line</code>.</td>
  1023. </tr>
  1024. <tr>
  1025. <td class="greenField">fontColor</td>
  1026. <td>String</td>
  1027. <td>#343434</td>
  1028. <td>Font color for the text label of the edge.
  1029. Only applicable when property <code>label</code> is defined.</td>
  1030. </tr>
  1031. <tr>
  1032. <td class="greenField">fontFace</td>
  1033. <td>String</td>
  1034. <td>arial</td>
  1035. <td>Font face for the text label of the edge,
  1036. for example "verdana" or "arial".
  1037. Only applicable when property <code>label</code> is defined.</td>
  1038. </tr>
  1039. <tr>
  1040. <td class="greenField">fontSize</td>
  1041. <td>Number</td>
  1042. <td>14</td>
  1043. <td>Font size in pixels for the text label of the edge.
  1044. Only applicable when property <code>label</code> is defined.</td>
  1045. </tr>
  1046. <tr>
  1047. <td class="greenField">fontFill</td>
  1048. <td>string</td>
  1049. <td>white</td>
  1050. <td>Font fill for the background color of the text label of the edge.
  1051. Only applicable when property <code>label</code> is defined.</td>
  1052. </tr>
  1053. <tr>
  1054. <td class="greenField">fontStrokeWidth</td>
  1055. <td>Number</td>
  1056. <td>0</td>
  1057. <td>The width of the label stroke (border around label's text) in pixels.
  1058. Only applicable when property <code>label</code> is defined.</td>
  1059. </tr>
  1060. <tr>
  1061. <td class="greenField">fontStrokeColor</td>
  1062. <td>String</td>
  1063. <td>'white'</td>
  1064. <td>The color of the label stroke.
  1065. Only applicable when property <code>label</code> is defined.</td>
  1066. </tr>
  1067. <tr>
  1068. <td class="greenField">inheritColor</td>
  1069. <td>String | Boolean</td>
  1070. <td>from</td>
  1071. <td>Possible values: <code>"to","from", true, false</code>. If this value is set to false, the edge color information is used. If the value is set to true or "from",
  1072. the color data from the borders of the "from" node is used. If this value is "to", the color data from the borders of the "to" node is used.</td>
  1073. </tr>
  1074. <tr>
  1075. <td class="greenField">labelAlignment</td>
  1076. <td>String</td>
  1077. <td>horizontal</td>
  1078. <td>Possible values: <code>"line-above", "line-center", "line-below"</code>. The alignment of the label when drawn on the edge.
  1079. If <code>horizontal</code> it will align the label absolute horizontial.</td>
  1080. </tr>
  1081. <tr>
  1082. <td class="greenField">style</td>
  1083. <td>string</td>
  1084. <td>line</td>
  1085. <td>Define a line style for the edge.
  1086. Choose from <code>line</code> (default), <code>arrow</code>,
  1087. <code>arrow-center</code>, or <code>dash-line</code>.
  1088. </td>
  1089. </tr>
  1090. <tr>
  1091. <td class="greenField">width</td>
  1092. <td>number</td>
  1093. <td>1</td>
  1094. <td>Width of the line in pixels. The <code>width</code> will
  1095. override a specified <code>value</code>, if a <code>value</code> is
  1096. specified too.</td>
  1097. </tr>
  1098. <tr>
  1099. <td class="greenField">widthSelectionMultiplier</td>
  1100. <td>Number</td>
  1101. <td>2</td>
  1102. <td>Determines the thickness scaling of an selected edge. This is applied when an edge, or a node connected to it, is selected.</td>
  1103. </tr>
  1104. <tr>
  1105. <td>widthMin</td>
  1106. <td>Number</td>
  1107. <td>1</td>
  1108. <td>The minimum thickness of the line when using per-edge defined values. This does nothing if you have not defined a value.</td>
  1109. </tr>
  1110. <tr>
  1111. <td>widthMax</td>
  1112. <td>Number</td>
  1113. <td>15</td>
  1114. <td>The maximum thickness of the line when using per-edge defined values. This does nothing if you have not defined a value.</td>
  1115. </tr>
  1116. </table>
  1117. <h3 id="Groups_configuration">Groups configuration</h3>
  1118. <p>It is possible to specify custom styles for groups of nodes.
  1119. Each node having assigned to this group gets the specified style.
  1120. The options <code>groups</code> is an object containing one or multiple groups,
  1121. identified by a unique string, the groupname.
  1122. </p>
  1123. <p>
  1124. A group can have the following styles:
  1125. </p>
  1126. <pre class="prettyprint lang-js">
  1127. var options = {
  1128. // ...
  1129. groups: {
  1130. mygroup: {
  1131. shape: 'circle',
  1132. color: {
  1133. border: 'black',
  1134. background: 'white',
  1135. highlight: {
  1136. border: 'yellow',
  1137. background: 'orange'
  1138. }
  1139. }
  1140. fontColor: 'red',
  1141. fontSize: 18
  1142. }
  1143. // add more groups here
  1144. }
  1145. };
  1146. var nodes = [
  1147. {id: 1, label: 'Node 1'}, // will get the default style
  1148. {id: 2, label: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  1149. // ... more nodes
  1150. ];
  1151. </pre>
  1152. <p>The following styles are available for groups:</p>
  1153. <table>
  1154. <tr>
  1155. <th>Name</th>
  1156. <th>Type</th>
  1157. <th>Default</th>
  1158. <th>Description</th>
  1159. </tr>
  1160. <tr>
  1161. <td>color</td>
  1162. <td>String | Object</td>
  1163. <td>Object</td>
  1164. <td>Color of the node</td>
  1165. </tr>
  1166. <tr>
  1167. <td>color.border</td>
  1168. <td>String</td>
  1169. <td>"#2B7CE9"</td>
  1170. <td>Border color of the node</td>
  1171. </tr>
  1172. <tr>
  1173. <td>color.background</td>
  1174. <td>String</td>
  1175. <td>"#97C2FC"</td>
  1176. <td>Background color of the node</td>
  1177. </tr>
  1178. <tr>
  1179. <td>color.highlight</td>
  1180. <td>String | Object</td>
  1181. <td>"#D2E5FF"</td>
  1182. <td>Default color of the node when the node is selected. In case of a string, the color is applied to
  1183. both border and background of the node.</td>
  1184. </tr>
  1185. <tr>
  1186. <td>color.highlight.background</td>
  1187. <td>String</td>
  1188. <td>"#D2E5FF"</td>
  1189. <td>Background color of the node when selected.</td>
  1190. </tr>
  1191. <tr>
  1192. <td>color.highlight.border</td>
  1193. <td>String</td>
  1194. <td>"#D2E5FF"</td>
  1195. <td>Border color of the node when selected.</td>
  1196. </tr>
  1197. <tr>
  1198. <td>image</td>
  1199. <td>String</td>
  1200. <td>none</td>
  1201. <td>Default image for the nodes. Only applicable in combination with
  1202. shape <code>image</code>.</td>
  1203. </tr>
  1204. <tr>
  1205. <td>fontColor</td>
  1206. <td>String</td>
  1207. <td>"black"</td>
  1208. <td>Font color of the node.</td>
  1209. </tr>
  1210. <tr>
  1211. <td>fontFace</td>
  1212. <td>String</td>
  1213. <td>"sans"</td>
  1214. <td>Font name of the node, for example "verdana" or "arial".</td>
  1215. </tr>
  1216. <tr>
  1217. <td>fontSize</td>
  1218. <td>Number</td>
  1219. <td>14</td>
  1220. <td>Font size for the node in pixels.</td>
  1221. </tr>
  1222. <tr>
  1223. <td>fontStrokeWidth</td>
  1224. <td>Number</td>
  1225. <td>0</td>
  1226. <td>The width of the label stroke (border around label's text) in pixels.</td>
  1227. </tr>
  1228. <tr>
  1229. <td>fontStrokeColor</td>
  1230. <td>String</td>
  1231. <td>"white"</td>
  1232. <td>The color of the label stroke.</td>
  1233. </tr>
  1234. <tr>
  1235. <td>shape</td>
  1236. <td>String</td>
  1237. <td>"ellipse"</td>
  1238. <td>Choose from
  1239. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  1240. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  1241. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  1242. In case of image, a property with name image must be provided, containing
  1243. image urls.</td>
  1244. </tr>
  1245. <tr>
  1246. <td>radius</td>
  1247. <td>Number</td>
  1248. <td>5</td>
  1249. <td>Default radius for the node. Only applicable in combination with
  1250. shapes <code>box</code> and <code>dot</code>.</td>
  1251. </tr>
  1252. </table>
  1253. <h3 id="Physics">Physics</h3>
  1254. <p>
  1255. The original simulation method was based on particel physics with a repulsion field (potential) around each node,
  1256. 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.
  1257. 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.
  1258. 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. <br/>
  1259. When using the hierarchical display option, hierarchicalRepulsion is automatically used as the physics solver. Similarly, if you use the hierarchicalRepulsion physics option, hierarchical display is automatically turned on with default settings.
  1260. <p class="important_note">Note: if the behaviour of your network is not the way you want it, use configurePhysics as described <u><a href="#PhysicsConfiguration">below</a></u> or by <u><a href="../examples/network/25_physics_configuration.html">example 25</a></u>.</p>
  1261. </p>
  1262. <pre class="prettyprint">
  1263. // These variables must be defined in an options object named physics.
  1264. // If a variable is not supplied, the default value is used.
  1265. var options = {
  1266. physics: {
  1267. barnesHut: {
  1268. enabled: true,
  1269. gravitationalConstant: -2000,
  1270. centralGravity: 0.1,
  1271. springLength: 95,
  1272. springConstant: 0.04,
  1273. damping: 0.09
  1274. },
  1275. repulsion: {
  1276. centralGravity: 0.1,
  1277. springLength: 50,
  1278. springConstant: 0.05,
  1279. nodeDistance: 100,
  1280. damping: 0.09
  1281. },
  1282. hierarchicalRepulsion: {
  1283. centralGravity: 0.5,
  1284. springLength: 150,
  1285. springConstant: 0.01,
  1286. nodeDistance: 60,
  1287. damping: 0.09
  1288. }
  1289. }
  1290. </pre>
  1291. <h5>barnesHut:</h5>
  1292. <table>
  1293. <tr>
  1294. <th>Name</th>
  1295. <th>Type</th>
  1296. <th>Default</th>
  1297. <th>Description</th>
  1298. </tr>
  1299. <tr>
  1300. <td>enabled</td>
  1301. <td>Boolean</td>
  1302. <td>true</td>
  1303. <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>
  1304. </tr>
  1305. <tr>
  1306. <td>gravitationalConstant</td>
  1307. <td>Number</td>
  1308. <td>-2000</td>
  1309. <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>
  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>95</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>springConstant</td>
  1326. <td>Number</td>
  1327. <td>0.04</td>
  1328. <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>
  1329. </tr>
  1330. <tr>
  1331. <td>damping</td>
  1332. <td>Number</td>
  1333. <td>0.09</td>
  1334. <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>
  1335. </tr>
  1336. </table>
  1337. <h5>repulsion:</h5>
  1338. <table>
  1339. <tr>
  1340. <th>Name</th>
  1341. <th>Type</th>
  1342. <th>Default</th>
  1343. <th>Description</th>
  1344. </tr>
  1345. <tr>
  1346. <td>centralGravity</td>
  1347. <td>Number</td>
  1348. <td>0.1</td>
  1349. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1350. </tr>
  1351. <tr>
  1352. <td>nodeDistance</td>
  1353. <td>Number</td>
  1354. <td>100</td>
  1355. <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>
  1356. </tr>
  1357. <tr>
  1358. <td>springLength</td>
  1359. <td>Number</td>
  1360. <td>50</td>
  1361. <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.
  1362. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1363. </tr>
  1364. <tr>
  1365. <td>springConstant</td>
  1366. <td>Number</td>
  1367. <td>0.05</td>
  1368. <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>
  1369. </tr>
  1370. <tr>
  1371. <td>damping</td>
  1372. <td>Number</td>
  1373. <td>0.09</td>
  1374. <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>
  1375. </tr>
  1376. </table>
  1377. <h5>hierarchicalRepulsion:</h5>
  1378. <table>
  1379. <tr>
  1380. <th>Name</th>
  1381. <th>Type</th>
  1382. <th>Default</th>
  1383. <th>Description</th>
  1384. </tr>
  1385. <tr>
  1386. <td>centralGravity</td>
  1387. <td>Number</td>
  1388. <td>0.5</td>
  1389. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1390. </tr>
  1391. <tr>
  1392. <td>nodeDistance</td>
  1393. <td>Number</td>
  1394. <td>60</td>
  1395. <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>
  1396. </tr>
  1397. <tr>
  1398. <td>springLength</td>
  1399. <td>Number</td>
  1400. <td>100</td>
  1401. <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.
  1402. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1403. </tr>
  1404. <tr>
  1405. <td>springConstant</td>
  1406. <td>Number</td>
  1407. <td>0.01</td>
  1408. <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>
  1409. </tr>
  1410. <tr>
  1411. <td>damping</td>
  1412. <td>Number</td>
  1413. <td>0.09</td>
  1414. <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>
  1415. </tr>
  1416. </table>
  1417. <h4 id="PhysicsConfiguration">Configuration:</h4>
  1418. Every dataset is different. Nodes can have different sizes based on content, interconnectivity can be high or low etc. Because of this, network has a special option
  1419. 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
  1420. settings you are happy with, you can supply them to network using the physics options as described above.
  1421. 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.
  1422. <pre class="prettyprint">
  1423. var options = {
  1424. configurePhysics:true
  1425. }
  1426. </pre>
  1427. <h3 id="Data_manipulation">Data manipulation</h3>
  1428. <p>
  1429. By using the data manipulation feature of the network you can dynamically create nodes, connect nodes with edges, edit nodes or delete nodes and edges.
  1430. 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
  1431. 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/network/21_data_manipulation.html">example 21</a>,
  1432. 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.
  1433. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1434. </p>
  1435. <pre class="prettyprint">
  1436. // These variables must be defined in an options object named dataManipulation.
  1437. // If a variable is not supplied, the default value is used.
  1438. var options = {
  1439. dataManipulation: {
  1440. enabled: false,
  1441. initiallyVisible: false
  1442. }
  1443. }
  1444. // OR to just load the module with default values:
  1445. var options = {
  1446. dataManipulation: true
  1447. }
  1448. </pre>
  1449. <table>
  1450. <tr>
  1451. <th>Name</th>
  1452. <th>Type</th>
  1453. <th>Default</th>
  1454. <th>Description</th>
  1455. </tr>
  1456. <tr>
  1457. <td>enabled</td>
  1458. <td>Boolean</td>
  1459. <td>false</td>
  1460. <td>Enabling or disabling of the data manipulation toolbar. If it is initially hidden, an edit button appears in the top left corner.</td>
  1461. </tr>
  1462. <tr>
  1463. <td>initiallyVisible</td>
  1464. <td>Boolean</td>
  1465. <td>false</td>
  1466. <td>Initially hide or show the data manipulation toolbar.</td>
  1467. </tr>
  1468. </table>
  1469. <h4 id="Data_manipulation_custom">Data manipulation: custom functionality</h4>
  1470. <p>
  1471. 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.
  1472. If the callback is NOT called, nothing happens. <a href="../examples/network/21_data_manipulation.html">Example 21</a> has two working examples
  1473. for the add and edit functions. The data the user is supplied with in these functions has been described in the code below.
  1474. 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
  1475. 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
  1476. requires the same data structure that is supplied to the user. <br /><br />
  1477. <b>If there is no injected function supplied for the edit operation, the button will not be shown in the toolbar.</b>
  1478. </p>
  1479. <pre class="prettyprint">
  1480. // If a variable is not supplied, the default value is used.
  1481. var options = {
  1482. dataManipulation: true,
  1483. onAdd: function(data,callback) {
  1484. /** data = {id: random unique id,
  1485. * label: new,
  1486. * x: x position of click (canvas space),
  1487. * y: y position of click (canvas space),
  1488. * allowedToMoveX: true,
  1489. * allowedToMoveY: true
  1490. * };
  1491. */
  1492. var newData = {..}; // alter the data as you want.
  1493. // all fields normally accepted by a node can be used.
  1494. callback(newData); // call the callback to add a node.
  1495. },
  1496. onEdit: function(data,callback) {
  1497. /** data = {id:...,
  1498. * label: ...,
  1499. * group: ...,
  1500. * shape: ...,
  1501. * color: {
  1502. * background:...,
  1503. * border:...,
  1504. * highlight: {
  1505. * background:...,
  1506. * border:...
  1507. * }
  1508. * }
  1509. * };
  1510. */
  1511. var newData = {..}; // alter the data as you want.
  1512. // all fields normally accepted by a node can be used.
  1513. callback(newData); // call the callback with the new data to edit the node.
  1514. }
  1515. onEditEdge: function(data,callback) {
  1516. /** data = {id: edgeID,
  1517. * from: nodeId1,
  1518. * to: nodeId2,
  1519. * };
  1520. */
  1521. var newData = {..}; // alter the data as you want, except for the ID.
  1522. // all fields normally accepted by an edge can be used.
  1523. callback(newData); // call the callback with the new data to edit the edge.
  1524. }
  1525. onConnect: function(data,callback) {
  1526. // data = {from: nodeId1, to: nodeId2};
  1527. var newData = {..}; // check or alter data as you see fit.
  1528. callback(newData); // call the callback to connect the nodes.
  1529. },
  1530. onDelete: function(data,callback) {
  1531. // data = {nodes: [selectedNodeIds], edges: [selectedEdgeIds]};
  1532. var newData = {..}; // alter the data as you want.
  1533. // the same data structure is required.
  1534. callback(newData); // call the callback to delete the objects.
  1535. }
  1536. };
  1537. </pre>
  1538. <p>
  1539. 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.
  1540. 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.
  1541. An code snippet from example 21 is shown below.
  1542. </p>
  1543. <pre class="prettyprint">
  1544. network.on("resize", function(params) {console.log(params.width,params.height)});
  1545. </pre>
  1546. <h3 id="Clustering">Clustering</h3>
  1547. <p>
  1548. The network now supports dynamic clustering of nodes. This allows a user to view a very large dataset (> 50.000 nodes) without
  1549. sacrificing performance. When loading a large dataset, the nodes are clustered initially (this may take a small while) to have a
  1550. responsive visualization to work with. The clustering is both outside-in and inside-out. Outside-in means that nodes with only one
  1551. connection will be contained, or clustered, in the node it is connected to. Inside-out clustering first determines which nodes are hubs.
  1552. Hubs are defined as the nodes with the top 3% highest amount of connections (assuming normal distribution). These hubs then "grow", meaning
  1553. 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.
  1554. <br />
  1555. <br />
  1556. 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
  1557. to calculate the required forces. The contained nodes are removed from the global nodes index, greatly speeding up the system.
  1558. <br />
  1559. <br />
  1560. The clustering has the following user-configurable settings. The default values have been tested with the Network examples and work well.
  1561. The default state for clustering is <b>off</b>.
  1562. </p>
  1563. <pre class="prettyprint">
  1564. // These variables must be defined in an options object named clustering.
  1565. // If a variable is not supplied, the default value is used.
  1566. var options = {
  1567. clustering: {
  1568. initialMaxNodes: 100,
  1569. clusterThreshold:500,
  1570. reduceToNodes:300,
  1571. chainThreshold: 0.4,
  1572. clusterEdgeThreshold: 20,
  1573. sectorThreshold: 100,
  1574. screenSizeThreshold: 0.2,
  1575. fontSizeMultiplier: 4.0,
  1576. maxFontSize: 1000,
  1577. forceAmplification: 0.1,
  1578. distanceAmplification: 0.1,
  1579. edgeGrowth: 20,
  1580. nodeScaling: {width: 1,
  1581. height: 1,
  1582. radius: 1},
  1583. maxNodeSizeIncrements: 600,
  1584. activeAreaBoxSize: 100,
  1585. clusterLevelDifference: 2
  1586. }
  1587. }
  1588. // OR to just load the module with default values:
  1589. var options = {
  1590. clustering: true
  1591. }
  1592. </pre>
  1593. <table>
  1594. <tr>
  1595. <th>Name</th>
  1596. <th>Type</th>
  1597. <th>Default</th>
  1598. <th>Description</th>
  1599. </tr>
  1600. <tr>
  1601. <td>initialMaxNodes</td>
  1602. <td>Number</td>
  1603. <td>100</td>
  1604. <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>
  1605. </tr>
  1606. <tr>
  1607. <td>clusterThreshold</td>
  1608. <td>Number</td>
  1609. <td>500</td>
  1610. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1611. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continuously fluid.</td>
  1612. </tr>
  1613. <tr>
  1614. <td>reduceToNodes</td>
  1615. <td>Number</td>
  1616. <td>300</td>
  1617. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1618. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  1619. </tr>
  1620. <tr>
  1621. <td>chainThreshold</td>
  1622. <td>Number</td>
  1623. <td>0.4</td>
  1624. <td>Because of the clustering methods used, long chains of nodes can be formed. To reduce these chains, this threshold is used.
  1625. 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).
  1626. If there are more, they are clustered together.</td>
  1627. </tr>
  1628. <tr>
  1629. <td>clusterEdgeThreshold</td>
  1630. <td>Number</td>
  1631. <td>20</td>
  1632. <td>This is the absolute edge length threshold in pixels. If the edge is smaller on screen (that means zooming out reduces this length)
  1633. the node will be clustered. This is triggered when zooming out.</td>
  1634. </tr>
  1635. <tr>
  1636. <td>sectorThreshold</td>
  1637. <td>Integer</td>
  1638. <td>50</td>
  1639. <td>If a cluster larger than <code>sectorThreshold</code> is opened, a seperate instance called a sector, will be created. All the simulation of
  1640. nodes outside of this instance will be paused. This is to maintain performance and clarity when examining large clusters.
  1641. 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>
  1642. </tr>
  1643. <tr>
  1644. <td>screenSizeThreshold</td>
  1645. <td>Number</td>
  1646. <td>0.2</td>
  1647. <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
  1648. 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
  1649. 20%, we collapse this sector.</td>
  1650. </tr>
  1651. <tr>
  1652. <td>fontSizeMultiplier</td>
  1653. <td>Number</td>
  1654. <td>4.0</td>
  1655. <td>This parameter denotes the increase in fontSize of the cluster when a single node is added to it.</td>
  1656. </tr>
  1657. <tr>
  1658. <td>maxFontSize</td>
  1659. <td>Number</td>
  1660. <td>1000</td>
  1661. <td>This parameter denotes the largest allowed font size. If the font becomes too large, some browsers experience problems displaying this.</td>
  1662. </tr>
  1663. <tr>
  1664. <td>forceAmplification</td>
  1665. <td>Number</td>
  1666. <td>0.6</td>
  1667. <td>This factor is used to calculate the increase of the repulsive force of a cluster. It is calculated by the following
  1668. formula: <code>repulsingForce *= 1 + (clusterSize * forceAmplification)</code>.</td>
  1669. </tr>
  1670. <tr>
  1671. <td>distanceAmplification</td>
  1672. <td>Number</td>
  1673. <td>0.2</td>
  1674. <td>This factor is used to calculate the increase in effective range of the repulsive force of the cluster.
  1675. A larger cluster has a longer range. It is calculated by the following
  1676. formula: <code>minDistance *= 1 + (clusterSize * distanceAmplification)</code>.</td>
  1677. </tr>
  1678. <tr>
  1679. <td>edgeGrowth</td>
  1680. <td>Number</td>
  1681. <td>20</td>
  1682. <td>This factor determines the elongation of edges connected to a cluster.</td>
  1683. </tr>
  1684. <tr>
  1685. <td>nodeScaling.width</td>
  1686. <td>Number</td>
  1687. <td>10</td>
  1688. <td>This factor determines how much the width of a cluster increases in pixels per added node.</td>
  1689. </tr>
  1690. <tr>
  1691. <td>nodeScaling.height</td>
  1692. <td>Number</td>
  1693. <td>10</td>
  1694. <td>This factor determines how much the height of a cluster increases in pixels per added node.</td>
  1695. </tr>
  1696. <tr>
  1697. <td>nodeScaling.radius</td>
  1698. <td>Number</td>
  1699. <td>10</td>
  1700. <td>This factor determines how much the radius of a cluster increases in pixels per added node.</td>
  1701. </tr>
  1702. <tr>
  1703. <td>maxNodeSizeIncrements</td>
  1704. <td>Number</td>
  1705. <td>600</td>
  1706. <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>
  1707. </tr>
  1708. <tr>
  1709. <td>activeAreaBoxSize</td>
  1710. <td>Number</td>
  1711. <td>100</td>
  1712. <td>Imagine a square with an edge length of <code>activeAreaBoxSize</code> pixels around your cursor.
  1713. If a cluster is in this box as you zoom in, the cluster can be opened in a seperate sector.
  1714. This is regardless of the zoom level.</td>
  1715. </tr>
  1716. <tr>
  1717. <td>clusterLevelDifference</td>
  1718. <td>Number</td>
  1719. <td>2</td>
  1720. <td>At every clustering session, Network will check if the difference between cluster levels is
  1721. acceptable. When a cluster is formed when zooming out, that is one cluster level.
  1722. If you zoom out further and it encompasses more nodes, that is another level. For example:
  1723. If the highest level of your network at any given time is 3, nodes that have not clustered or
  1724. have clustered only once will join their neighbour with the lowest cluster level.</td>
  1725. </tr>
  1726. </table>
  1727. <h3 id="Navigation_controls">Navigation controls</h3>
  1728. <p>
  1729. Network has a menu with navigation controls, which is disabled by default.
  1730. It can be configured with the following settings. To correctly display the navigation icons, the <b>vis.css</b> file must be included.
  1731. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1732. </p>
  1733. <pre class="prettyprint">
  1734. // use of navigation controls
  1735. var options = {
  1736. navigation: true
  1737. }
  1738. </pre>
  1739. <h3 id="Keyboard_navigation">Keyboard navigation</h3>
  1740. <p>
  1741. The network can be navigated using shortcut keys.
  1742. The default state for the keyboard navigation is <b>off</b>. The predefined keys can be found in the example <a href="../examples/network/20_navigation.html">20_navigation.html</a>.
  1743. </p>
  1744. <pre class="prettyprint">
  1745. // simple use of keyboard controls
  1746. var options = {
  1747. keyboard: true
  1748. }
  1749. // advanced configuration for keyboard controls
  1750. var options = {
  1751. keyboard: {
  1752. speed: {
  1753. x: 10,
  1754. y: 10,
  1755. zoom: 0.02
  1756. }
  1757. }
  1758. }
  1759. </pre>
  1760. <table>
  1761. <tr>
  1762. <th>Name</th>
  1763. <th>Type</th>
  1764. <th>Default</th>
  1765. <th>Description</th>
  1766. </tr>
  1767. <tr>
  1768. <td>speed.x</td>
  1769. <td>Number</td>
  1770. <td>10</td>
  1771. <td>This defines the speed of the camera movement in the x direction when using the keyboard navigation.
  1772. </td>
  1773. </tr>
  1774. <tr>
  1775. <td>speed.y</td>
  1776. <td>Number</td>
  1777. <td>10</td>
  1778. <td>This defines the speed of the camera movement in the y direction when using the keyboard navigation.</td>
  1779. </tr>
  1780. <tr>
  1781. <td>speed.zoom</td>
  1782. <td>Number</td>
  1783. <td>0.02</td>
  1784. <td>This defines the zoomspeed when using the keyboard navigation.</td>
  1785. </tr>
  1786. </table>
  1787. <h3 id="Hierarchical_layout">Hierarchical layout</h3>
  1788. <p>
  1789. The network 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.
  1790. 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
  1791. is shown in <a href="../examples/network/23_hierarchical_layout.html">example 23</a> and the user-defined method is shown in <a href="../examples/network/24_hierarchical_layout_userdefined.html">example 24</a>.
  1792. This layout method does not support smooth curves or clustering. It automatically turns these features off.
  1793. </p>
  1794. <pre class="prettyprint">
  1795. // simple use of the hierarchical layout
  1796. var options = {
  1797. hierarchicalLayout: true
  1798. }
  1799. // advanced configuration for hierarchical layout
  1800. var options = {
  1801. hierarchicalLayout: {
  1802. enabled:false,
  1803. levelSeparation: 150,
  1804. nodeSpacing: 100,
  1805. direction: "UD",
  1806. layout: "hubsize"
  1807. }
  1808. }
  1809. // partial configuration automatically sets enabled to true
  1810. var options = {
  1811. hierarchicalLayout: {
  1812. nodeSpacing: 100,
  1813. direction: "UD"
  1814. }
  1815. }
  1816. </pre>
  1817. <table>
  1818. <tr>
  1819. <th>Name</th>
  1820. <th>Type</th>
  1821. <th>Default</th>
  1822. <th>Description</th>
  1823. </tr>
  1824. <tr>
  1825. <td>enabled</td>
  1826. <td>Boolean</td>
  1827. <td>false</td>
  1828. <td>Enable or disable the hierarchical layout.
  1829. </td>
  1830. </tr>
  1831. <tr>
  1832. <td>levelSeparation</td>
  1833. <td>Number</td>
  1834. <td>150</td>
  1835. <td>This defines the space between levels (in the Y-direction, considering UP-DOWN direction).</td>
  1836. </tr>
  1837. <tr>
  1838. <td>nodeSpacing</td>
  1839. <td>Number</td>
  1840. <td>100</td>
  1841. <td>This defines the space between nodes in the same level (in the X-direction, considering UP-DOWN direction).
  1842. This is only relevant during the initial placing of nodes.</td>
  1843. </tr>
  1844. <tr>
  1845. <td>direction</td>
  1846. <td>String</td>
  1847. <td>UD</td>
  1848. <td>This defines the direction the network is drawn in. The supported directions are: Up-Down (UD), Down-Up (DU), Left-Right (LR) and Right-Left (RL).
  1849. These need to be supplied by the acronyms in parentheses.</td>
  1850. </tr>
  1851. <tr>
  1852. <td>layout</td>
  1853. <td>String</td>
  1854. <td>hubsize</td>
  1855. <td>This defines the way the nodes are distributed. Available options are <code>hubsize</code> and <code>direction</code>. The default value is hubsize, meaning the node with the most edges connected to it (largest hub) is on top.
  1856. Alternatively, direction arranges the nodes based on the direction of the edges. See <a href="../examples/network/32_hierarchicaLayoutMethods.html">example 32</a> for more information.</td>
  1857. </tr>
  1858. </table>
  1859. <h3 id="Localization">Localization</h3>
  1860. <p>
  1861. When using vis.js in other languages, one can use the localization option to get a localized data manipulation interface.
  1862. </p>
  1863. <table>
  1864. <tr>
  1865. <th>Name</th>
  1866. <th>Type</th>
  1867. <th>Default</th>
  1868. <th>Description</th>
  1869. </tr>
  1870. <tr>
  1871. <td>locale</td>
  1872. <td>String</td>
  1873. <td>none</td>
  1874. <td>Select a locale for the Network.</td>
  1875. </tr>
  1876. <tr>
  1877. <td>locales</td>
  1878. <td>Object</td>
  1879. <td>none</td>
  1880. <td>A map with i18n locales.</td>
  1881. </tr>
  1882. </table>
  1883. <p>
  1884. To set a locale for the Network, specify the option <code>locale</code>:
  1885. </p>
  1886. <pre class="prettyprint lang-js">var options = {
  1887. locale: 'nl'
  1888. };
  1889. </pre>
  1890. <h4>Create a new locale</h4>
  1891. To load a locale into the Timeline not supported by default, one can add a new locale to the option <code>locales</code>:
  1892. <pre class="prettyprint lang-js">var options = {
  1893. locales: {
  1894. // create a new locale (text strings should be replaced with localized strings)
  1895. mylocale: {
  1896. edit: 'Edit',
  1897. del: 'Delete selected',
  1898. back: 'Back',
  1899. addNode: 'Add Node',
  1900. addEdge: 'Add Edge',
  1901. editNode: 'Edit Node',
  1902. editEdge: 'Edit Edge',
  1903. addDescription: 'Click in an empty space to place a new node.',
  1904. edgeDescription: 'Click on a node and drag the edge to another node to connect them.',
  1905. editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.',
  1906. createEdgeError: 'Cannot link edges to a cluster.',
  1907. deleteClusterError: 'Clusters cannot be deleted.'
  1908. }
  1909. },
  1910. // use the new locale
  1911. locale: 'mylocale'
  1912. };
  1913. </pre>
  1914. <h4 id="available-locales">Available locales</h4>
  1915. <p>
  1916. Network comes with support for the following locales:
  1917. </p>
  1918. <table>
  1919. <tr><th>Language</th><th>Code</th></tr>
  1920. <tr>
  1921. <td>English</td>
  1922. <td>
  1923. <code>en</code><br>
  1924. <code>en_EN</code><br>
  1925. <code>en_US</code>
  1926. </td>
  1927. </tr>
  1928. <tr>
  1929. <td>Dutch</td>
  1930. <td>
  1931. <code>nl</code><br>
  1932. <code>nl_NL</code><br>
  1933. <code>nl_BE</code>
  1934. </td>
  1935. </tr>
  1936. </table>
  1937. <h3 id="Tooltips">Tooltips</h3>
  1938. <p>
  1939. The behaviour and style of the tooltips used to display node and edge title attributes can be customized.
  1940. </p>
  1941. <pre class="prettyprint">
  1942. // tooltip behaviour and style options
  1943. var options = {
  1944. tooltip: {
  1945. delay: 300,
  1946. fontColor: "black",
  1947. fontSize: 14, // px
  1948. fontFace: "verdana",
  1949. color: {
  1950. border: "#666",
  1951. background: "#FFFFC6"
  1952. }
  1953. }
  1954. }
  1955. </pre>
  1956. <table>
  1957. <tr>
  1958. <th>Name</th>
  1959. <th>Type</th>
  1960. <th>Default</th>
  1961. <th>Description</th>
  1962. </tr>
  1963. <tr>
  1964. <td>delay</td>
  1965. <td>Number</td>
  1966. <td>300</td>
  1967. <td>Time in milliseconds a user must hover over a node or edge before a tooltip appears.</td>
  1968. </tr>
  1969. <tr>
  1970. <td>fontColor</td>
  1971. <td>String</td>
  1972. <td>"black"</td>
  1973. <td>Default color for tooltip text.</td>
  1974. </tr>
  1975. <tr>
  1976. <td>fontSize</td>
  1977. <td>Number</td>
  1978. <td>14</td>
  1979. <td>Size in pixels of tooltip text.</td>
  1980. </tr>
  1981. <tr>
  1982. <td>fontFace</td>
  1983. <td>String</td>
  1984. <td>"verdana"</td>
  1985. <td>Font family to used for tooltip text.</td>
  1986. </tr>
  1987. <tr>
  1988. <td>color.background</td>
  1989. <td>String</td>
  1990. <td>"#FFFFC6"</td>
  1991. <td>Background color for the node.</td>
  1992. </tr>
  1993. <tr>
  1994. <td>color.border</td>
  1995. <td>String</td>
  1996. <td>"#666"</td>
  1997. <td>Border color for the node.</td>
  1998. </tr>
  1999. </table>
  2000. <h2 id="Methods">Methods</h2>
  2001. <p>
  2002. Network supports the following methods.
  2003. </p>
  2004. <table>
  2005. <tr>
  2006. <th>Method</th>
  2007. <th>Return Type</th>
  2008. <th>Description</th>
  2009. </tr>
  2010. <tr>
  2011. <td>getScale()</td>
  2012. <td>Number</td>
  2013. <td>Returns the scale of the network. This can be for animation. This scale is like a percentage, 1.0 = 100%.
  2014. Zooming in is > 1.0, zooming out is < 0. Scale cannot be smaller or equal to 0.
  2015. </td>
  2016. </tr>
  2017. <tr>
  2018. <td>getCenterCoordinates()</td>
  2019. <td>Number</td>
  2020. <td>Returns the x and y coodinates of the center of the screen (in canvas space).
  2021. </td>
  2022. </tr>
  2023. <tr>
  2024. <td>getBoundingBox()</td>
  2025. <td>Object</td>
  2026. <td>Returns a bounding box for the node including label in the format: {top:Number,left:Number,right:Number,bottom:Number}. These values are in canvas space.
  2027. </td>
  2028. </tr>
  2029. <tr>
  2030. <td>getSelection()</td>
  2031. <td>Array of ids</td>
  2032. <td>Returns an array with the ids of the selected nodes.
  2033. Returns an empty array if no nodes are selected.
  2034. The selections are not ordered.
  2035. </td>
  2036. </tr>
  2037. <tr>
  2038. <td>focusOnNode(nodeId, [options])</td>
  2039. <td>none</td>
  2040. <td>This function will move the view to center on the specified node. An optional options object can submitted where you can define the animation properties. <br />
  2041. The options that can be defined are:<br />
  2042. <b><code>scale:Number</code></b><br /> - to zoom to that scale,<br />
  2043. <b><code>offset:{x:Number, y:Number}</code></b><br /> - to offset the position from the center of the canvas (in pixels),<br />
  2044. <b><code>locked: boolean</code></b><br /> - if true, the view remains locked on this node until either another focusOnNode, moveTo, releaseNode or drag is done <br />
  2045. <b><code>animation: Object || Boolean</code></b><br /> - to define the specifics of the animation. True is animated with default settings, false is not animated.<br />
  2046. <br />
  2047. The animation object can consist of:<br />
  2048. <b><code>duration: Number</code></b><br /> - the duration of the animation in milliseconds,<br />
  2049. <b><code>easingFunction: String</code></b><br /> - the easing function of the animation, available are:<br />
  2050. <code>linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic,
  2051. easeInQuart, easeOutQuart, easeInOutQuart,
  2052. easeInQuint, easeOutQuint, easeInOutQuint </code> <br /><br />
  2053. </td>
  2054. </tr>
  2055. <tr>
  2056. <td>releaseNode()</td>
  2057. <td>none</td>
  2058. <td>When locked on to a node, this function releases it again. If the view is not locked onto a node due to the focusOnNode locked option, nothing happens.
  2059. </td>
  2060. </tr>
  2061. <tr>
  2062. <td>DOMtoCanvas(pos)</td>
  2063. <td>object</td>
  2064. <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 network container.
  2065. </td>
  2066. </tr>
  2067. <tr>
  2068. <td>canvasToDOM(pos)</td>
  2069. <td>object</td>
  2070. <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 network container.
  2071. </td>
  2072. </tr>
  2073. <tr>
  2074. <td>moveTo(options)</td>
  2075. <td>object</td>
  2076. <td>This function allows you to programmatically move the view. The options that can be defined are:<br />
  2077. <b><code>position:{x:Number, y:Number}</code></b><br /> - to move to that position (in canvas units), <br />
  2078. <b><code>scale:Number</code></b><br /> - to zoom to that scale,<br />
  2079. <b><code>offset:{x:Number, y:Number}</code></b><br /> - to offset the position from the center of the canvas (in DOM units),<br />
  2080. <b><code>animation: Object || Boolean</code></b><br /> - to define the specifics of the animation.<br />
  2081. <br />
  2082. The animation object can consist of:<br />
  2083. <b><code>duration: Number</code></b><br /> - the duration of the animation in milliseconds,<br />
  2084. <b><code>easingFunction: String</code></b><br /> - the easing function of the animation, available are:<br />
  2085. <code>linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic,
  2086. easeInQuart, easeOutQuart, easeInOutQuart,
  2087. easeInQuint, easeOutQuint, easeInOutQuint </code> <br /><br />
  2088. <i>You will have to define at least a scale or a position. Otherwise, there is nothing to move to.</i>
  2089. </td>
  2090. </tr>
  2091. <tr>
  2092. <td>on(event, callback)</td>
  2093. <td>none</td>
  2094. <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>
  2095. </tr>
  2096. <tr>
  2097. <td>off(event, callback)</td>
  2098. <td>none</td>
  2099. <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>
  2100. </tr>
  2101. <tr>
  2102. <td>destroy()</td>
  2103. <td>none</td>
  2104. <td>Remove all bindings and clean up after the Network.</td>
  2105. </tr>
  2106. <tr>
  2107. <td>redraw()</td>
  2108. <td>none</td>
  2109. <td>Redraw the network. Useful when the layout of the webpage changed.</td>
  2110. </tr>
  2111. <tr>
  2112. <td>setData(data,[disableStart])</td>
  2113. <td>none</td>
  2114. <td>Loads data. Parameter <code>data</code> is an object containing
  2115. nodes, edges, and options. Parameters nodes, edges are an Array.
  2116. Options is a name-value map and is optional. Parameter <code>disableStart</code> is
  2117. an optional Boolean and can disable the start of the simulation that would begin at the end
  2118. of this function by default.
  2119. </td>
  2120. </tr>
  2121. <tr>
  2122. <td>setOptions(options)</td>
  2123. <td>none</td>
  2124. <td>Set options for the network. The available options are described in
  2125. the section <a href="#Configuration_options">Configuration Options</a>.
  2126. </td>
  2127. </tr>
  2128. <tr>
  2129. <td>selectNodes(selection, [highlightEdges])</td>
  2130. <td>none</td>
  2131. <td>Select nodes.
  2132. <code>selection</code> is an array with ids of nodes to be selected.
  2133. The array <code>selection</code> can contain zero or multiple ids.
  2134. Example usage: <code>network.selectNodes([3, 5]);</code> will select
  2135. nodes with id 3 and 5. The highlisghEdges boolean can be used to automatically select the edges connected to the node.
  2136. </td>
  2137. </tr>
  2138. <tr>
  2139. <td>selectEdges(selection)</td>
  2140. <td>none</td>
  2141. <td>Select Edges.
  2142. <code>selection</code> is an array with ids of edges to be selected.
  2143. The array <code>selection</code> can contain zero or multiple ids.
  2144. Example usage: <code>network.selectEdges([3, 5]);</code> will select
  2145. edges with id 3 and 5.
  2146. </td>
  2147. </tr>
  2148. <tr>
  2149. <td>setSize(width, height)</td>
  2150. <td>none</td>
  2151. <td>Parameters <code>width</code> and <code>height</code> are strings,
  2152. containing a new size for the visualization. Size can be provided in pixels
  2153. or in percentages.</td>
  2154. </tr>
  2155. <tr>
  2156. <td>getPositions([ids])</td>
  2157. <td>Object</td>
  2158. <td>This will return an object of all nodes' positions. Data can be accessed with object[nodeId].x and .y. You can optionally supply an id as string or number or an array of ids. If no id or array of ids have been supplied, all positions are returned.
  2159. </td>
  2160. </tr>
  2161. <tr>
  2162. <td>storePositions()</td>
  2163. <td>none</td>
  2164. <td>When using the vis.DataSet to load your nodes into the network, this method will put the X and Y positions of all nodes into that dataset. It will also include allowedToMoveX and allowedToMoveY with the correct values.
  2165. If you're loading your nodes from a database and have this dynamically coupled with the DataSet, you can use this
  2166. to stablize your network once, then save the positions in that database through the DataSet so the next time you load the nodes, stabilization will be near instantaneous.
  2167. If the nodes are still moving and you're using dynamic smooth edges (which is on by default), you can use the option freezeForStabilization to improve initialization time.
  2168. <br><br><i><code>NOTE:</code>This method does not work with the hierarchical layout because the hierarchical algorithm is assigning X Y positions on load, regardless of the ones you supply it with.</i>
  2169. </td>
  2170. </tr>
  2171. <tr>
  2172. <td>zoomExtent([options])</td>
  2173. <td>none</td>
  2174. <td>Scales the network so all the nodes are in center view. Optionally you can supply options for animation. These
  2175. options can just be a boolean. When true, the zoom is animated, when false there is no animation.
  2176. Alternatively, you can supply an object.
  2177. <br /><br /> The object can consist of:<br />
  2178. <b><code>duration: Number</code></b><br /> - the duration of the animation in milliseconds,<br />
  2179. <b><code>easingFunction: String</code></b><br /> - the easing function of the animation, available are:<br />
  2180. <code>linear, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic,
  2181. easeInQuart, easeOutQuart, easeInOutQuart,
  2182. easeInQuint, easeOutQuint, easeInOutQuint </code>
  2183. </td>
  2184. </tr>
  2185. </table>
  2186. <h2 id="Events">Events</h2>
  2187. <p>
  2188. Network fires events after one or multiple nodes are selected or deselected.
  2189. The event can be catched by creating a listener.
  2190. </p>
  2191. <p>
  2192. Here an example on how to catch a <code>select</code> event.
  2193. </p>
  2194. <pre class="prettyprint lang-js">
  2195. network.on('select', function (properties) {
  2196. alert('selected nodes: ' + properties.nodes);
  2197. });
  2198. </pre>
  2199. <p>
  2200. A listener can be removed via the function <code>off</code>:
  2201. </p>
  2202. <pre class="prettyprint lang-js">
  2203. function onSelect (properties) {
  2204. alert('selected nodes: ' + properties.nodes);
  2205. }
  2206. // add event listener
  2207. network.on('select', onSelect);
  2208. // do stuff...
  2209. // remove event listener
  2210. network.off('select', onSelect);
  2211. </pre>
  2212. <p>
  2213. The following events are available.
  2214. </p>
  2215. <table>
  2216. <tr>
  2217. <th>name</th>
  2218. <th>Description</th>
  2219. <th>Properties</th>
  2220. </tr>
  2221. <tr>
  2222. <td>animationFinished</td>
  2223. <td>Fired after an animation is finished.
  2224. </td>
  2225. <td>
  2226. none
  2227. </td>
  2228. </tr>
  2229. <tr>
  2230. <td>select</td>
  2231. <td>Fired after the user selects or deselects a node by clicking it.
  2232. Not fired when the method <code>setSelection</code>is executed.
  2233. </td>
  2234. <td>
  2235. <ul>
  2236. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  2237. <li><code>edges</code>: an array with the ids of the selected edges</li>
  2238. </ul>
  2239. </td>
  2240. </tr>
  2241. <tr>
  2242. <td>click</td>
  2243. <td>Fired after the user clicks or taps on a touchscreen.</td>
  2244. <td>
  2245. <ul>
  2246. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  2247. <li><code>edges</code>: an array with the ids of the selected edges</li>
  2248. <li><code>pointer.DOM</code>:object containing XY coordinates in the DOM</li>
  2249. <li><code>pointer.canvas</code>:object containing XY coordinates in the canvas</li>
  2250. </ul>
  2251. </td>
  2252. </tr>
  2253. <tr>
  2254. <td>doubleClick</td>
  2255. <td>Fired after the user double clicks or double taps on a touchscreen.</td>
  2256. <td>
  2257. <ul>
  2258. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  2259. <li><code>edges</code>: an array with the ids of the selected edges</li>
  2260. <li><code>pointer.DOM</code>:object containing XY coordinates in the DOM</li>
  2261. <li><code>pointer.canvas</code>:object containing XY coordinates in the canvas</li>
  2262. </ul>
  2263. </td>
  2264. </tr>
  2265. <tr>
  2266. <tr>
  2267. <td>hoverNode</td>
  2268. <td>Fired when the mouse is moved over a node (assuming the hover option is enabled).</td>
  2269. <td>
  2270. <ul>
  2271. <li><code>node</code>: an object with the id of the hovered node.</li>
  2272. </ul>
  2273. </td>
  2274. </tr>
  2275. <tr>
  2276. <tr>
  2277. <td>blurNode</td>
  2278. <td>Fired when the mouse is moved off a node (assuming the hover option is enabled).</td>
  2279. <td>
  2280. <ul>
  2281. <li><code>node</code>: an object with the id of the hovered node.</li>
  2282. </ul>
  2283. </td>
  2284. </tr>
  2285. <tr>
  2286. <td>resize</td>
  2287. <td>Fired when the size of the canvas has been resized, either by a redraw call when the container div has changed in size, a setSize() call with new values or a setOptions() with new width and/or height values.</td>
  2288. <td>
  2289. <ul>
  2290. <li><code>width</code>: the new width of the canvas</li>
  2291. <li><code>height</code>: the new height of the canvas</li>
  2292. <li><code>oldWidth</code>: the old width of the canvas</li>
  2293. <li><code>oldHeight</code>: the old height of the canvas</li>
  2294. </ul>
  2295. </td>
  2296. </tr>
  2297. <tr>
  2298. <td>dragStart</td>
  2299. <td>Fired when a node is being dragged.</td>
  2300. <td>
  2301. <ul>
  2302. <li><code>nodeIds</code>: Array of ids of the nodes that are being dragged</li>
  2303. </ul>
  2304. </td>
  2305. </tr>
  2306. <tr>
  2307. <td>dragEnd</td>
  2308. <td>Fired when the dragging of a node(s) has ended.</td>
  2309. <td>
  2310. <ul>
  2311. <li><code>nodeIds</code>: Array of ids of the nodes that were being dragged</li>
  2312. </ul>
  2313. </td>
  2314. </tr>
  2315. <tr>
  2316. <td>startStabilization</td>
  2317. <td>Fired once when the network starts the physics calculation. This ends with the stabilized event.
  2318. <td>
  2319. none
  2320. </td>
  2321. </tr>
  2322. <tr>
  2323. <td>stabilized</td>
  2324. <td>Fired every time the network has been stabilized. This event can be used to trigger the .storePositions() function after stabilization. Fired with an object having the following properties:</td>
  2325. <td>
  2326. <ul>
  2327. <li><code>iterations</code>: number of iterations used to stabilize</li>
  2328. </ul>
  2329. </td>
  2330. </tr>
  2331. <tr>
  2332. <td>viewChanged</td>
  2333. <td>Fired when the view has changed. This is when the network has moved or zoomed.</td>
  2334. <td>
  2335. none
  2336. </td>
  2337. </tr>
  2338. <tr>
  2339. <td>zoom</td>
  2340. <td>Fired when the network has zoomed. This event can be used to trigger the .storePositions() function after stabilization.</td>
  2341. <td>
  2342. <ul>
  2343. <li><code>direction: </code> "+" or "-" </li>
  2344. </ul>
  2345. </td>
  2346. </tr>
  2347. </table>
  2348. <h2 id="Data_policy">Data policy</h2>
  2349. <p>
  2350. All code and data is processed and rendered in the browser.
  2351. No data is sent to any server.
  2352. </p>
  2353. </div>
  2354. </body>
  2355. </html>