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.

2552 lines
84 KiB

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