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.

2550 lines
81 KiB

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