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.

1375 lines
37 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>vis.js | graph documentation</title>
  5. <link href="css/prettify.css" type="text/css" rel="stylesheet" />
  6. <link href='css/style.css' type='text/css' rel='stylesheet'>
  7. <script type="text/javascript" src="lib/prettify/prettify.js"></script>
  8. </head>
  9. <body onload="prettyPrint();">
  10. <div id="container">
  11. <h1>Graph documentation</h1>
  12. <h2><a name="Contents"></a>Contents</h2>
  13. <ul>
  14. <li><a href="#Overview">Overview</a></li>
  15. <li><a href="#Example">Example</a></li>
  16. <li><a href="#Loading">Loading</a></li>
  17. <li>
  18. <a href="#Data_Format">Data Format</a>
  19. <ul>
  20. <li><a href="#Nodes">Nodes</a></li>
  21. <li><a href="#Edges">Edges</a></li>
  22. <li><a href="#DOT_language">DOT language</a></li>
  23. </ul>
  24. </li>
  25. <li><a href="#Configuration_Options">Configuration Options</a></li>
  26. <li><a href="#Clustering">Clustering</a></li>
  27. <li><a href="#NavigationUI">Navigation GUI</a></li>
  28. <li><a href="#Keyboard">Keyboard Navigation</a></li>
  29. <li><a href="#Methods">Methods</a></li>
  30. <li><a href="#Events">Events</a></li>
  31. <li><a href="#Data_Policy">Data Policy</a></li>
  32. </ul>
  33. <h2 id="Overview">Overview</h2>
  34. <p>
  35. Graph is a visualization to display graphs and networks consisting of nodes
  36. and edges. The visualization is easy to use and supports custom shapes,
  37. styles, colors, sizes, images, and more.
  38. </p>
  39. <p>
  40. The graph visualization works smooth on any modern browser for up to a
  41. few hundred nodes and edges.
  42. </p>
  43. <p>
  44. To get started with Graph, install or download the
  45. <a href="http://visjs.org" target="_blank">vis.js</a> library.
  46. </p>
  47. <h2 id="Example">Example</h2>
  48. <p>
  49. Here a basic graph example. Note that unlike the
  50. <a href="timeline.html">Timeline</a>, the Graph does not need the vis.css
  51. file.
  52. </p>
  53. <p>
  54. More examples can be found in the
  55. <a href="../examples" target="_blank">examples directory</a>.
  56. </p>
  57. <pre class="prettyprint lang-html">&lt;!doctype html&gt;
  58. &lt;html&gt;
  59. &lt;head&gt;
  60. &lt;title&gt;Graph | Basic usage&lt;/title&gt;
  61. &lt;script type="text/javascript" src="../../dist/vis.js"&gt;&lt;/script&gt;
  62. &lt;/head&gt;
  63. &lt;body&gt;
  64. &lt;div id="mygraph"&gt;&lt;/div&gt;
  65. &lt;script type="text/javascript"&gt;
  66. // create an array with nodes
  67. var nodes = [
  68. {id: 1, label: 'Node 1'},
  69. {id: 2, label: 'Node 2'},
  70. {id: 3, label: 'Node 3'},
  71. {id: 4, label: 'Node 4'},
  72. {id: 5, label: 'Node 5'}
  73. ];
  74. // create an array with edges
  75. var edges = [
  76. {from: 1, to: 2},
  77. {from: 1, to: 3},
  78. {from: 2, to: 4},
  79. {from: 2, to: 5}
  80. ];
  81. // create a graph
  82. var container = document.getElementById('mygraph');
  83. var data= {
  84. nodes: nodes,
  85. edges: edges,
  86. };
  87. var options = {
  88. width: '400px',
  89. height: '400px'
  90. };
  91. var graph = new vis.Graph(container, data, options);
  92. &lt;/script&gt;
  93. &lt;/body&gt;
  94. &lt;/html&gt;
  95. </pre>
  96. <h2 id="Loading">Loading</h2>
  97. <p>
  98. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  99. in a subfolder of your project. Include the library script in the head of your html code:
  100. </p>
  101. <pre class="prettyprint lang-html">
  102. &lt;script type="text/javascript" src="vis/dist/vis.js"&gt;&lt;/script&gt;
  103. </pre>
  104. The constructor of the Graph is <code>vis.Graph</code>.
  105. <pre class="prettyprint lang-js">var graph = new vis.Graph(container, data, options);</pre>
  106. The constructor accepts three parameters:
  107. <ul>
  108. <li>
  109. <code>container</code> is the DOM element in which to create the graph.
  110. </li>
  111. <li>
  112. <code>data</code> is an Object containing properties <code>nodes</code> and
  113. <code>edges</code>, which both contain an array with objects.
  114. Optionally, data may contain an <code>options</code> object.
  115. The parameter <code>data</code> is optional, data can also be set using
  116. the method <code>setData</code>. Section <a href="#Data_Format">Data Format</a>
  117. describes the data object.
  118. </li>
  119. <li>
  120. <code>options</code> is an optional Object containing a name-value map
  121. with options. Options can also be set using the method
  122. <code>setOptions</code>.
  123. Section <a href="#Configuration_Options">Configuration Options</a>
  124. describes the available options.
  125. </li>
  126. </ul>
  127. <h2 id="Data_Format">Data Format</h2>
  128. <p>
  129. The <code>data</code> parameter of the Graph constructor is an object
  130. which can contain different types of data.
  131. The following properties are supported in the <code>data</code> object:
  132. </p>
  133. <ul>
  134. <li>
  135. <span style="font-weight: bold;">A property pair <code>nodes</code> and <code>edges</code></span>,
  136. both containing an Array with objects. The data formats are described
  137. in the sections <a href="#Nodes">Nodes</a> and <a href="#Edges">Edges</a>.
  138. Example:
  139. <pre class="prettyprint lang-js">
  140. var data = {
  141. nodes: [...],
  142. edges: [...]
  143. };
  144. </pre>
  145. </li>
  146. <li>
  147. <span style="font-weight: bold;">A property <code>dot</code></span>,
  148. containing a string with data in the
  149. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  150. DOT support is described in section <a href="#DOT_language">DOT_language</a>.
  151. Example:
  152. <pre class="prettyprint lang-js">
  153. var data = {
  154. dot: '...'
  155. };
  156. </pre>
  157. </li>
  158. <li>
  159. <span style="font-weight: bold;">A property <code>options</code></span>,
  160. containing an object with global options.
  161. Options can be provided as third parameter in the graph constructor
  162. as well. Section <a href="#Configuration_Options">Configuration Options</a>
  163. describes the available options.
  164. </li>
  165. </ul>
  166. <h3 id="Nodes">Nodes</h3>
  167. <p>
  168. Nodes typically have an <code>id</code> and <code>label</code>.
  169. A node must contain at least a property <code>id</code>.
  170. Nodes can have extra properties, used to define the shape and style of the
  171. nodes.
  172. </p>
  173. <p>
  174. A JavaScript Array with nodes is constructed like:
  175. </p>
  176. <pre class="prettyprint lang-js">
  177. var nodes = [
  178. {
  179. id: 1,
  180. label: 'Node 1'
  181. },
  182. // ... more nodes
  183. ];
  184. </pre>
  185. <p>
  186. Nodes support the following properties:
  187. </p>
  188. <table>
  189. <tr>
  190. <th>Name</th>
  191. <th>Type</th>
  192. <th>Required</th>
  193. <th>Description</th>
  194. </tr>
  195. <tr>
  196. <td>color</td>
  197. <td>String | Object</td>
  198. <td>no</td>
  199. <td>Color for the node.</td>
  200. </tr>
  201. <tr>
  202. <td>color.background</td>
  203. <td>String</td>
  204. <td>no</td>
  205. <td>Background color for the node.</td>
  206. </tr>
  207. <tr>
  208. <td>color.border</td>
  209. <td>String</td>
  210. <td>no</td>
  211. <td>Border color for the node.</td>
  212. </tr>
  213. <tr>
  214. <td>color.highlight</td>
  215. <td>String | Object</td>
  216. <td>no</td>
  217. <td>Color of the node when selected.</td>
  218. </tr>
  219. <tr>
  220. <td>color.highlight.background</td>
  221. <td>String</td>
  222. <td>no</td>
  223. <td>Background color of the node when selected.</td>
  224. </tr>
  225. <tr>
  226. <td>color.highlight.border</td>
  227. <td>String</td>
  228. <td>no</td>
  229. <td>Border color of the node when selected.</td>
  230. </tr>
  231. <tr>
  232. <td>group</td>
  233. <td>Number | String</td>
  234. <td>no</td>
  235. <td>A group number or name. The type can be <code>number</code>,
  236. <code>string</code>, or an other type. All nodes with the same group get
  237. the same color schema.</td>
  238. </tr>
  239. <tr>
  240. <td>fontColor</td>
  241. <td>String</td>
  242. <td>no</td>
  243. <td>Font color for label in the node.</td>
  244. </tr>
  245. <tr>
  246. <td>fontFace</td>
  247. <td>String</td>
  248. <td>no</td>
  249. <td>Font face for label in the node, for example "verdana" or "arial".</td>
  250. </tr>
  251. <tr>
  252. <td>fontSize</td>
  253. <td>Number</td>
  254. <td>no</td>
  255. <td>Font size in pixels for label in the node.</td>
  256. </tr>
  257. <tr>
  258. <td>id</td>
  259. <td>Number | String</td>
  260. <td>yes</td>
  261. <td>A unique id for this node.
  262. Nodes may not have duplicate id's.
  263. Id's do not need to be consecutive.
  264. An id is normally a number, but may be any type.</td>
  265. </tr>
  266. <tr>
  267. <td>image</td>
  268. <td>string</td>
  269. <td>no</td>
  270. <td>Url of an image. Only applicable when the shape of the node is
  271. <code>image</code>.</td>
  272. </tr>
  273. <tr>
  274. <td>radius</td>
  275. <td>number</td>
  276. <td>no</td>
  277. <td>Radius for the node. Applicable for all shapes except <code>box</code>,
  278. <code>circle</code>, <code>ellipse</code> and <code>database</code>.
  279. The value of <code>radius</code> will override a value in
  280. property <code>value</code>.</td>
  281. </tr>
  282. <tr>
  283. <td>shape</td>
  284. <td>string</td>
  285. <td>no</td>
  286. <td>Define the shape for the node.
  287. Choose from
  288. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  289. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  290. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  291. <br><br>
  292. In case of <code>image</code>, a property with name <code>image</code> must
  293. be provided, containing image urls.
  294. <br><br>
  295. The shapes <code>dot</code>, <code>star</code>, <code>triangle</code>,
  296. <code>triangleDown</code>, and <code>square</code>, are scalable.
  297. The size is determined by the properties <code>radius</code> or
  298. <code>value</code>.
  299. <br><br>
  300. When a property <code>label</code> is provided,
  301. this label will be displayed inside the shape in case of shapes
  302. <code>box</code>, <code>circle</code>, <code>ellipse</code>,
  303. and <code>database</code>.
  304. For all other shapes, the label will be displayed right below the shape.
  305. </td>
  306. </tr>
  307. <tr>
  308. <td>label</td>
  309. <td>string</td>
  310. <td>no</td>
  311. <td>Text label to be displayed in the node or under the image of the node.
  312. Multiple lines can be separated by a newline character <code>\n</code> .</td>
  313. </tr>
  314. <tr>
  315. <td>title</td>
  316. <td>string</td>
  317. <td>no</td>
  318. <td>Title to be displayed when the user hovers over the node.
  319. The title can contain HTML code.</td>
  320. </tr>
  321. <tr>
  322. <td>value</td>
  323. <td>number</td>
  324. <td>no</td>
  325. <td>A value for the node.
  326. The radius of the nodes will be scaled automatically from minimum to
  327. maximum value.
  328. Only applicable when the shape of the node is <code>dot</code>.
  329. If a <code>radius</code> is provided for the node too, it will override the
  330. radius calculated from the value.</td>
  331. </tr>
  332. <tr>
  333. <td>x</td>
  334. <td>number</td>
  335. <td>no</td>
  336. <td>Horizontal position in pixels.
  337. The horizontal position of the node will be fixed.
  338. The vertical position y may remain undefined.</td>
  339. </tr>
  340. <tr>
  341. <td>y</td>
  342. <td>number</td>
  343. <td>no</td>
  344. <td>Vertical position in pixels.
  345. The vertical position of the node will be fixed.
  346. The horizontal position x may remain undefined.</td>
  347. </tr>
  348. </table>
  349. <h3 id="Edges">Edges</h3>
  350. <p>
  351. Edges are connections between nodes.
  352. An edge must at least contain properties <code>from</code> and
  353. <code>to</code>, both referring to the <code>id</code> of a node.
  354. Edges can have extra properties, used to define the type and style.
  355. </p>
  356. <p>
  357. A JavaScript Array with edges is constructed as:
  358. </p>
  359. <pre class="prettyprint lang-js">
  360. var edges = [
  361. {
  362. from: 1,
  363. to: 3
  364. },
  365. // ... more edges
  366. ];
  367. </pre>
  368. <p>
  369. Edges support the following properties:
  370. </p>
  371. <table>
  372. <tr>
  373. <th>Name</th>
  374. <th>Type</th>
  375. <th>Required</th>
  376. <th>Description</th>
  377. </tr>
  378. <tr>
  379. <td>color</td>
  380. <td>string</td>
  381. <td>no</td>
  382. <td>A HTML color for the edge.</td>
  383. </tr>
  384. <tr>
  385. <td>dash</td>
  386. <td>Object</td>
  387. <td>no</td>
  388. <td>
  389. Object containing properties for dashed lines.
  390. Available properties: <code>length</code>, <code>gap</code>,
  391. <code>altLength</code>.
  392. </td>
  393. </tr>
  394. <tr>
  395. <td>dash.altLength</td>
  396. <td>number</td>
  397. <td>no</td>
  398. <td>Length of the alternated dash in pixels on a dashed line.
  399. Specifying <code>dash.altLength</code> allows for creating
  400. a dashed line with a dash-dot style, for example when
  401. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  402. See also the option <code>dahs.length</code>.
  403. Only applicable when the line style is <code>dash-line</code>.</td>
  404. </tr>
  405. <tr>
  406. <td>dash.length</td>
  407. <td>number</td>
  408. <td>no</td>
  409. <td>Length of a dash in pixels on a dashed line.
  410. Only applicable when the line style is <code>dash-line</code>.</td>
  411. </tr>
  412. <tr>
  413. <td>dash.gap</td>
  414. <td>number</td>
  415. <td>no</td>
  416. <td>Length of a gap in pixels on a dashed line.
  417. Only applicable when the line style is <code>dash-line</code>.</td>
  418. </tr>
  419. <tr>
  420. <td>fontColor</td>
  421. <td>String</td>
  422. <td>no</td>
  423. <td>Font color for the text label of the edge.
  424. Only applicable when property <code>label</code> is defined.</td>
  425. </tr>
  426. <tr>
  427. <td>fontFace</td>
  428. <td>String</td>
  429. <td>no</td>
  430. <td>Font face for the text label of the edge,
  431. for example "verdana" or "arial".
  432. Only applicable when property <code>label</code> is defined.</td>
  433. </tr>
  434. <tr>
  435. <td>fontSize</td>
  436. <td>Number</td>
  437. <td>no</td>
  438. <td>Font size in pixels for the text label of the edge.
  439. Only applicable when property <code>label</code> is defined.</td>
  440. </tr>
  441. <tr>
  442. <td>from</td>
  443. <td>Number | String</td>
  444. <td>yes</td>
  445. <td>The id of a node where the edge starts. The type must correspond with
  446. the type of the node id's. This is normally a number, but can be any
  447. type.</td>
  448. </tr>
  449. <tr>
  450. <td>length</td>
  451. <td>number</td>
  452. <td>no</td>
  453. <td>The length of the edge in pixels.</td>
  454. </tr>
  455. <tr>
  456. <td>style</td>
  457. <td>string</td>
  458. <td>no</td>
  459. <td>Define a line style for the edge.
  460. Choose from <code>line</code> (default), <code>arrow</code>,
  461. <code>arrow-center</code>, or <code>dash-line</code>.
  462. </td>
  463. </tr>
  464. <tr>
  465. <td>label</td>
  466. <td>string</td>
  467. <td>no</td>
  468. <td>Text label to be displayed halfway the edge.</td>
  469. </tr>
  470. <tr>
  471. <td>title</td>
  472. <td>string</td>
  473. <td>no</td>
  474. <td>Title to be displayed when the user hovers over the edge.
  475. The title can contain HTML code.</td>
  476. </tr>
  477. <tr>
  478. <td>to</td>
  479. <td>Number | String</td>
  480. <td>yes</td>
  481. <td>The id of a node where the edge ends. The type must correspond with
  482. the type of the node id's. This is normally a number, but can be any
  483. type.</td>
  484. </tr>
  485. <tr>
  486. <td>value</td>
  487. <td>number</td>
  488. <td>no</td>
  489. <td>A value for the edge.
  490. The width of the edges will be scaled automatically from minimum to
  491. maximum value.
  492. If a <code>width</code> is provided for the edge too, it will override the
  493. width calculated from the value.</td>
  494. </tr>
  495. <tr>
  496. <td>width</td>
  497. <td>number</td>
  498. <td>no</td>
  499. <td>Width of the line in pixels. The <code>width</code> will
  500. override a specified <code>value</code>, if a <code>value</code> is
  501. specified too.</td>
  502. </tr>
  503. </table>
  504. <h3 id="DOT_language">DOT language</h3>
  505. <p>
  506. Graph supports data in the
  507. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  508. To provide data in the DOT language, the <code>data</code> object must contain
  509. a property <code>dot</code> with a String containing the data.
  510. </p>
  511. <p>
  512. Example usage:
  513. </p>
  514. <pre class="prettyprint lang-js">
  515. // provide data in the DOT language
  516. var data = {
  517. dot: 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
  518. };
  519. // create a graph
  520. var graph = new vis.Graph(container, data);
  521. </pre>
  522. <h2 id="Configuration_Options">Configuration Options</h2>
  523. <p>
  524. Options can be used to customize the graph. Options are defined as a JSON object.
  525. All options are optional.
  526. </p>
  527. <pre class="prettyprint lang-js">
  528. var options = {
  529. width: '100%',
  530. height: '400px',
  531. edges: {
  532. color: 'red',
  533. width: 2
  534. }
  535. };
  536. </pre>
  537. <p>
  538. The following options are available.
  539. </p>
  540. <table>
  541. <tr>
  542. <th>Name</th>
  543. <th>Type</th>
  544. <th>Default</th>
  545. <th>Description</th>
  546. </tr>
  547. <tr>
  548. <td>edges.color</td>
  549. <td>String</td>
  550. <td>"#2B7CE9"</td>
  551. <td>The default color of a edge.</td>
  552. </tr>
  553. <tr>
  554. <td>edges.dash</td>
  555. <td>Object</td>
  556. <td>Object</td>
  557. <td>
  558. Object containing default properties for dashed lines.
  559. Available properties: <code>length</code>, <code>gap</code>,
  560. <code>altLength</code>.
  561. </td>
  562. </tr>
  563. <tr>
  564. <td>edges.dash.altLength</td>
  565. <td>number</td>
  566. <td>none</td>
  567. <td>Default length of the alternated dash in pixels on a dashed line.
  568. Specifying <code>dash.altLength</code> allows for creating
  569. a dashed line with a dash-dot style, for example when
  570. <code>dash.length=10</code> and <code>dash.altLength=5</code>.
  571. See also the option <code>dahs.length</code>.
  572. Only applicable when the line style is <code>dash-line</code>.</td>
  573. </tr>
  574. <tr>
  575. <td>edges.dash.length</td>
  576. <td>number</td>
  577. <td>10</td>
  578. <td>Default length of a dash in pixels on a dashed line.
  579. Only applicable when the line style is <code>dash-line</code>.</td>
  580. </tr>
  581. <tr>
  582. <td>edges.dash.gap</td>
  583. <td>number</td>
  584. <td>5</td>
  585. <td>Default length of a gap in pixels on a dashed line.
  586. Only applicable when the line style is <code>dash-line</code>.</td>
  587. </tr>
  588. <tr>
  589. <td>edges.length</td>
  590. <td>Number</td>
  591. <td>100</td>
  592. <td>The default length of a edge.</td>
  593. </tr>
  594. <tr>
  595. <td>edges.style</td>
  596. <td>String</td>
  597. <td>"line"</td>
  598. <td>The default style of a edge.
  599. Choose from <code>line</code> (default), <code>arrow</code>,
  600. <code>arrow-center</code>, <code>dash-line</code>.</td>
  601. </tr>
  602. <tr>
  603. <td>edges.width</td>
  604. <td>Number</td>
  605. <td>1</td>
  606. <td>The default width of a edge.</td>
  607. </tr>
  608. <tr>
  609. <td>groups</td>
  610. <td>Object</td>
  611. <td>none</td>
  612. <td>It is possible to specify custom styles for groups.
  613. Each node assigned a group gets the specified style.
  614. See <a href="#Groups">Groups</a> for an overview of the available styles
  615. and an example.
  616. </td>
  617. </tr>
  618. <tr>
  619. <td>height</td>
  620. <td>String</td>
  621. <td>"400px"</td>
  622. <td>The height of the graph in pixels or as a percentage.</td>
  623. </tr>
  624. <tr>
  625. <td>nodes.color</td>
  626. <td>String | Object</td>
  627. <td>Object</td>
  628. <td>Default color of the nodes. When color is a string, the color is applied
  629. to both background as well as the border of the node.</td>
  630. </tr>
  631. <tr>
  632. <td>nodes.color.background</td>
  633. <td>String</td>
  634. <td>"#97C2FC"</td>
  635. <td>Default background color of the nodes</td>
  636. </tr>
  637. <tr>
  638. <td>nodes.color.border</td>
  639. <td>String</td>
  640. <td>"#2B7CE9"</td>
  641. <td>Default border color of the nodes</td>
  642. </tr>
  643. <tr>
  644. <td>nodes.color.highlight</td>
  645. <td>String | Object</td>
  646. <td>Object</td>
  647. <td>Default color of the node when the node is selected. Applied to
  648. both border and background of the node.</td>
  649. </tr>
  650. <tr>
  651. <td>nodes.color.highlight.background</td>
  652. <td>String</td>
  653. <td>"#D2E5FF"</td>
  654. <td>Default background color of the node when selected.</td>
  655. </tr>
  656. <tr>
  657. <td>nodes.color.highlight.border</td>
  658. <td>String</td>
  659. <td>"#2B7CE9"</td>
  660. <td>Default border color of the node when selected.</td>
  661. </tr>
  662. <tr>
  663. <td>nodes.fontColor</td>
  664. <td>String</td>
  665. <td>"black"</td>
  666. <td>Default font color for the text label in the nodes.</td>
  667. </tr>
  668. <tr>
  669. <td>nodes.fontFace</td>
  670. <td>String</td>
  671. <td>"sans"</td>
  672. <td>Default font face for the text label in the nodes, for example "verdana" or "arial".</td>
  673. </tr>
  674. <tr>
  675. <td>nodes.fontSize</td>
  676. <td>Number</td>
  677. <td>14</td>
  678. <td>Default font size in pixels for the text label in the nodes.</td>
  679. </tr>
  680. <tr>
  681. <td>nodes.group</td>
  682. <td>String</td>
  683. <td>none</td>
  684. <td>Default group for the nodes.</td>
  685. </tr>
  686. <tr>
  687. <td>nodes.image</td>
  688. <td>String</td>
  689. <td>none</td>
  690. <td>Default image url for the nodes. only applicable with shape <code>image</code>.</td>
  691. </tr>
  692. <tr>
  693. <td>nodes.widthMin</td>
  694. <td>Number</td>
  695. <td>16</td>
  696. <td>The minimum width for a scaled image. Only applicable with shape <code>image</code>.</td>
  697. </tr>
  698. <tr>
  699. <td>nodes.widthMax</td>
  700. <td>Number</td>
  701. <td>64</td>
  702. <td>The maximum width for a scaled image. Only applicable with shape <code>image</code>.</td>
  703. </tr>
  704. <tr>
  705. <td>nodes.shape</td>
  706. <td>String</td>
  707. <td>"ellipse"</td>
  708. <td>The default shape for all nodes.
  709. Choose from
  710. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  711. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  712. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  713. This shape can be overridden by a group shape, or by a shape of an individual node.</td>
  714. </tr>
  715. <tr>
  716. <td>nodes.radius</td>
  717. <td>Number</td>
  718. <td>5</td>
  719. <td>The default radius for a node. Only applicable with shape <code>dot</code>.</td>
  720. </tr>
  721. <tr>
  722. <td>nodes.radiusMin</td>
  723. <td>Number</td>
  724. <td>5</td>
  725. <td>The minimum radius for a scaled node. Only applicable with shape <code>dot</code>.</td>
  726. </tr>
  727. <tr>
  728. <td>nodes.radiusMax</td>
  729. <td>Number</td>
  730. <td>20</td>
  731. <td>The maximum radius for a scaled node. Only applicable with shape <code>dot</code>.</td>
  732. </tr>
  733. <tr>
  734. <td>selectable</td>
  735. <td>Boolean</td>
  736. <td>true</td>
  737. <td>If true, nodes in the graph can be selected by clicking them.
  738. Long press can be used to select multiple nodes.</td>
  739. </tr>
  740. <tr>
  741. <td>stabilize</td>
  742. <td>Boolean</td>
  743. <td>true</td>
  744. <td>If true, the graph is stabilized before displaying it. If false,
  745. the nodes move to a stabe position visibly in an animated way.</td>
  746. </tr>
  747. <tr>
  748. <td>width</td>
  749. <td>String</td>
  750. <td>"400px"</td>
  751. <td>The width of the graph in pixels or as a percentage.</td>
  752. </tr>
  753. </table>
  754. <br>
  755. <h3 id="Groups">Groups</h3>
  756. <p>It is possible to specify custom styles for groups of nodes.
  757. Each node having assigned to this group gets the specified style.
  758. The options <code>groups</code> is an object containing one or multiple groups,
  759. identified by a unique string, the groupname.
  760. </p>
  761. <p>
  762. A group can have the following styles:
  763. </p>
  764. <pre class="prettyprint lang-js">
  765. var options = {
  766. // ...
  767. groups: {
  768. mygroup: {
  769. shape: 'circle',
  770. color: {
  771. border: 'black',
  772. background: 'white',
  773. highlight: {
  774. border: 'yellow',
  775. background: 'orange'
  776. }
  777. }
  778. fontColor: 'red',
  779. fontSize: 18
  780. }
  781. // add more groups here
  782. }
  783. };
  784. var nodes = [
  785. {id: 1, label: 'Node 1'}, // will get the default style
  786. {id: 2, label: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  787. // ... more nodes
  788. ];
  789. </pre>
  790. <p>The following styles are available for groups:</p>
  791. <table>
  792. <tr>
  793. <th>Name</th>
  794. <th>Type</th>
  795. <th>Default</th>
  796. <th>Description</th>
  797. </tr>
  798. <tr>
  799. <td>color</td>
  800. <td>String | Object</td>
  801. <td>Object</td>
  802. <td>Color of the node</td>
  803. </tr>
  804. <tr>
  805. <td>color.border</td>
  806. <td>String</td>
  807. <td>"#2B7CE9"</td>
  808. <td>Border color of the node</td>
  809. </tr>
  810. <tr>
  811. <td>color.background</td>
  812. <td>String</td>
  813. <td>"#97C2FC"</td>
  814. <td>Background color of the node</td>
  815. </tr>
  816. <tr>
  817. <td>color.highlight</td>
  818. <td>String</td>
  819. <td>"#D2E5FF"</td>
  820. <td>Color of the node when selected.</td>
  821. </tr>
  822. <tr>
  823. <td>color.highlight.background</td>
  824. <td>String</td>
  825. <td>"#D2E5FF"</td>
  826. <td>Background color of the node when selected.</td>
  827. </tr>
  828. <tr>
  829. <td>color.highlight.border</td>
  830. <td>String</td>
  831. <td>"#D2E5FF"</td>
  832. <td>Border color of the node when selected.</td>
  833. </tr>
  834. <tr>
  835. <td>image</td>
  836. <td>String</td>
  837. <td>none</td>
  838. <td>Default image for the nodes. Only applicable in combination with
  839. shape <code>image</code>.</td>
  840. </tr>
  841. <tr>
  842. <td>fontColor</td>
  843. <td>String</td>
  844. <td>"black"</td>
  845. <td>Font color of the node.</td>
  846. </tr>
  847. <tr>
  848. <td>fontFace</td>
  849. <td>String</td>
  850. <td>"sans"</td>
  851. <td>Font name of the node, for example "verdana" or "arial".</td>
  852. </tr>
  853. <tr>
  854. <td>fontSize</td>
  855. <td>Number</td>
  856. <td>14</td>
  857. <td>Font size for the node in pixels.</td>
  858. </tr>
  859. <tr>
  860. <td>shape</td>
  861. <td>String</td>
  862. <td>"ellipse"</td>
  863. <td>Choose from
  864. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  865. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  866. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  867. In case of image, a property with name image must be provided, containing
  868. image urls.</td>
  869. </tr>
  870. <tr>
  871. <td>radius</td>
  872. <td>Number</td>
  873. <td>5</td>
  874. <td>Default radius for the node. Only applicable in combination with
  875. shapes <code>box</code> and <code>dot</code>.</td>
  876. </tr>
  877. </table>
  878. <h2 id="Clustering">Clustering</h2>
  879. <p>
  880. The graph now supports dynamic clustering of nodes. This allows a user to view a very large dataset (> 50.000 nodes) without
  881. sacrificing performance. When loading a large dataset, the nodes are clustered initially (this may take a small while) to have a
  882. responsive visualization to work with. The clustering is both outside-in and inside-out. Outside-in means that nodes with only one
  883. connection will be contained, or clustered, in the node it is connected to. Inside-out clustering first determines which nodes are hubs.
  884. Hubs are defined as the nodes with the top 3% highest amount of connections (assuming normal distribution). These hubs then "grow", meaning
  885. 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.
  886. <br />
  887. <br />
  888. 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
  889. to calculate the required forces. The contained nodes are removed from the global nodes index, greatly speeding up the system.
  890. <br />
  891. <br />
  892. The clustering has the following user-configurable settings. The default values have been tested with the Graph examples and work well.
  893. The default state for clustering is <b>off</b>.
  894. </p>
  895. <pre class="prettyprint">
  896. // These variables must be defined in an options object named clustering.
  897. </pre>
  898. <table>
  899. <tr>
  900. <th>Name</th>
  901. <th>Type</th>
  902. <th>Default</th>
  903. <th>Description</th>
  904. </tr>
  905. <tr>
  906. <td>enabled</td>
  907. <td>Boolean</td>
  908. <td>false</td>
  909. <td>On/off switch for clustering. It is assumed clustering is enabled in the descriptions below.</td>
  910. </tr>
  911. <tr>
  912. <td>initialMaxNumberOfNodes</td>
  913. <td>Number</td>
  914. <td>100</td>
  915. <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>
  916. </tr>
  917. <tr>
  918. <td>absoluteMaxNumberOfNodes</td>
  919. <td>Number</td>
  920. <td>500</td>
  921. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  922. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  923. </tr>
  924. <tr>
  925. <td>reduceToMaxNumberOfNodes</td>
  926. <td>Number</td>
  927. <td>300</td>
  928. <td>While zooming in and out, clusters can open up. Once there are more than <code>absoluteMaxNumberOfNodes</code> nodes,
  929. clustering starts until <code>reduceToMaxNumberOfNodes</code> nodes are left. This is done to ensure performance is continiously fluid.</td>
  930. </tr>
  931. <tr>
  932. <td>chainThreshold</td>
  933. <td>Number</td>
  934. <td>0.4</td>
  935. <td>Because of the clustering methods used, long chains of nodes can be formed. To reduce these chains, this threshold is used.
  936. 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).
  937. If there are more, they are clustered together.</td>
  938. </tr>
  939. <tr>
  940. <td>clusterEdgeThreshold</td>
  941. <td>Number</td>
  942. <td>20</td>
  943. <td>This is the absolute edge length threshold in pixels. If the edge is smaller on screen (that means zooming out reduces this length)
  944. the node will be clustered. This is triggered when zooming out.</td>
  945. </tr>
  946. <tr>
  947. <td>sectorThreshold</td>
  948. <td>Integer</td>
  949. <td>50</td>
  950. <td>If a cluster larger than <code>sectorThreshold</code> is opened, a seperate instance called a sector, will be created. All the simulation of
  951. nodes outside of this instance will be paused. This is to maintain performance and clarity when examining large clusters.
  952. 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>
  953. </tr>
  954. <tr>
  955. <td>screenSizeThreshold</td>
  956. <td>Number</td>
  957. <td>0.2</td>
  958. <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
  959. 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
  960. 20%, we collapse this sector.</td>
  961. </tr>
  962. <tr>
  963. <td>fontSizeMultiplier</td>
  964. <td>Number</td>
  965. <td>4.0</td>
  966. <td>This parameter denotes the increase in fontSize of the cluster when a single node is added to it.</td>
  967. </tr>
  968. <tr>
  969. <td>forceAmplification</td>
  970. <td>Number</td>
  971. <td>0.6</td>
  972. <td>This factor is used to calculate the increase of the repulsive force of a cluster. It is calculated by the following
  973. formula: <code>repulsingForce *= 1 + (clusterSize * forceAmplification)</code>.</td>
  974. </tr>
  975. <tr>
  976. <td>distanceAmplification</td>
  977. <td>Number</td>
  978. <td>0.2</td>
  979. <td>This factor is used to calculate the increase in effective range of the repulsive force of the cluster.
  980. A larger cluster has a longer range. It is calculated by the following
  981. formula: <code>minDistance *= 1 + (clusterSize * distanceAmplification)</code>.</td>
  982. </tr>
  983. <tr>
  984. <td>edgeGrowth</td>
  985. <td>Number</td>
  986. <td>11</td>
  987. <td>This factor determines the elongation of edges connected to a cluster.</td>
  988. </tr>
  989. <tr>
  990. <td>clusterSizeWidthFactor</td>
  991. <td>Number</td>
  992. <td>10</td>
  993. <td>This factor determines how much the width of a cluster increases in pixels per added node.</td>
  994. </tr>
  995. <tr>
  996. <td>clusterSizeHeightFactor</td>
  997. <td>Number</td>
  998. <td>10</td>
  999. <td>This factor determines how much the height of a cluster increases in pixels per added node.</td>
  1000. </tr>
  1001. <tr>
  1002. <td>clusterSizeRadiusFactor</td>
  1003. <td>Number</td>
  1004. <td>10</td>
  1005. <td>This factor determines how much the radius of a cluster increases in pixels per added node.</td>
  1006. </tr>
  1007. <tr>
  1008. <td>activeAreaBoxSize</td>
  1009. <td>Number</td>
  1010. <td>100</td>
  1011. <td>Imagine a square with an edge length of <code>activeAreaBoxSize</code> pixels around your cursor.
  1012. If a cluster is in this box as you zoom in, the cluster can be opened in a seperate sector.
  1013. This is regardless of the zoom level.</td>
  1014. </tr>
  1015. </table>
  1016. <h2 id="NavigationUI">Navigation GUI Elements</h2>
  1017. <p>
  1018. As of 0.4.0, a node-based navigation GUI system has been added to vis.js.
  1019. It can be configured with the following user-configurable settings.
  1020. The default state for the GUI navigation elements is <b>off</b>.
  1021. </p>
  1022. <pre class="prettyprint">
  1023. // These variables must be defined in an options object named navigationUI.
  1024. // If a variable is not supplied, the default value is used.
  1025. options: {
  1026. navigationUI: {
  1027. enabled: false,
  1028. initiallyVisible: true,
  1029. enableToggling: true,
  1030. iconPath: this._getIconURL() // automatic loading of the default icons
  1031. },
  1032. }
  1033. </pre>
  1034. <table>
  1035. <tr>
  1036. <th>Name</th>
  1037. <th>Type</th>
  1038. <th>Default</th>
  1039. <th>Description</th>
  1040. </tr>
  1041. <tr>
  1042. <td>enabled</td>
  1043. <td>Boolean</td>
  1044. <td>false</td>
  1045. <td>On/off switch for the navigation UI elements.</td>
  1046. </tr>
  1047. <tr>
  1048. <td>initiallyVisible</td>
  1049. <td>Boolean</td>
  1050. <td>true</td>
  1051. <td>The UI elements can be toggled by pressing the "u" key. If <code>initiallyVisible</code> is false, the UI is hidden
  1052. until "u" is pressed on the keyboard.
  1053. </td>
  1054. </tr>
  1055. <tr>
  1056. <td>enableToggling</td>
  1057. <td>Boolean</td>
  1058. <td>true</td>
  1059. <td>Enable or disable the option to press "u" to toggle the UI elements. If the UI is initially hidden and the toggling is off, the UI cannot be used!</td>
  1060. </tr>
  1061. <tr>
  1062. <td>iconPath</td>
  1063. <td>string</td>
  1064. <td>[path to vis.js]/UI_icons/</td>
  1065. <td>The path to the icon images can be defined here. If custom icons are used, they have to have the same filename as the ones originally packaged with vis.js.</td>
  1066. </tr>
  1067. </table>
  1068. <h2 id="Keyboard">Keyboard Navigation</h2>
  1069. <p>
  1070. As of 0.4.0, keyboard navigation has been added to vis.js.
  1071. It can be configured with the following user-configurable settings.
  1072. The default state for the keyboard navigation is <b>off</b>. The predefined keys can be found in the <a href="../examples/graph/20_UI_example.html">UI example.</a>
  1073. </p>
  1074. <pre class="prettyprint">
  1075. // These variables must be defined in an options object named keyboardNavigation.
  1076. // If a variable is not supplied, the default value is used
  1077. options: {
  1078. keyboardNavigation: {
  1079. enabled: false,
  1080. xMovementSpeed: 10,
  1081. yMovementSpeed: 10,
  1082. zoomMovementSpeed: 0.02
  1083. }
  1084. }
  1085. </pre>
  1086. <table>
  1087. <tr>
  1088. <th>Name</th>
  1089. <th>Type</th>
  1090. <th>Default</th>
  1091. <th>Description</th>
  1092. </tr>
  1093. <tr>
  1094. <td>enabled</td>
  1095. <td>Boolean</td>
  1096. <td>false</td>
  1097. <td>On/off switch for the keyboard navigation.</td>
  1098. </tr>
  1099. <tr>
  1100. <td>xMovementSpeed</td>
  1101. <td>Number</td>
  1102. <td>10</td>
  1103. <td>This defines the speed of the camera movement in the x direction when using the keyboard navigation.
  1104. </td>
  1105. </tr>
  1106. <tr>
  1107. <td>yMovementSpeed</td>
  1108. <td>Boolean</td>
  1109. <td>10</td>
  1110. <td>This defines the speed of the camera movement in the y direction when using the keyboard navigation.</td>
  1111. </tr>
  1112. <tr>
  1113. <td>zoomMovementSpeed</td>
  1114. <td>string</td>
  1115. <td>0.02</td>
  1116. <td>This defines the zoomspeed when using the keyboard navigation.</td>
  1117. </tr>
  1118. </table>
  1119. <h2 id="Methods">Methods</h2>
  1120. <p>
  1121. Graph supports the following methods.
  1122. </p>
  1123. <table>
  1124. <tr>
  1125. <th>Method</th>
  1126. <th>Return Type</th>
  1127. <th>Description</th>
  1128. </tr>
  1129. <tr>
  1130. <td>setData(data,[disableStart])</td>
  1131. <td>none</td>
  1132. <td>Loads data. Parameter <code>data</code> is an object containing
  1133. nodes, edges, and options. Parameters nodes, edges are an Array.
  1134. Options is a name-value map and is optional. Parameter <code>disableStart</code> is
  1135. an optional Boolean and can disable the start of the simulation that would begin at the end
  1136. of this function by default.
  1137. </td>
  1138. </tr>
  1139. <tr>
  1140. <td>setOptions(options)</td>
  1141. <td>none</td>
  1142. <td>Set options for the graph. The available options are described in
  1143. the section <a href="#Configuration_Options">Configuration Options</a>.
  1144. </td>
  1145. </tr>
  1146. <tr>
  1147. <td>getSelection()</td>
  1148. <td>Array of ids</td>
  1149. <td>Returns an array with the ids of the selected nodes.
  1150. Returns an empty array if no nodes are selected.
  1151. The selections are not ordered.
  1152. </td>
  1153. </tr>
  1154. <tr>
  1155. <td>redraw()</td>
  1156. <td>none</td>
  1157. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  1158. </tr>
  1159. <tr>
  1160. <td>setSelection(selection)</td>
  1161. <td>none</td>
  1162. <td>Select nodes.
  1163. <code>selection</code> is an array with ids of nodes to be selected.
  1164. The array <code>selection</code> can contain zero or multiple ids.
  1165. Example usage: <code>graph.setSelection([3, 5]);</code> will select
  1166. nodes with id 3 and 5.
  1167. </td>
  1168. </tr>
  1169. <tr>
  1170. <td>setSize(width, height)</td>
  1171. <td>none</td>
  1172. <td>Parameters <code>width</code> and <code>height</code> are strings,
  1173. containing a new size for the visualization. Size can be provided in pixels
  1174. or in percentages.</td>
  1175. </tr>
  1176. </table>
  1177. <h2 id="Events">Events</h2>
  1178. <p>
  1179. Graph fires events after one or multiple nodes are selected.
  1180. The event can be catched by creating a listener.
  1181. </p>
  1182. <p>
  1183. Here an example on how to catch a <code>select</code> event.
  1184. </p>
  1185. <pre class="prettyprint lang-js">
  1186. function onSelect() {
  1187. alert('selected nodes: ' + graph.getSelection());
  1188. }
  1189. vis.events.addListener(graph, 'select', onSelect);
  1190. </pre>
  1191. <p>
  1192. The following events are available.
  1193. </p>
  1194. <table>
  1195. <col width="10%">
  1196. <col width="60%">
  1197. <col width="30%">
  1198. <tr>
  1199. <th>name</th>
  1200. <th>Description</th>
  1201. <th>Properties</th>
  1202. </tr>
  1203. <tr>
  1204. <td>select</td>
  1205. <td>Fired after the user selects or unselects a node by clicking it,
  1206. or when selecting a number of nodes by dragging a selection area
  1207. around them. Not fired when the method <code>setSelection</code>
  1208. is executed. The ids of the selected nodes can be retrieved via the
  1209. method <code>getSelection</code>.
  1210. </td>
  1211. <td>none</td>
  1212. </tr>
  1213. </table>
  1214. <h2 id="Data_Policy">Data Policy</h2>
  1215. <p>
  1216. All code and data is processed and rendered in the browser.
  1217. No data is sent to any server.
  1218. </p>
  1219. </div>
  1220. </body>
  1221. </html>