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.

1927 lines
58 KiB

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