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.

2219 lines
69 KiB

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