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.

2456 lines
78 KiB

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