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.

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