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.

1915 lines
57 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>
  1047. <pre class="prettyprint">
  1048. // These variables must be defined in an options object named physics.
  1049. // If a variable is not supplied, the default value is used.
  1050. var options = {
  1051. physics: {
  1052. barnesHut: {
  1053. enabled: true,
  1054. gravitationalConstant: -2000,
  1055. centralGravity: 0.1,
  1056. springLength: 100,
  1057. springConstant: 0.05,
  1058. damping: 0.09
  1059. },
  1060. repulsion: {
  1061. centralGravity: 0.1,
  1062. springLength: 50,
  1063. springConstant: 0.05,
  1064. nodeDistance: 100,
  1065. damping: 0.09
  1066. },
  1067. }
  1068. </pre>
  1069. <h5>barnesHut:</h5>
  1070. <table>
  1071. <tr>
  1072. <th>Name</th>
  1073. <th>Type</th>
  1074. <th>Default</th>
  1075. <th>Description</th>
  1076. </tr>
  1077. <tr>
  1078. <td>enabled</td>
  1079. <td>Boolean</td>
  1080. <td>true</td>
  1081. <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>
  1082. </tr>
  1083. <tr>
  1084. <td>gravitationalConstant</td>
  1085. <td>Number</td>
  1086. <td>-2000</td>
  1087. <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>
  1088. </tr>
  1089. <tr>
  1090. <td>centralGravity</td>
  1091. <td>Number</td>
  1092. <td>0.1</td>
  1093. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1094. </tr>
  1095. <tr>
  1096. <td>springLength</td>
  1097. <td>Number</td>
  1098. <td>100</td>
  1099. <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.
  1100. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1101. </tr>
  1102. <tr>
  1103. <td>springConstant</td>
  1104. <td>Number</td>
  1105. <td>0.05</td>
  1106. <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>
  1107. </tr>
  1108. <tr>
  1109. <td>damping</td>
  1110. <td>Number</td>
  1111. <td>0.09</td>
  1112. <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>
  1113. </tr>
  1114. </table>
  1115. <h5>repulsion:</h5>
  1116. <table>
  1117. <tr>
  1118. <th>Name</th>
  1119. <th>Type</th>
  1120. <th>Default</th>
  1121. <th>Description</th>
  1122. </tr>
  1123. <tr>
  1124. <td>centralGravity</td>
  1125. <td>Number</td>
  1126. <td>0.1</td>
  1127. <td>The central gravity is a force that pulls all nodes to the center. This ensures independent groups do not float apart.</td>
  1128. </tr>
  1129. <tr>
  1130. <td>springLength</td>
  1131. <td>Number</td>
  1132. <td>50</td>
  1133. <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.
  1134. To greatly reduce the edge length, the gravitationalConstant has to be reduced as well.</td>
  1135. </tr>
  1136. <tr>
  1137. <td>nodeDistance</td>
  1138. <td>Number</td>
  1139. <td>100</td>
  1140. <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>
  1141. </tr>
  1142. <tr>
  1143. <td>springConstant</td>
  1144. <td>Number</td>
  1145. <td>0.05</td>
  1146. <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>
  1147. </tr>
  1148. <tr>
  1149. <td>damping</td>
  1150. <td>Number</td>
  1151. <td>0.09</td>
  1152. <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>
  1153. </tr>
  1154. </table>
  1155. <h3 id="Data_manipulation">Data manipulation</h3>
  1156. <p>
  1157. 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.
  1158. 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
  1159. 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>,
  1160. two functions have been injected into the add and edit functionality. This is described in more detail in the next subsection.
  1161. </p>
  1162. <pre class="prettyprint">
  1163. // These variables must be defined in an options object named dataManipulation.
  1164. // If a variable is not supplied, the default value is used.
  1165. var options = {
  1166. dataManipulation: {
  1167. enabled: false,
  1168. initiallyVisible: false
  1169. }
  1170. }
  1171. // OR to just load the module with default values:
  1172. var options: {
  1173. dataManipulation: true
  1174. }
  1175. </pre>
  1176. <table>
  1177. <tr>
  1178. <th>Name</th>
  1179. <th>Type</th>
  1180. <th>Default</th>
  1181. <th>Description</th>
  1182. </tr>
  1183. <tr>
  1184. <td>enabled</td>
  1185. <td>Boolean</td>
  1186. <td>false</td>
  1187. <td>Enabling or disabling of the data manipulation toolbar. If it is initially hidden, an edit button appears in the top left corner.</td>
  1188. </tr>
  1189. <tr>
  1190. <td>initiallyVisible</td>
  1191. <td>Boolean</td>
  1192. <td>false</td>
  1193. <td>Initially hide or show the data manipulation toolbar.</td>
  1194. </tr>
  1195. </table>
  1196. <h4 id="Data_manipulation_custom">Data manipulation: custom functionality</h4>
  1197. <p>
  1198. 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.
  1199. If the callback is NOT called, nothing happens. <a href="../examples/graph/21_data_manipulation.html">Example 21</a> has two working examples
  1200. for the add and edit functions. The data the user is supplied with in these functions has been described in the code below.
  1201. 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
  1202. 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
  1203. requires the same data structure that is supplied to the user. <br /><br />
  1204. <b>If there is no injected function supplied for the edit operation, the button will not be shown in the toolbar.</b>
  1205. </p>
  1206. <pre class="prettyprint">
  1207. // If a variable is not supplied, the default value is used.
  1208. var options: {
  1209. dataManipulation: true,
  1210. onAdd: function(data,callback) {
  1211. /** data = {id: random unique id,
  1212. * label: new,
  1213. * x: x position of click (canvas space),
  1214. * y: y position of click (canvas space),
  1215. * allowedToMove: true
  1216. * };
  1217. */
  1218. var newData = {..}; // alter the data as you want.
  1219. // all fields normally accepted by a node can be used.
  1220. callback(newData); // call the callback to add a node.
  1221. },
  1222. onEdit: function(data,callback) {
  1223. /** data = {id:...,
  1224. * label: ...,
  1225. * group: ...,
  1226. * shape: ...,
  1227. * color: {
  1228. * background:...,
  1229. * border:...,
  1230. * highlight: {
  1231. * background:...,
  1232. * border:...
  1233. * }
  1234. * }
  1235. * };
  1236. */
  1237. var newData = {..}; // alter the data as you want.
  1238. // all fields normally accepted by a node can be used.
  1239. callback(newData); // call the callback with the new data to edit the node.
  1240. }
  1241. onConnect: function(data,callback) {
  1242. // data = {from: nodeId1, to: nodeId2};
  1243. var newData = {..}; // check or alter data as you see fit.
  1244. callback(newData); // call the callback to connect the nodes.
  1245. },
  1246. onDelete: function(data,callback) {
  1247. // data = {nodes: [selectedNodeIds], edges: [selectedEdgeIds]};
  1248. var newData = {..}; // alter the data as you want.
  1249. // the same data structure is required.
  1250. callback(newData); // call the callback to delete the objects.
  1251. }
  1252. };
  1253. </pre>
  1254. <p>
  1255. 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.
  1256. 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.
  1257. An code snippet from example 21 is shown below.
  1258. </p>
  1259. <pre class="prettyprint">
  1260. graph.on("resize", function(params) {console.log(params.width,params.height)});
  1261. </pre>
  1262. <h3 id="Clustering">Clustering</h3>
  1263. <p>
  1264. The graph now supports dynamic clustering of nodes. This allows a user to view a very large dataset (> 50.000 nodes) without
  1265. sacrificing performance. When loading a large dataset, the nodes are clustered initially (this may take a small while) to have a
  1266. responsive visualization to work with. The clustering is both outside-in and inside-out. Outside-in means that nodes with only one
  1267. connection will be contained, or clustered, in the node it is connected to. Inside-out clustering first determines which nodes are hubs.
  1268. Hubs are defined as the nodes with the top 3% highest amount of connections (assuming normal distribution). These hubs then "grow", meaning
  1269. 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.
  1270. <br />
  1271. <br />
  1272. 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
  1273. to calculate the required forces. The contained nodes are removed from the global nodes index, greatly speeding up the system.
  1274. <br />
  1275. <br />
  1276. The clustering has the following user-configurable settings. The default values have been tested with the Graph examples and work well.
  1277. The default state for clustering is <b>off</b>.
  1278. </p>
  1279. <pre class="prettyprint">
  1280. // These variables must be defined in an options object named clustering.
  1281. // If a variable is not supplied, the default value is used.
  1282. var options = {
  1283. clustering: {
  1284. initialMaxNodes: 100,
  1285. clusterThreshold:500,
  1286. reduceToNodes:300,
  1287. chainThreshold: 0.4,
  1288. clusterEdgeThreshold: 20,
  1289. sectorThreshold: 100,
  1290. screenSizeThreshold: 0.2,
  1291. fontSizeMultiplier: 4.0,
  1292. maxFontSize: 1000,
  1293. forceAmplification: 0.1,
  1294. distanceAmplification: 0.1,
  1295. edgeGrowth: 20,
  1296. nodeScaling: {width: 1,
  1297. height: 1,
  1298. radius: 1},
  1299. maxNodeSizeIncrements: 600,
  1300. activeAreaBoxSize: 100,
  1301. clusterLevelDifference: 2
  1302. }
  1303. }
  1304. // OR to just load the module with default values:
  1305. var options: {
  1306. clustering: true
  1307. }
  1308. </pre>
  1309. <table>
  1310. <tr>
  1311. <th>Name</th>
  1312. <th>Type</th>
  1313. <th>Default</th>
  1314. <th>Description</th>
  1315. </tr>
  1316. <tr>
  1317. <td>initialMaxNodes</td>
  1318. <td>Number</td>
  1319. <td>100</td>
  1320. <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>
  1321. </tr>
  1322. <tr>
  1323. <td>clusterThreshold</td>
  1324. <td>Number</td>
  1325. <td>500</td>
  1326. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1327. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continuously fluid.</td>
  1328. </tr>
  1329. <tr>
  1330. <td>reduceToNodes</td>
  1331. <td>Number</td>
  1332. <td>300</td>
  1333. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  1334. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  1335. </tr>
  1336. <tr>
  1337. <td>chainThreshold</td>
  1338. <td>Number</td>
  1339. <td>0.4</td>
  1340. <td>Because of the clustering methods used, long chains of nodes can be formed. To reduce these chains, this threshold is used.
  1341. 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).
  1342. If there are more, they are clustered together.</td>
  1343. </tr>
  1344. <tr>
  1345. <td>clusterEdgeThreshold</td>
  1346. <td>Number</td>
  1347. <td>20</td>
  1348. <td>This is the absolute edge length threshold in pixels. If the edge is smaller on screen (that means zooming out reduces this length)
  1349. the node will be clustered. This is triggered when zooming out.</td>
  1350. </tr>
  1351. <tr>
  1352. <td>sectorThreshold</td>
  1353. <td>Integer</td>
  1354. <td>50</td>
  1355. <td>If a cluster larger than <code>sectorThreshold</code> is opened, a seperate instance called a sector, will be created. All the simulation of
  1356. nodes outside of this instance will be paused. This is to maintain performance and clarity when examining large clusters.
  1357. 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>
  1358. </tr>
  1359. <tr>
  1360. <td>screenSizeThreshold</td>
  1361. <td>Number</td>
  1362. <td>0.2</td>
  1363. <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
  1364. 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
  1365. 20%, we collapse this sector.</td>
  1366. </tr>
  1367. <tr>
  1368. <td>fontSizeMultiplier</td>
  1369. <td>Number</td>
  1370. <td>4.0</td>
  1371. <td>This parameter denotes the increase in fontSize of the cluster when a single node is added to it.</td>
  1372. </tr>
  1373. <tr>
  1374. <td>maxFontSize</td>
  1375. <td>Number</td>
  1376. <td>1000</td>
  1377. <td>This parameter denotes the largest allowed font size. If the font becomes too large, some browsers experience problems displaying this.</td>
  1378. </tr>
  1379. <tr>
  1380. <td>forceAmplification</td>
  1381. <td>Number</td>
  1382. <td>0.6</td>
  1383. <td>This factor is used to calculate the increase of the repulsive force of a cluster. It is calculated by the following
  1384. formula: <code>repulsingForce *= 1 + (clusterSize * forceAmplification)</code>.</td>
  1385. </tr>
  1386. <tr>
  1387. <td>distanceAmplification</td>
  1388. <td>Number</td>
  1389. <td>0.2</td>
  1390. <td>This factor is used to calculate the increase in effective range of the repulsive force of the cluster.
  1391. A larger cluster has a longer range. It is calculated by the following
  1392. formula: <code>minDistance *= 1 + (clusterSize * distanceAmplification)</code>.</td>
  1393. </tr>
  1394. <tr>
  1395. <td>edgeGrowth</td>
  1396. <td>Number</td>
  1397. <td>20</td>
  1398. <td>This factor determines the elongation of edges connected to a cluster.</td>
  1399. </tr>
  1400. <tr>
  1401. <td>nodeScaling.width</td>
  1402. <td>Number</td>
  1403. <td>10</td>
  1404. <td>This factor determines how much the width of a cluster increases in pixels per added node.</td>
  1405. </tr>
  1406. <tr>
  1407. <td>nodeScaling.height</td>
  1408. <td>Number</td>
  1409. <td>10</td>
  1410. <td>This factor determines how much the height of a cluster increases in pixels per added node.</td>
  1411. </tr>
  1412. <tr>
  1413. <td>nodeScaling.radius</td>
  1414. <td>Number</td>
  1415. <td>10</td>
  1416. <td>This factor determines how much the radius of a cluster increases in pixels per added node.</td>
  1417. </tr>
  1418. <tr>
  1419. <td>maxNodeSizeIncrements</td>
  1420. <td>Number</td>
  1421. <td>600</td>
  1422. <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>
  1423. </tr>
  1424. <tr>
  1425. <td>activeAreaBoxSize</td>
  1426. <td>Number</td>
  1427. <td>100</td>
  1428. <td>Imagine a square with an edge length of <code>activeAreaBoxSize</code> pixels around your cursor.
  1429. If a cluster is in this box as you zoom in, the cluster can be opened in a seperate sector.
  1430. This is regardless of the zoom level.</td>
  1431. </tr>
  1432. <tr>
  1433. <td>clusterLevelDifference</td>
  1434. <td>Number</td>
  1435. <td>2</td>
  1436. <td>At every clustering session, Graph will check if the difference between cluster levels is
  1437. acceptable. When a cluster is formed when zooming out, that is one cluster level.
  1438. If you zoom out further and it encompasses more nodes, that is another level. For example:
  1439. If the highest level of your graph at any given time is 3, nodes that have not clustered or
  1440. have clustered only once will join their neighbour with the lowest cluster level.</td>
  1441. </tr>
  1442. </table>
  1443. <h3 id="Navigation_controls">Navigation controls</h3>
  1444. <p>
  1445. Graph has a menu with navigation controls, which is disabled by default.
  1446. It can be configured with the following settings.
  1447. </p>
  1448. <pre class="prettyprint">
  1449. // use of navigation controls
  1450. var options: {
  1451. navigation: true
  1452. }
  1453. </pre>
  1454. <h3 id="Keyboard_navigation">Keyboard navigation</h3>
  1455. <p>
  1456. The graph can be navigated using shortcut keys.
  1457. 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>.
  1458. </p>
  1459. <pre class="prettyprint">
  1460. // simple use of keyboard controls
  1461. var options: {
  1462. keyboard: true
  1463. }
  1464. // advanced configuration for keyboard controls
  1465. var options: {
  1466. keyboard: {
  1467. speed: {
  1468. x: 10,
  1469. y: 10,
  1470. zoom: 0.02
  1471. }
  1472. }
  1473. }
  1474. </pre>
  1475. <table>
  1476. <tr>
  1477. <th>Name</th>
  1478. <th>Type</th>
  1479. <th>Default</th>
  1480. <th>Description</th>
  1481. </tr>
  1482. <tr>
  1483. <td>speed.x</td>
  1484. <td>Number</td>
  1485. <td>10</td>
  1486. <td>This defines the speed of the camera movement in the x direction when using the keyboard navigation.
  1487. </td>
  1488. </tr>
  1489. <tr>
  1490. <td>speed.y</td>
  1491. <td>Number</td>
  1492. <td>10</td>
  1493. <td>This defines the speed of the camera movement in the y direction when using the keyboard navigation.</td>
  1494. </tr>
  1495. <tr>
  1496. <td>speed.zoom</td>
  1497. <td>Number</td>
  1498. <td>0.02</td>
  1499. <td>This defines the zoomspeed when using the keyboard navigation.</td>
  1500. </tr>
  1501. </table>
  1502. <h3 id="Hierarchical_layout">Hierarchical layout</h3>
  1503. <p>
  1504. 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.
  1505. 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
  1506. 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>.
  1507. This layout method does not support smooth curves or clustering. It automatically turns these features off.
  1508. </p>
  1509. <pre class="prettyprint">
  1510. // simple use of the hierarchical layout
  1511. var options: {
  1512. hierarchicalLayout: true
  1513. }
  1514. // advanced configuration for hierarchical layout
  1515. var options: {
  1516. hierarchicalLayout: {
  1517. enabled:false,
  1518. levelSeparation: 150,
  1519. nodeSpacing: 100,
  1520. direction: "UD"
  1521. }
  1522. }
  1523. // partial configuration automatically sets enabled to true
  1524. var options: {
  1525. hierarchicalLayout: {
  1526. nodeSpacing: 100,
  1527. direction: "UD"
  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, considering UP-DOWN 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, considering UP-DOWN direction).
  1556. This is only relevant during the initial placing of nodes.</td>
  1557. </tr>
  1558. <tr>
  1559. <td>direction</td>
  1560. <td>String</td>
  1561. <td>UD</td>
  1562. <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).
  1563. These need to be supplied by the acronyms in parentheses.</td>
  1564. </tr>
  1565. </table>
  1566. <h2 id="Methods">Methods</h2>
  1567. <p>
  1568. Graph supports the following methods.
  1569. </p>
  1570. <table>
  1571. <tr>
  1572. <th>Method</th>
  1573. <th>Return Type</th>
  1574. <th>Description</th>
  1575. </tr>
  1576. <tr>
  1577. <td>getSelection()</td>
  1578. <td>Array of ids</td>
  1579. <td>Returns an array with the ids of the selected nodes.
  1580. Returns an empty array if no nodes are selected.
  1581. The selections are not ordered.
  1582. </td>
  1583. </tr>
  1584. <tr>
  1585. <td>on(event, callback)</td>
  1586. <td>none</td>
  1587. <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>
  1588. </tr>
  1589. <tr>
  1590. <td>off(event, callback)</td>
  1591. <td>none</td>
  1592. <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>
  1593. </tr>
  1594. <tr>
  1595. <td>redraw()</td>
  1596. <td>none</td>
  1597. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  1598. </tr>
  1599. <tr>
  1600. <td>setData(data,[disableStart])</td>
  1601. <td>none</td>
  1602. <td>Loads data. Parameter <code>data</code> is an object containing
  1603. nodes, edges, and options. Parameters nodes, edges are an Array.
  1604. Options is a name-value map and is optional. Parameter <code>disableStart</code> is
  1605. an optional Boolean and can disable the start of the simulation that would begin at the end
  1606. of this function by default.
  1607. </td>
  1608. </tr>
  1609. <tr>
  1610. <td>setOptions(options)</td>
  1611. <td>none</td>
  1612. <td>Set options for the graph. The available options are described in
  1613. the section <a href="#Configuration_options">Configuration Options</a>.
  1614. </td>
  1615. </tr>
  1616. <tr>
  1617. <td>setSelection(selection)</td>
  1618. <td>none</td>
  1619. <td>Select nodes.
  1620. <code>selection</code> is an array with ids of nodes to be selected.
  1621. The array <code>selection</code> can contain zero or multiple ids.
  1622. Example usage: <code>graph.setSelection([3, 5]);</code> will select
  1623. nodes with id 3 and 5.
  1624. </td>
  1625. </tr>
  1626. <tr>
  1627. <td>setSize(width, height)</td>
  1628. <td>none</td>
  1629. <td>Parameters <code>width</code> and <code>height</code> are strings,
  1630. containing a new size for the visualization. Size can be provided in pixels
  1631. or in percentages.</td>
  1632. </tr>
  1633. <tr>
  1634. <td>zoomExtent</td>
  1635. <td>none</td>
  1636. <td>Scales the graph so all the nodes are in center view.</td>
  1637. </tr>
  1638. </table>
  1639. <h2 id="Events">Events</h2>
  1640. <p>
  1641. Graph fires events after one or multiple nodes are selected or deselected.
  1642. The event can be catched by creating a listener.
  1643. </p>
  1644. <p>
  1645. Here an example on how to catch a <code>select</code> event.
  1646. </p>
  1647. <pre class="prettyprint lang-js">
  1648. graph.on('select', function (properties) {
  1649. alert('selected nodes: ' + properties.nodes);
  1650. });
  1651. </pre>
  1652. <p>
  1653. A listener can be removed via the function <code>off</code>:
  1654. </p>
  1655. <pre class="prettyprint lang-js">
  1656. function onSelect (properties) {
  1657. alert('selected nodes: ' + properties.nodes);
  1658. }
  1659. // add event listener
  1660. graph.on('select', onSelect);
  1661. // do stuff...
  1662. // remove event listener
  1663. graph.off('select', onSelect);
  1664. </pre>
  1665. <p>
  1666. The following events are available.
  1667. </p>
  1668. <table>
  1669. <tr>
  1670. <th>name</th>
  1671. <th>Description</th>
  1672. <th>Properties</th>
  1673. </tr>
  1674. <tr>
  1675. <td>select</td>
  1676. <td>Fired after the user selects or deselects a node by clicking it.
  1677. Not fired when the method <code>setSelection</code>is executed.
  1678. </td>
  1679. <td>
  1680. <ul>
  1681. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1682. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1683. </ul>
  1684. </td>
  1685. </tr>
  1686. <tr>
  1687. <td>click</td>
  1688. <td>Fired after the user clicks or taps on a touchscreen.</td>
  1689. <td>
  1690. <ul>
  1691. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1692. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1693. </ul>
  1694. </td>
  1695. </tr>
  1696. <tr>
  1697. <td>doubleClick</td>
  1698. <td>Fired after the user double clicks or double taps on a touchscreen.</td>
  1699. <td>
  1700. <ul>
  1701. <li><code>nodes</code>: an array with the ids of the selected nodes</li>
  1702. <li><code>edges</code>: an array with the ids of the selected edges</li>
  1703. </ul>
  1704. </td>
  1705. </tr>
  1706. <tr>
  1707. <td>resize</td>
  1708. <td>Fired when the size of the canvas has been updated (not neccecarily changed) by the setSize() function or by the setOptions() function.</td>
  1709. <td>
  1710. <ul>
  1711. <li><code>width</code>: the new width of the canvas</li>
  1712. <li><code>height</code>: the new height of the canvas</li>
  1713. </ul>
  1714. </td>
  1715. </tr>
  1716. </table>
  1717. <h2 id="Data_policy">Data policy</h2>
  1718. <p>
  1719. All code and data is processed and rendered in the browser.
  1720. No data is sent to any server.
  1721. </p>
  1722. </div>
  1723. </body>
  1724. </html>