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.

2350 lines
73 KiB

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