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.

2205 lines
69 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | 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><a href="#Navigation_controls">navigation</a></td>
  699. <td>Object</td>
  700. <td>none</td>
  701. <td>
  702. Configuration options for the navigation controls. See section <a href="#Navigation_controls">Navigation controls</a> for an overview of the available options.
  703. </td>
  704. </tr>
  705. <tr>
  706. <td><a href="#Nodes_configuration">nodes</a></td>
  707. <td>Object</td>
  708. <td>none</td>
  709. <td>
  710. Configuration options applied to all nodes. See section <a href="#Nodes_configuration">Nodes configuration</a> for an overview of the available options.
  711. </td>
  712. </tr>
  713. <tr>
  714. <td>smoothCurves</td>
  715. <td>Boolean</td>
  716. <td>true</td>
  717. <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>
  718. </tr>
  719. <tr>
  720. <td>selectable</td>
  721. <td>Boolean</td>
  722. <td>true</td>
  723. <td>If true, nodes in the graph can be selected by clicking them.
  724. Long press can be used to select multiple nodes.</td>
  725. </tr>
  726. <tr>
  727. <td>stabilize</td>
  728. <td>Boolean</td>
  729. <td>true</td>
  730. <td>If true, the graph is stabilized before displaying it. If false,
  731. the nodes move to a stabe position visibly in an animated way.</td>
  732. </tr>
  733. <tr>
  734. <td>stabilizationIterations</td>
  735. <td>Number</td>
  736. <td>1000</td>
  737. <td>If stabilize is set to true, this number is the (maximum) amount of physics steps the stabilization process takes
  738. 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>
  739. </tr>
  740. <tr>
  741. <td>width</td>
  742. <td>String</td>
  743. <td>"400px"</td>
  744. <td>The width of the graph in pixels or as a percentage.</td>
  745. </tr>
  746. </table>
  747. <br>
  748. <h3 id="Nodes_configuration">Nodes configuration</h3>
  749. <p>
  750. 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.
  751. </p>
  752. <p>
  753. For example to give the nodes a custom color, shape, and size:
  754. </p>
  755. <pre class="prettyprint lang-js">
  756. var options = {
  757. // ...
  758. nodes: {
  759. color: {
  760. background: 'white',
  761. border: 'red',
  762. highlight: {
  763. background: 'pink',
  764. border: 'red'
  765. }
  766. },
  767. shape: 'star',
  768. radius: 24
  769. }
  770. };
  771. </pre>
  772. <p>
  773. The following options are available for nodes. These options must be created
  774. inside an object <code>nodes</code> in the graphs options object.</p>
  775. <table>
  776. <tr>
  777. <td>color</td>
  778. <td>String | Object</td>
  779. <td>Object</td>
  780. <td>Default color of the nodes. When color is a string, the color is applied
  781. to both background as well as the border of the node.</td>
  782. </tr>
  783. <tr>
  784. <td>color.background</td>
  785. <td>String</td>
  786. <td>"#97C2FC"</td>
  787. <td>Default background color of the nodes</td>
  788. </tr>
  789. <tr>
  790. <td>color.border</td>
  791. <td>String</td>
  792. <td>"#2B7CE9"</td>
  793. <td>Default border color of the nodes</td>
  794. </tr>
  795. <tr>
  796. <td>color.highlight</td>
  797. <td>String | Object</td>
  798. <td>Object</td>
  799. <td>Default color of the node when the node is selected. In case of a string, the color is applied to
  800. both border and background of the node.</td>
  801. </tr>
  802. <tr>
  803. <td>color.highlight.background</td>
  804. <td>String</td>
  805. <td>"#D2E5FF"</td>
  806. <td>Default background color of the node when selected.</td>
  807. </tr>
  808. <tr>
  809. <td>color.highlight.border</td>
  810. <td>String</td>
  811. <td>"#2B7CE9"</td>
  812. <td>Default border color of the node when selected.</td>
  813. </tr>
  814. <tr>
  815. <td>allowedToMoveX</td>
  816. <td>Boolean</td>
  817. <td>false</td>
  818. <td>If allowedToMoveX is false, then the node will not move from its supplied position.
  819. If an X position has been supplied, it is fixed in the X-direction.
  820. If no X value has been supplied, this argument will not do anything.</td>
  821. </tr>
  822. <tr>
  823. <td>allowedToMoveY</td>
  824. <td>Boolean</td>
  825. <td>false</td>
  826. <td>If allowedToMoveY is false, then the node will not move from its supplied position.
  827. If an Y position has been supplied, it is fixed in the Y-direction.
  828. If no Y value has been supplied, this argument will not do anything.</td>
  829. </tr>
  830. <tr>
  831. <td>fontColor</td>
  832. <td>String</td>
  833. <td>"black"</td>
  834. <td>Default font color for the text label in the nodes.</td>
  835. </tr>
  836. <tr>
  837. <td>fontFace</td>
  838. <td>String</td>
  839. <td>"sans"</td>
  840. <td>Default font face for the text label in the nodes, for example "verdana" or "arial".</td>
  841. </tr>
  842. <tr>
  843. <td>fontSize</td>
  844. <td>Number</td>
  845. <td>14</td>
  846. <td>Default font size in pixels for the text label in the nodes.</td>
  847. </tr>
  848. <tr>
  849. <td>group</td>
  850. <td>String</td>
  851. <td>none</td>
  852. <td>Default group for the nodes.</td>
  853. </tr>
  854. <tr>
  855. <td>image</td>
  856. <td>String</td>
  857. <td>none</td>
  858. <td>Default image url for the nodes. only applicable to shape <code>image</code>.</td>
  859. </tr>
  860. <tr>
  861. <td>mass</td>
  862. <td>number</td>
  863. <td>1</td>
  864. <td>When using the Barnes Hut simulation method (which is selected by default),
  865. the mass of a node determines the gravitational repulsion during the simulation. Higher mass will push other nodes further away.</td>
  866. </tr>
  867. <tr>
  868. <td>level</td>
  869. <td>number</td>
  870. <td>-1</td>
  871. <td>This level is used in the hierarchical layout. If this is not selected, the level does not do anything.</td>
  872. </tr>
  873. <tr>
  874. <td>widthMin</td>
  875. <td>Number</td>
  876. <td>16</td>
  877. <td>The minimum width for a scaled image. Only applicable to shape <code>image</code>.</td>
  878. </tr>
  879. <tr>
  880. <td>widthMax</td>
  881. <td>Number</td>
  882. <td>64</td>
  883. <td>The maximum width for a scaled image. Only applicable to shape <code>image</code>.</td>
  884. </tr>
  885. <tr>
  886. <td>shape</td>
  887. <td>String</td>
  888. <td>"ellipse"</td>
  889. <td>The default shape for all nodes.
  890. Choose from
  891. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  892. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  893. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  894. This shape can be overridden by a group shape, or by a shape of an individual node.</td>
  895. </tr>
  896. <tr>
  897. <td>radius</td>
  898. <td>Number</td>
  899. <td>5</td>
  900. <td>The default radius for a node. Only applicable to shapes <code>dot</code>,
  901. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  902. </tr>
  903. <tr>
  904. <td>radiusMin</td>
  905. <td>Number</td>
  906. <td>5</td>
  907. <td>The minimum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  908. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  909. </tr>
  910. <tr>
  911. <td>radiusMax</td>
  912. <td>Number</td>
  913. <td>20</td>
  914. <td>The maximum radius for a scaled node. Only applicable to shapes <code>dot</code>,
  915. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.</td>
  916. </tr>
  917. </table>
  918. <h3 id="Edges_configuration">Edges configuration</h3>
  919. <p>
  920. 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.
  921. </p>
  922. <p>
  923. For example to set the width of all edges to 2 pixels and give them a red color:
  924. </p>
  925. <pre class="prettyprint lang-js">
  926. var options = {
  927. // ...
  928. edges: {
  929. color: 'red',
  930. width: 2
  931. }
  932. };
  933. </pre>
  934. <p>
  935. The following options are available for edges. These options must be created
  936. inside an object <code>edges</code> in the graphs options object.
  937. </p>
  938. <table>
  939. <tr>
  940. <th>Name</th>
  941. <th>Type</th>
  942. <th>Default</th>
  943. <th>Description</th>
  944. </tr>
  945. <tr>
  946. <td>arrowScaleFactor</td>
  947. <td>Number</td>
  948. <td>1</td>
  949. <td>If you are using arrows, this will scale the arrow. Values < 1 give smaller arrows, > 1 larger arrows. Default: 1.</td>
  950. </tr>
  951. <tr>
  952. <td>color</td>
  953. <td>String | Object</td>
  954. <td>Object</td>
  955. <td>Colors of the edge. This object contains both colors for the selected and unselected state.</td>
  956. </tr>
  957. <tr>
  958. <td>color.color</td>
  959. <td>String</td>
  960. <td>"#848484"</td>
  961. <td>Color of the edge when not selected.</td>
  962. </tr>
  963. <tr>
  964. <td>color.highlight</td>
  965. <td>String</td>
  966. <td>"#848484"</td>
  967. <td>Color of the edge when selected.</td>
  968. </tr>
  969. <tr>
  970. <td>dash</td>
  971. <td>Object</td>
  972. <td>Object</td>
  973. <td>
  974. Object containing default properties for dashed lines.
  975. Available properties: <code>length</code>, <code>gap</code>,
  976. <code>altLength</code>.
  977. </td>
  978. </tr>
  979. <tr>
  980. <td>dash.altLength</td>
  981. <td>number</td>
  982. <td>none</td>
  983. <td>Default length of the alternated dash in pixels on a dashed line.
  984. Specifying <code>dash.altLength</code> allows for creating
  985. a dashed line with a dash-dot style, for example when
  986. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  987. See also the option <code>dahs.length</code>.
  988. Only applicable when the line style is <code>dash-line</code>.</td>
  989. </tr>
  990. <tr>
  991. <td>dash.length</td>
  992. <td>number</td>
  993. <td>10</td>
  994. <td>Default length of a dash in pixels on a dashed line.
  995. Only applicable when the line style is <code>dash-line</code>.</td>
  996. </tr>
  997. <tr>
  998. <td>dash.gap</td>
  999. <td>number</td>
  1000. <td>5</td>
  1001. <td>Default length of a gap in pixels on a dashed line.
  1002. Only applicable when the line style is <code>dash-line</code>.</td>
  1003. </tr>
  1004. <tr>
  1005. <td>length</td>
  1006. <td>number</td>
  1007. <td>physics.[method].springLength</td>
  1008. <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>
  1009. </tr>
  1010. <tr>
  1011. <td>style</td>
  1012. <td>String</td>
  1013. <td>"line"</td>
  1014. <td>The default style of a edge.
  1015. Choose from <code>line</code> (default), <code>arrow</code>,
  1016. <code>arrow-center</code>, <code>dash-line</code>.</td>
  1017. </tr>
  1018. <tr>
  1019. <td>width</td>
  1020. <td>Number</td>
  1021. <td>1</td>
  1022. <td>The default width of a edge.</td>
  1023. </tr>
  1024. </table>
  1025. <h3 id="Groups_configuration">Groups configuration</h3>
  1026. <p>It is possible to specify custom styles for groups of nodes.
  1027. Each node having assigned to this group gets the specified style.
  1028. The options <code>groups</code> is an object containing one or multiple groups,
  1029. identified by a unique string, the groupname.
  1030. </p>
  1031. <p>
  1032. A group can have the following styles:
  1033. </p>
  1034. <pre class="prettyprint lang-js">
  1035. var options = {
  1036. // ...
  1037. groups: {
  1038. mygroup: {
  1039. shape: 'circle',
  1040. color: {
  1041. border: 'black',
  1042. background: 'white',
  1043. highlight: {
  1044. border: 'yellow',
  1045. background: 'orange'
  1046. }
  1047. }
  1048. fontColor: 'red',
  1049. fontSize: 18
  1050. }
  1051. // add more groups here
  1052. }
  1053. };
  1054. var nodes = [
  1055. {id: 1, label: 'Node 1'}, // will get the default style
  1056. {id: 2, label: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  1057. // ... more nodes
  1058. ];
  1059. </pre>
  1060. <p>The following styles are available for groups:</p>
  1061. <table>
  1062. <tr>
  1063. <th>Name</th>
  1064. <th>Type</th>
  1065. <th>Default</th>
  1066. <th>Description</th>
  1067. </tr>
  1068. <tr>
  1069. <td>color</td>
  1070. <td>String | Object</td>
  1071. <td>Object</td>
  1072. <td>Color of the node</td>
  1073. </tr>
  1074. <tr>
  1075. <td>color.border</td>
  1076. <td>String</td>
  1077. <td>"#2B7CE9"</td>
  1078. <td>Border color of the node</td>
  1079. </tr>
  1080. <tr>
  1081. <td>color.background</td>
  1082. <td>String</td>
  1083. <td>"#97C2FC"</td>
  1084. <td>Background color of the node</td>
  1085. </tr>
  1086. <tr>
  1087. <td>color.highlight</td>
  1088. <td>String | Object</td>
  1089. <td>"#D2E5FF"</td>
  1090. <td>Default color of the node when the node is selected. In case of a string, the color is applied to
  1091. both border and background of the node.</td>
  1092. </tr>
  1093. <tr>
  1094. <td>color.highlight.background</td>
  1095. <td>String</td>
  1096. <td>"#D2E5FF"</td>
  1097. <td>Background color of the node when selected.</td>
  1098. </tr>
  1099. <tr>
  1100. <td>color.highlight.border</td>
  1101. <td>String</td>
  1102. <td>"#D2E5FF"</td>
  1103. <td>Border color of the node when selected.</td>
  1104. </tr>
  1105. <tr>
  1106. <td>image</td>
  1107. <td>String</td>
  1108. <td>none</td>
  1109. <td>Default image for the nodes. Only applicable in combination with
  1110. shape <code>image</code>.</td>
  1111. </tr>
  1112. <tr>
  1113. <td>fontColor</td>
  1114. <td>String</td>
  1115. <td>"black"</td>
  1116. <td>Font color of the node.</td>
  1117. </tr>
  1118. <tr>
  1119. <td>fontFace</td>
  1120. <td>String</td>
  1121. <td>"sans"</td>
  1122. <td>Font name of the node, for example "verdana" or "arial".</td>
  1123. </tr>
  1124. <tr>
  1125. <td>fontSize</td>
  1126. <td>Number</td>
  1127. <td>14</td>
  1128. <td>Font size for the node in pixels.</td>
  1129. </tr>
  1130. <tr>
  1131. <td>shape</td>
  1132. <td>String</td>
  1133. <td>"ellipse"</td>
  1134. <td>Choose from
  1135. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  1136. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  1137. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  1138. In case of image, a property with name image must be provided, containing
  1139. image urls.</td>
  1140. </tr>
  1141. <tr>
  1142. <td>radius</td>
  1143. <td>Number</td>
  1144. <td>5</td>
  1145. <td>Default radius for the node. Only applicable in combination with
  1146. shapes <code>box</code> and <code>dot</code>.</td>
  1147. </tr>
  1148. </table>
  1149. <h3 id="Physics">Physics</h3>
  1150. <p>
  1151. The original simulation method was based on particel physics with a repulsion field (potential) around each node,
  1152. 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.
  1153. 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.
  1154. 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.
  1155. <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>
  1156. </p>
  1157. <pre class="prettyprint">
  1158. // These variables must be defined in an options object named physics.
  1159. // If a variable is not supplied, the default value is used.
  1160. var options = {
  1161. physics: {
  1162. barnesHut: {
  1163. enabled: true,
  1164. gravitationalConstant: -2000,
  1165. centralGravity: 0.1,
  1166. springLength: 95,
  1167. springConstant: 0.04,
  1168. damping: 0.09
  1169. },
  1170. repulsion: {
  1171. centralGravity: 0.1,
  1172. springLength: 50,
  1173. springConstant: 0.05,
  1174. nodeDistance: 100,
  1175. damping: 0.09
  1176. },
  1177. }
  1178. </pre>
  1179. <h5>barnesHut:</h5>
  1180. <table>
  1181. <tr>
  1182. <th>Name</th>
  1183. <th>Type</th>
  1184. <th>Default</th>
  1185. <th>Description</th>
  1186. </tr>
  1187. <tr>
  1188. <td>enabled</td>
  1189. <td>Boolean</td>
  1190. <td>true</td>
  1191. <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>
  1192. </tr>
  1193. <tr>
  1194. <td>gravitationalConstant</td>
  1195. <td>Number</td>
  1196. <td>-2000</td>
  1197. <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>
  1198. </tr>
  1199. <tr>
  1200. <td>centralGravity</td>
  1201. <td>Number</td>
  1202. <td>0.1</td>
  1203. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1204. </tr>
  1205. <tr>
  1206. <td>springLength</td>
  1207. <td>Number</td>
  1208. <td>95</td>
  1209. <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.
  1210. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1211. </tr>
  1212. <tr>
  1213. <td>springConstant</td>
  1214. <td>Number</td>
  1215. <td>0.04</td>
  1216. <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>
  1217. </tr>
  1218. <tr>
  1219. <td>damping</td>
  1220. <td>Number</td>
  1221. <td>0.09</td>
  1222. <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>
  1223. </tr>
  1224. </table>
  1225. <h5>repulsion:</h5>
  1226. <table>
  1227. <tr>
  1228. <th>Name</th>
  1229. <th>Type</th>
  1230. <th>Default</th>
  1231. <th>Description</th>
  1232. </tr>
  1233. <tr>
  1234. <td>centralGravity</td>
  1235. <td>Number</td>
  1236. <td>0.1</td>
  1237. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1238. </tr>
  1239. <tr>
  1240. <td>springLength</td>
  1241. <td>Number</td>
  1242. <td>50</td>
  1243. <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.
  1244. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1245. </tr>
  1246. <tr>
  1247. <td>nodeDistance</td>
  1248. <td>Number</td>
  1249. <td>100</td>
  1250. <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>
  1251. </tr>
  1252. <tr>
  1253. <td>springConstant</td>
  1254. <td>Number</td>
  1255. <td>0.05</td>
  1256. <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>
  1257. </tr>
  1258. <tr>
  1259. <td>damping</td>
  1260. <td>Number</td>
  1261. <td>0.09</td>
  1262. <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>
  1263. </tr>
  1264. </table>
  1265. <h4 id="PhysicsConfiguration">Configuration:</h4>
  1266. 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
  1267. 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
  1268. settings you are happy with, you can supply them to graph using the physics options as described above.
  1269. 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.
  1270. <pre class="prettyprint">
  1271. var options = {
  1272. configurePhysics:true
  1273. }
  1274. </pre>
  1275. <h3 id="Data_manipulation">Data manipulation</h3>
  1276. <p>
  1277. 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.
  1278. 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
  1279. 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>,
  1280. 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.
  1281. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1282. </p>
  1283. <pre class="prettyprint">
  1284. // These variables must be defined in an options object named dataManipulation.
  1285. // If a variable is not supplied, the default value is used.
  1286. var options = {
  1287. dataManipulation: {
  1288. enabled: false,
  1289. initiallyVisible: false
  1290. }
  1291. }
  1292. // OR to just load the module with default values:
  1293. var options: {
  1294. dataManipulation: true
  1295. }
  1296. </pre>
  1297. <table>
  1298. <tr>
  1299. <th>Name</th>
  1300. <th>Type</th>
  1301. <th>Default</th>
  1302. <th>Description</th>
  1303. </tr>
  1304. <tr>
  1305. <td>enabled</td>
  1306. <td>Boolean</td>
  1307. <td>false</td>
  1308. <td>Enabling or disabling of the data manipulation toolbar. If it is initially hidden, an edit button appears in the top left corner.</td>
  1309. </tr>
  1310. <tr>
  1311. <td>initiallyVisible</td>
  1312. <td>Boolean</td>
  1313. <td>false</td>
  1314. <td>Initially hide or show the data manipulation toolbar.</td>
  1315. </tr>
  1316. </table>
  1317. <h4 id="Data_manipulation_custom">Data manipulation: custom functionality</h4>
  1318. <p>
  1319. 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.
  1320. If the callback is NOT called, nothing happens. <a href="../examples/graph/21_data_manipulation.html">Example 21</a> has two working examples
  1321. for the add and edit functions. The data the user is supplied with in these functions has been described in the code below.
  1322. 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
  1323. 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
  1324. requires the same data structure that is supplied to the user. <br /><br />
  1325. <b>If there is no injected function supplied for the edit operation, the button will not be shown in the toolbar.</b>
  1326. </p>
  1327. <pre class="prettyprint">
  1328. // If a variable is not supplied, the default value is used.
  1329. var options: {
  1330. dataManipulation: true,
  1331. onAdd: function(data,callback) {
  1332. /** data = {id: random unique id,
  1333. * label: new,
  1334. * x: x position of click (canvas space),
  1335. * y: y position of click (canvas space),
  1336. * allowedToMoveX: true,
  1337. * allowedToMoveY: true
  1338. * };
  1339. */
  1340. var newData = {..}; // alter the data as you want.
  1341. // all fields normally accepted by a node can be used.
  1342. callback(newData); // call the callback to add a node.
  1343. },
  1344. onEdit: function(data,callback) {
  1345. /** data = {id:...,
  1346. * label: ...,
  1347. * group: ...,
  1348. * shape: ...,
  1349. * color: {
  1350. * background:...,
  1351. * border:...,
  1352. * highlight: {
  1353. * background:...,
  1354. * border:...
  1355. * }
  1356. * }
  1357. * };
  1358. */
  1359. var newData = {..}; // alter the data as you want.
  1360. // all fields normally accepted by a node can be used.
  1361. callback(newData); // call the callback with the new data to edit the node.
  1362. }
  1363. onConnect: function(data,callback) {
  1364. // data = {from: nodeId1, to: nodeId2};
  1365. var newData = {..}; // check or alter data as you see fit.
  1366. callback(newData); // call the callback to connect the nodes.
  1367. },
  1368. onDelete: function(data,callback) {
  1369. // data = {nodes: [selectedNodeIds], edges: [selectedEdgeIds]};
  1370. var newData = {..}; // alter the data as you want.
  1371. // the same data structure is required.
  1372. callback(newData); // call the callback to delete the objects.
  1373. }
  1374. };
  1375. </pre>
  1376. <p>
  1377. 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.
  1378. 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.
  1379. An code snippet from example 21 is shown below.
  1380. </p>
  1381. <pre class="prettyprint">
  1382. graph.on("resize", function(params) {console.log(params.width,params.height)});
  1383. </pre>
  1384. <h3 id="Clustering">Clustering</h3>
  1385. <p>
  1386. The graph now supports dynamic clustering of nodes. This allows a user to view a very large dataset (> 50.000 nodes) without
  1387. sacrificing performance. When loading a large dataset, the nodes are clustered initially (this may take a small while) to have a
  1388. responsive visualization to work with. The clustering is both outside-in and inside-out. Outside-in means that nodes with only one
  1389. connection will be contained, or clustered, in the node it is connected to. Inside-out clustering first determines which nodes are hubs.
  1390. Hubs are defined as the nodes with the top 3% highest amount of connections (assuming normal distribution). These hubs then "grow", meaning
  1391. 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.
  1392. <br />
  1393. <br />
  1394. 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
  1395. to calculate the required forces. The contained nodes are removed from the global nodes index, greatly speeding up the system.
  1396. <br />
  1397. <br />
  1398. The clustering has the following user-configurable settings. The default values have been tested with the Graph examples and work well.
  1399. The default state for clustering is <b>off</b>.
  1400. </p>
  1401. <pre class="prettyprint">
  1402. // These variables must be defined in an options object named clustering.
  1403. // If a variable is not supplied, the default value is used.
  1404. var options = {
  1405. clustering: {
  1406. initialMaxNodes: 100,
  1407. clusterThreshold:500,
  1408. reduceToNodes:300,
  1409. chainThreshold: 0.4,
  1410. clusterEdgeThreshold: 20,
  1411. sectorThreshold: 100,
  1412. screenSizeThreshold: 0.2,
  1413. fontSizeMultiplier: 4.0,
  1414. maxFontSize: 1000,
  1415. forceAmplification: 0.1,
  1416. distanceAmplification: 0.1,
  1417. edgeGrowth: 20,
  1418. nodeScaling: {width: 1,
  1419. height: 1,
  1420. radius: 1},
  1421. maxNodeSizeIncrements: 600,
  1422. activeAreaBoxSize: 100,
  1423. clusterLevelDifference: 2
  1424. }
  1425. }
  1426. // OR to just load the module with default values:
  1427. var options: {
  1428. clustering: true
  1429. }
  1430. </pre>
  1431. <table>
  1432. <tr>
  1433. <th>Name</th>
  1434. <th>Type</th>
  1435. <th>Default</th>
  1436. <th>Description</th>
  1437. </tr>
  1438. <tr>
  1439. <td>initialMaxNodes</td>
  1440. <td>Number</td>
  1441. <td>100</td>
  1442. <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>
  1443. </tr>
  1444. <tr>
  1445. <td>clusterThreshold</td>
  1446. <td>Number</td>
  1447. <td>500</td>
  1448. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1449. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continuously fluid.</td>
  1450. </tr>
  1451. <tr>
  1452. <td>reduceToNodes</td>
  1453. <td>Number</td>
  1454. <td>300</td>
  1455. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1456. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  1457. </tr>
  1458. <tr>
  1459. <td>chainThreshold</td>
  1460. <td>Number</td>
  1461. <td>0.4</td>
  1462. <td>Because of the clustering methods used, long chains of nodes can be formed. To reduce these chains, this threshold is used.
  1463. 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).
  1464. If there are more, they are clustered together.</td>
  1465. </tr>
  1466. <tr>
  1467. <td>clusterEdgeThreshold</td>
  1468. <td>Number</td>
  1469. <td>20</td>
  1470. <td>This is the absolute edge length threshold in pixels. If the edge is smaller on screen (that means zooming out reduces this length)
  1471. the node will be clustered. This is triggered when zooming out.</td>
  1472. </tr>
  1473. <tr>
  1474. <td>sectorThreshold</td>
  1475. <td>Integer</td>
  1476. <td>50</td>
  1477. <td>If a cluster larger than <code>sectorThreshold</code> is opened, a seperate instance called a sector, will be created. All the simulation of
  1478. nodes outside of this instance will be paused. This is to maintain performance and clarity when examining large clusters.
  1479. 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>
  1480. </tr>
  1481. <tr>
  1482. <td>screenSizeThreshold</td>
  1483. <td>Number</td>
  1484. <td>0.2</td>
  1485. <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
  1486. 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
  1487. 20%, we collapse this sector.</td>
  1488. </tr>
  1489. <tr>
  1490. <td>fontSizeMultiplier</td>
  1491. <td>Number</td>
  1492. <td>4.0</td>
  1493. <td>This parameter denotes the increase in fontSize of the cluster when a single node is added to it.</td>
  1494. </tr>
  1495. <tr>
  1496. <td>maxFontSize</td>
  1497. <td>Number</td>
  1498. <td>1000</td>
  1499. <td>This parameter denotes the largest allowed font size. If the font becomes too large, some browsers experience problems displaying this.</td>
  1500. </tr>
  1501. <tr>
  1502. <td>forceAmplification</td>
  1503. <td>Number</td>
  1504. <td>0.6</td>
  1505. <td>This factor is used to calculate the increase of the repulsive force of a cluster. It is calculated by the following
  1506. formula: <code>repulsingForce *= 1 + (clusterSize * forceAmplification)</code>.</td>
  1507. </tr>
  1508. <tr>
  1509. <td>distanceAmplification</td>
  1510. <td>Number</td>
  1511. <td>0.2</td>
  1512. <td>This factor is used to calculate the increase in effective range of the repulsive force of the cluster.
  1513. A larger cluster has a longer range. It is calculated by the following
  1514. formula: <code>minDistance *= 1 + (clusterSize * distanceAmplification)</code>.</td>
  1515. </tr>
  1516. <tr>
  1517. <td>edgeGrowth</td>
  1518. <td>Number</td>
  1519. <td>20</td>
  1520. <td>This factor determines the elongation of edges connected to a cluster.</td>
  1521. </tr>
  1522. <tr>
  1523. <td>nodeScaling.width</td>
  1524. <td>Number</td>
  1525. <td>10</td>
  1526. <td>This factor determines how much the width of a cluster increases in pixels per added node.</td>
  1527. </tr>
  1528. <tr>
  1529. <td>nodeScaling.height</td>
  1530. <td>Number</td>
  1531. <td>10</td>
  1532. <td>This factor determines how much the height of a cluster increases in pixels per added node.</td>
  1533. </tr>
  1534. <tr>
  1535. <td>nodeScaling.radius</td>
  1536. <td>Number</td>
  1537. <td>10</td>
  1538. <td>This factor determines how much the radius of a cluster increases in pixels per added node.</td>
  1539. </tr>
  1540. <tr>
  1541. <td>maxNodeSizeIncrements</td>
  1542. <td>Number</td>
  1543. <td>600</td>
  1544. <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>
  1545. </tr>
  1546. <tr>
  1547. <td>activeAreaBoxSize</td>
  1548. <td>Number</td>
  1549. <td>100</td>
  1550. <td>Imagine a square with an edge length of <code>activeAreaBoxSize</code> pixels around your cursor.
  1551. If a cluster is in this box as you zoom in, the cluster can be opened in a seperate sector.
  1552. This is regardless of the zoom level.</td>
  1553. </tr>
  1554. <tr>
  1555. <td>clusterLevelDifference</td>
  1556. <td>Number</td>
  1557. <td>2</td>
  1558. <td>At every clustering session, Graph will check if the difference between cluster levels is
  1559. acceptable. When a cluster is formed when zooming out, that is one cluster level.
  1560. If you zoom out further and it encompasses more nodes, that is another level. For example:
  1561. If the highest level of your graph at any given time is 3, nodes that have not clustered or
  1562. have clustered only once will join their neighbour with the lowest cluster level.</td>
  1563. </tr>
  1564. </table>
  1565. <h3 id="Navigation_controls">Navigation controls</h3>
  1566. <p>
  1567. Graph has a menu with navigation controls, which is disabled by default.
  1568. It can be configured with the following settings. To correctly display the navigation icons, the <b>vis.css</b> file must be included.
  1569. The user is free to alter or overload the CSS classes but without them the navigation icons are not visible.
  1570. </p>
  1571. <pre class="prettyprint">
  1572. // use of navigation controls
  1573. var options: {
  1574. navigation: true
  1575. }
  1576. </pre>
  1577. <h3 id="Keyboard_navigation">Keyboard navigation</h3>
  1578. <p>
  1579. The graph can be navigated using shortcut keys.
  1580. 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>.
  1581. </p>
  1582. <pre class="prettyprint">
  1583. // simple use of keyboard controls
  1584. var options: {
  1585. keyboard: true
  1586. }
  1587. // advanced configuration for keyboard controls
  1588. var options: {
  1589. keyboard: {
  1590. speed: {
  1591. x: 10,
  1592. y: 10,
  1593. zoom: 0.02
  1594. }
  1595. }
  1596. }
  1597. </pre>
  1598. <table>
  1599. <tr>
  1600. <th>Name</th>
  1601. <th>Type</th>
  1602. <th>Default</th>
  1603. <th>Description</th>
  1604. </tr>
  1605. <tr>
  1606. <td>speed.x</td>
  1607. <td>Number</td>
  1608. <td>10</td>
  1609. <td>This defines the speed of the camera movement in the x direction when using the keyboard navigation.
  1610. </td>
  1611. </tr>
  1612. <tr>
  1613. <td>speed.y</td>
  1614. <td>Number</td>
  1615. <td>10</td>
  1616. <td>This defines the speed of the camera movement in the y direction when using the keyboard navigation.</td>
  1617. </tr>
  1618. <tr>
  1619. <td>speed.zoom</td>
  1620. <td>Number</td>
  1621. <td>0.02</td>
  1622. <td>This defines the zoomspeed when using the keyboard navigation.</td>
  1623. </tr>
  1624. </table>
  1625. <h3 id="Hierarchical_layout">Hierarchical layout</h3>
  1626. <p>
  1627. 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.
  1628. 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
  1629. 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>.
  1630. This layout method does not support smooth curves or clustering. It automatically turns these features off.
  1631. </p>
  1632. <pre class="prettyprint">
  1633. // simple use of the hierarchical layout
  1634. var options: {
  1635. hierarchicalLayout: true
  1636. }
  1637. // advanced configuration for hierarchical layout
  1638. var options: {
  1639. hierarchicalLayout: {
  1640. enabled:false,
  1641. levelSeparation: 150,
  1642. nodeSpacing: 100,
  1643. direction: "UD"
  1644. }
  1645. }
  1646. // partial configuration automatically sets enabled to true
  1647. var options: {
  1648. hierarchicalLayout: {
  1649. nodeSpacing: 100,
  1650. direction: "UD"
  1651. }
  1652. }
  1653. </pre>
  1654. <table>
  1655. <tr>
  1656. <th>Name</th>
  1657. <th>Type</th>
  1658. <th>Default</th>
  1659. <th>Description</th>
  1660. </tr>
  1661. <tr>
  1662. <td>enabled</td>
  1663. <td>Boolean</td>
  1664. <td>false</td>
  1665. <td>Enable or disable the hierarchical layout.
  1666. </td>
  1667. </tr>
  1668. <tr>
  1669. <td>levelSeparation</td>
  1670. <td>Number</td>
  1671. <td>150</td>
  1672. <td>This defines the space between levels (in the Y-direction, considering UP-DOWN direction).</td>
  1673. </tr>
  1674. <tr>
  1675. <td>nodeSpacing</td>
  1676. <td>Number</td>
  1677. <td>100</td>
  1678. <td>This defines the space between nodes in the same level (in the X-direction, considering UP-DOWN direction).
  1679. This is only relevant during the initial placing of nodes.</td>
  1680. </tr>
  1681. <tr>
  1682. <td>direction</td>
  1683. <td>String</td>
  1684. <td>UD</td>
  1685. <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).
  1686. These need to be supplied by the acronyms in parentheses.</td>
  1687. </tr>
  1688. </table>
  1689. <h3 id="Localization">Localization</h3>
  1690. <p>
  1691. When using vis.js in other languages, one can use the localization option to overwrite the labels used in the data manipulation interface.
  1692. </p>
  1693. <pre class="prettyprint">
  1694. var options: {
  1695. labels:{
  1696. add:"Add Node",
  1697. edit:"Edit",
  1698. link:"Add Link",
  1699. del:"Delete selected",
  1700. editNode:"Edit Node",
  1701. back:"Back",
  1702. addDescription:"Click in an empty space to place a new node.",
  1703. linkDescription:"Click on a node and drag the edge to another
  1704. node to connect them.",
  1705. addError:"The function for add does not support two arguments
  1706. (data,callback).",
  1707. linkError:"The function for connect does not support two arguments
  1708. (data,callback).",
  1709. editError:"The function for edit does not support two arguments
  1710. (data, callback).",
  1711. editBoundError:"No edit function has been bound to this button.",
  1712. deleteError:"The function for delete does not support two arguments
  1713. (data, callback).",
  1714. deleteClusterError:"Clusters cannot be deleted."
  1715. }
  1716. }
  1717. </pre>
  1718. <table>
  1719. <tr>
  1720. <th>Name</th>
  1721. <th>Type</th>
  1722. <th>Default</th>
  1723. <th>Description</th>
  1724. </tr>
  1725. <tr>
  1726. <td>labels</td>
  1727. <td>object</td>
  1728. <td>(shown above)</td>
  1729. <td>Overwrite one or all labels used in the datamanipulation interface with localized strings.
  1730. </td>
  1731. </tr>
  1732. </table>
  1733. <h3 id="Tooltips">Tooltips</h3>
  1734. <p>
  1735. The behaviour and style of the tooltips used to display node and edge title attributes can be customized.
  1736. </p>
  1737. <pre class="prettyprint">
  1738. // tooltip behaviour and style options
  1739. var options: {
  1740. tooltip: {
  1741. delay: 300,
  1742. fontColor: "black",
  1743. fontSize: 14, // px
  1744. fontFace: "verdana",
  1745. color: {
  1746. border: "#666",
  1747. background: "#FFFFC6"
  1748. }
  1749. }
  1750. }
  1751. </pre>
  1752. <table>
  1753. <tr>
  1754. <th>Name</th>
  1755. <th>Type</th>
  1756. <th>Default</th>
  1757. <th>Description</th>
  1758. </tr>
  1759. <tr>
  1760. <td>delay</td>
  1761. <td>Number</td>
  1762. <td>300</td>
  1763. <td>Time in milliseconds a user must hover over a node or edge before a tooltip appears.</td>
  1764. </tr>
  1765. <tr>
  1766. <td>fontColor</td>
  1767. <td>String</td>
  1768. <td>"black"</td>
  1769. <td>Default color for tooltip text.</td>
  1770. </tr>
  1771. <tr>
  1772. <td>fontSize</td>
  1773. <td>Number</td>
  1774. <td>14</td>
  1775. <td>Size in pixels of tooltip text.</td>
  1776. </tr>
  1777. <tr>
  1778. <td>fontFace</td>
  1779. <td>String</td>
  1780. <td>"verdana"</td>
  1781. <td>Font family to used for tooltip text.</td>
  1782. </tr>
  1783. <tr>
  1784. <td>color.background</td>
  1785. <td>String</td>
  1786. <td>"#FFFFC6"</td>
  1787. <td>Background color for the node.</td>
  1788. </tr>
  1789. <tr>
  1790. <td>color.border</td>
  1791. <td>String</td>
  1792. <td>"#666"</td>
  1793. <td>Border color for the node.</td>
  1794. </tr>
  1795. </table>
  1796. <h2 id="Methods">Methods</h2>
  1797. <p>
  1798. Graph supports the following methods.
  1799. </p>
  1800. <table>
  1801. <tr>
  1802. <th>Method</th>
  1803. <th>Return Type</th>
  1804. <th>Description</th>
  1805. </tr>
  1806. <tr>
  1807. <td>getSelection()</td>
  1808. <td>Array of ids</td>
  1809. <td>Returns an array with the ids of the selected nodes.
  1810. Returns an empty array if no nodes are selected.
  1811. The selections are not ordered.
  1812. </td>
  1813. </tr>
  1814. <tr>
  1815. <td>storePosition()</td>
  1816. <td>none</td>
  1817. <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.
  1818. 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.
  1819. </td>
  1820. </tr>
  1821. <tr>
  1822. <td>DOMtoCanvas(pos)</td>
  1823. <td>object</td>
  1824. <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.
  1825. </td>
  1826. </tr>
  1827. <tr>
  1828. <td>canvasToDOM(pos)</td>
  1829. <td>object</td>
  1830. <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.
  1831. </td>
  1832. </tr>
  1833. <tr>
  1834. <td>on(event, callback)</td>
  1835. <td>none</td>
  1836. <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>
  1837. </tr>
  1838. <tr>
  1839. <td>off(event, callback)</td>
  1840. <td>none</td>
  1841. <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>
  1842. </tr>
  1843. <tr>
  1844. <td>redraw()</td>
  1845. <td>none</td>
  1846. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  1847. </tr>
  1848. <tr>
  1849. <td>setData(data,[disableStart])</td>
  1850. <td>none</td>
  1851. <td>Loads data. Parameter <code>data</code> is an object containing
  1852. nodes, edges, and options. Parameters nodes, edges are an Array.
  1853. Options is a name-value map and is optional. Parameter <code>disableStart</code> is
  1854. an optional Boolean and can disable the start of the simulation that would begin at the end
  1855. of this function by default.
  1856. </td>
  1857. </tr>
  1858. <tr>
  1859. <td>setOptions(options,[initializeView])</td>
  1860. <td>none</td>
  1861. <td>Set options for the graph. The available options are described in
  1862. the section <a href="#Configuration_options">Configuration Options</a>. The <code>initializeView</code> boolean parameter is
  1863. optional and can be used to avoid the resetting of the view when loading the options.
  1864. This can be used when changing the options of an already initialized graph.
  1865. </td>
  1866. </tr>
  1867. <tr>
  1868. <td>setSelection(selection)</td>
  1869. <td>none</td>
  1870. <td>Select nodes.
  1871. <code>selection</code> is an array with ids of nodes to be selected.
  1872. The array <code>selection</code> can contain zero or multiple ids.
  1873. Example usage: <code>graph.setSelection([3, 5]);</code> will select
  1874. nodes with id 3 and 5.
  1875. </td>
  1876. </tr>
  1877. <tr>
  1878. <td>setSize(width, height)</td>
  1879. <td>none</td>
  1880. <td>Parameters <code>width</code> and <code>height</code> are strings,
  1881. containing a new size for the visualization. Size can be provided in pixels
  1882. or in percentages.</td>
  1883. </tr>
  1884. <tr>
  1885. <td>zoomExtent()</td>
  1886. <td>none</td>
  1887. <td>Scales the graph so all the nodes are in center view.</td>
  1888. </tr>
  1889. </table>
  1890. <h2 id="Events">Events</h2>
  1891. <p>
  1892. Graph fires events after one or multiple nodes are selected or deselected.
  1893. The event can be catched by creating a listener.
  1894. </p>
  1895. <p>
  1896. Here an example on how to catch a <code>select</code> event.
  1897. </p>
  1898. <pre class="prettyprint lang-js">
  1899. graph.on('select', function (properties) {
  1900. alert('selected nodes: ' + properties.nodes);
  1901. });
  1902. </pre>
  1903. <p>
  1904. A listener can be removed via the function <code>off</code>:
  1905. </p>
  1906. <pre class="prettyprint lang-js">
  1907. function onSelect (properties) {
  1908. alert('selected nodes: ' + properties.nodes);
  1909. }
  1910. // add event listener
  1911. graph.on('select', onSelect);
  1912. // do stuff...
  1913. // remove event listener
  1914. graph.off('select', onSelect);
  1915. </pre>
  1916. <p>
  1917. The following events are available.
  1918. </p>
  1919. <table>
  1920. <tr>
  1921. <th>name</th>
  1922. <th>Description</th>
  1923. <th>Properties</th>
  1924. </tr>
  1925. <tr>
  1926. <td>select</td>
  1927. <td>Fired after the user selects or deselects a node by clicking it.
  1928. Not fired when the method <code>setSelection</code>is executed.
  1929. </td>
  1930. <td>
  1931. <ul>
  1932. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1933. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1934. </ul>
  1935. </td>
  1936. </tr>
  1937. <tr>
  1938. <td>click</td>
  1939. <td>Fired after the user clicks or taps on a touchscreen.</td>
  1940. <td>
  1941. <ul>
  1942. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1943. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1944. </ul>
  1945. </td>
  1946. </tr>
  1947. <tr>
  1948. <td>doubleClick</td>
  1949. <td>Fired after the user double clicks or double taps on a touchscreen.</td>
  1950. <td>
  1951. <ul>
  1952. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1953. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1954. </ul>
  1955. </td>
  1956. </tr>
  1957. <tr>
  1958. <td>resize</td>
  1959. <td>Fired when the size of the canvas has been updated (not neccecarily changed) by the setSize() function or by the setOptions() function.</td>
  1960. <td>
  1961. <ul>
  1962. <li><code>width</code>: the new width of the canvas</li>
  1963. <li><code>height</code>: the new height of the canvas</li>
  1964. </ul>
  1965. </td>
  1966. </tr>
  1967. <tr>
  1968. <td>stabilized</td>
  1969. <td>Fired when the graph has been stabilized after initialization. This event can be used to trigger the .storePosition() function after stabilization.</td>
  1970. <td>
  1971. <ul>
  1972. <li><code>iterations</code>: number of iterations used to stabilize</li>
  1973. </ul>
  1974. </td>
  1975. </tr>
  1976. <tr>
  1977. <td>viewChanged</td>
  1978. <td>Fired when the view has changed. This is when the graph has moved or zoomed.</td>
  1979. <td>
  1980. none
  1981. </td>
  1982. </tr>
  1983. <tr>
  1984. <td>zoom</td>
  1985. <td>Fired when the graph has zoomed. This event can be used to trigger the .storePosition() function after stabilization.</td>
  1986. <td>
  1987. <ul>
  1988. <li><code>direction: </code> "+" or "-" </li>
  1989. </ul>
  1990. </td>
  1991. </tr>
  1992. </table>
  1993. <h2 id="Data_policy">Data policy</h2>
  1994. <p>
  1995. All code and data is processed and rendered in the browser.
  1996. No data is sent to any server.
  1997. </p>
  1998. </div>
  1999. </body>
  2000. </html>