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.

1872 lines
55 KiB

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