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.

1165 lines
31 KiB

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Graph documentation</title>
  5. <link rel='stylesheet' href='css/style.css' type='text/css' />
  6. <link href="prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="prettify/prettify.js"></script>
  8. <style>
  9. pre.prettyprint {
  10. border-color: lightgray;
  11. }
  12. </style>
  13. </head>
  14. <body onload="prettyPrint();">
  15. <div id="container">
  16. <h1>Graph documentation</h1>
  17. <table>
  18. <tr>
  19. <td>Author</td>
  20. <td>Jos de Jong, <a href="http://www.almende.com" target="_blank">Almende B.V.</a></td>
  21. </tr>
  22. <tr>
  23. <td>Webpage</td>
  24. <td><a href="http://visjs.org" target="_blank">http://visjs.org</a></td>
  25. </tr>
  26. <tr>
  27. <td>License</td>
  28. <td> <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Apache License, Version 2.0</a></td>
  29. </tr>
  30. </table>
  31. <h2><a name="Contents"></a>Contents</h2>
  32. <ul>
  33. <li><a href="#Overview">Overview</a></li>
  34. <li><a href="#Example">Example</a></li>
  35. <li><a href="#Loading">Loading</a></li>
  36. <li><a href="#Data_Format">Data Format</a></li>
  37. <li><a href="#Data_Import">Data Import</a></li>
  38. <li><a href="#Configuration_Options">Configuration Options</a></li>
  39. <li><a href="#Methods">Methods</a></li>
  40. <li><a href="#Events">Events</a></li>
  41. <li><a href="#Data_Policy">Data Policy</a></li>
  42. </ul>
  43. <h2><a name="Overview"></a>Overview</h2>
  44. <p>
  45. Graph is a visualization to display graphs and networks consisting of nodes
  46. and edges. The visualization is easy to use and supports custom styles,
  47. colors, sizes, images, and more.
  48. </p>
  49. <p>
  50. The graph visualization works smooth on any modern browser for up to a
  51. few hundred nodes and edges.
  52. </p>
  53. <p>
  54. To get started with Graph, install or download the
  55. <a href="http://visjs.org" target="_blank">vis.js</a> library.
  56. </p>
  57. <h2><a name="Example"></a>Example</h2>
  58. <p>
  59. Here a basic graph example. More examples can be found in the
  60. <a href="../examples" target="_blank">examples directory</a>.
  61. </p>
  62. <pre class="prettyprint lang-html">&lt;!doctype html&gt;
  63. &lt;html&gt;
  64. &lt;head&gt;
  65. &lt;title&gt;Graph | Basic usage&lt;/title&gt;
  66. &lt;script type="text/javascript" src="../../vis.js"&gt;&lt;/script&gt;
  67. &lt;/head&gt;
  68. &lt;body&gt;
  69. &lt;div id="mygraph"&gt;&lt;/div&gt;
  70. &lt;script type="text/javascript"&gt;
  71. // create an array with nodes
  72. var nodes = [
  73. {id: 1, text: 'Node 1'},
  74. {id: 2, text: 'Node 2'},
  75. {id: 3, text: 'Node 3'},
  76. {id: 4, text: 'Node 4'},
  77. {id: 5, text: 'Node 5'}
  78. ];
  79. // create an array with edges
  80. var edges = [
  81. {from: 1, to: 2},
  82. {from: 1, to: 3},
  83. {from: 2, to: 4},
  84. {from: 2, to: 5}
  85. ];
  86. // create a graph
  87. var container = document.getElementById('mygraph');
  88. var data= {
  89. nodes: nodes,
  90. edges: edges,
  91. };
  92. var options = {
  93. width: '400px',
  94. height: '400px'
  95. };
  96. var graph = new vis.Graph(container, data, options);
  97. &lt;/script&gt;
  98. &lt;/body&gt;
  99. &lt;/html&gt;
  100. </pre>
  101. <h2><a name="Loading"></a>Loading</h2>
  102. <p>
  103. Install or download the <a href="http://visjs.org" target="_blank">vis.js</a> library.
  104. in a subfolder of your project. Include the library script in the head of your html code:
  105. </p>
  106. <pre class="prettyprint lang-html">
  107. &lt;script type="text/javascript" src="vis/vis.js"&gt;&lt;/script&gt;
  108. </pre>
  109. The class name of the Graph is <code>vis.Graph</code>.
  110. <pre class="prettyprint lang-js">var graph = new vis.Graph(container, data, options);</pre>
  111. The constructor accepts three parameters:
  112. <ul>
  113. <li>
  114. <code>container</code> is the DOM element in which to create the graph.
  115. </li>
  116. <li>
  117. <code>data</code> is an Object containing properties <code>nodes</code> and
  118. <code>edges</code>, which both contain an array with objects.
  119. Optionally, data may contain an <code>options</code> object.
  120. The parameter <code>data</code> is optional, data can also be set using
  121. the method <code>setData</code>.
  122. </li>
  123. <li>
  124. <code>options</code> is an optional Object containing a name-value map
  125. with options. Options can also be set using the method
  126. <code>setOptions</code>.
  127. </li>
  128. </ul>
  129. <h2><a name="Data_Format"></a>Data Format</h2>
  130. <p>
  131. The Graph draws nodes and edges, which are both an Array with objects.
  132. This section describes the data format of nodes and edges.
  133. </p>
  134. <h3>Nodes</h3>
  135. <p>
  136. Nodes typically have an <code>id</code> and <code>text</code>.
  137. A node must contain at least a property <code>id</code>.
  138. Nodes can have extra properties, used to define the type and style the
  139. nodes.
  140. </p>
  141. <p>
  142. A JavaScript Array with nodes is constructed like:
  143. </p>
  144. <pre class="prettyprint lang-js">
  145. var nodes = [
  146. {
  147. 'id': 1,
  148. 'text': 'Node 1'
  149. },
  150. // ... more data
  151. ];
  152. </pre>
  153. <p>
  154. Nodes support the following properties:
  155. </p>
  156. <table>
  157. <tr>
  158. <th>Name</th>
  159. <th>Type</th>
  160. <th>Required</th>
  161. <th>Description</th>
  162. </tr>
  163. <tr>
  164. <td>action</td>
  165. <td>string</td>
  166. <td>no</td>
  167. <td>By specifying <code>action</code>, a node can be created, updated,
  168. or deleted. This is useful in combination with <code>timestamp</code>
  169. to animate history, or for dynamically updating the graph.
  170. Available values are: <code>create</code>,
  171. <code>update</code> (default), or <code>delete</code>.
  172. </td>
  173. </tr>
  174. <tr>
  175. <td>backgroundColor</td>
  176. <td>String</td>
  177. <td>"#97C2FC"</td>
  178. <td>Background color for the node.</td>
  179. </tr>
  180. <tr>
  181. <td>borderColor</td>
  182. <td>String</td>
  183. <td>"#2B7CE9"</td>
  184. <td>Border color for the node.</td>
  185. </tr>
  186. <tr>
  187. <td>group</td>
  188. <td>*</td>
  189. <td>no</td>
  190. <td>A group number or name. The type can be <code>number</code>,
  191. <code>string</code>, or an other type. All nodes with the same group get
  192. the same color schema.</td>
  193. </tr>
  194. <tr>
  195. <td>fontColor</td>
  196. <td>String</td>
  197. <td>"black"</td>
  198. <td>Font color for text in the node.</td>
  199. </tr>
  200. <tr>
  201. <td>fontFace</td>
  202. <td>String</td>
  203. <td>"sans"</td>
  204. <td>Font face for text in the node, for example "verdana" or "arial".</td>
  205. </tr>
  206. <tr>
  207. <td>fontSize</td>
  208. <td>Number</td>
  209. <td>14</td>
  210. <td>Font size in pixels for text in the node.</td>
  211. </tr>
  212. <tr>
  213. <td>highlightColor</td>
  214. <td>String</td>
  215. <td>"#D2E5FF"</td>
  216. <td>Background color of the node when selected.</td>
  217. </tr>
  218. <tr>
  219. <td>id</td>
  220. <td>*</td>
  221. <td>yes</td>
  222. <td>A unique id for this node.
  223. Nodes may not have duplicate id's.
  224. Id's do not need to be consecutive.
  225. An id is normally a number, but may be any type.</td>
  226. </tr>
  227. <tr>
  228. <td>image</td>
  229. <td>string</td>
  230. <td>no</td>
  231. <td>Url of an image. Only applicable when the style of the node is
  232. <code>image</code>.</td>
  233. </tr>
  234. <tr>
  235. <td>radius</td>
  236. <td>number</td>
  237. <td>no</td>
  238. <td>Radius for the node. Applicable for all styles except <code>rect</code>,
  239. <code>circle</code>, and <code>database</code>.
  240. The value of <code>radius</code> will override a value in
  241. property <code>value</code>.</td>
  242. </tr>
  243. <tr>
  244. <td>style</td>
  245. <td>string</td>
  246. <td>no</td>
  247. <td>Define the shape for the node.
  248. Choose from <code>rect</code> (default), <code>circle</code>,
  249. <code>database</code>, <code>image</code>, <code>text</code>,
  250. <code>dot</code>, <code>star</code>, <code>triangle</code>,
  251. <code>triangleDown</code>, and <code>square</code>.
  252. <br><br>
  253. In case of <code>image</code>, a property with name <code>image</code> must
  254. be provided, containing image urls.
  255. <br><br>
  256. The shapes <code>dot</code>, <code>star</code>, <code>triangle</code>,
  257. <code>triangleDown</code>, and <code>square</code>, are scalable.
  258. The size is determined by the properties <code>radius</code> or
  259. <code>value</code>.
  260. <br><br>
  261. When a property <code>text</code> is provided,
  262. this text will be displayed inside the shape in case of styles
  263. <code>rect</code>, <code>circle</code>, and <code>database</code>.
  264. For all other shapes, the text will be displayed right below the shape.
  265. </td>
  266. </tr>
  267. <tr>
  268. <td>text</td>
  269. <td>string</td>
  270. <td>no</td>
  271. <td>Text to be displayed in the node or under the image of the node.
  272. Multiple lines can be separated by a newline character <code>\n</code> .</td>
  273. </tr>
  274. <tr>
  275. <td>timestamp</td>
  276. <td>Date | Number</td>
  277. <td>no</td>
  278. <td>Timestamp used for filtering nodes when animating.
  279. See section <a href="#Animation">Animation</a> for more information.</td>
  280. </tr>
  281. <tr>
  282. <td>title</td>
  283. <td>string</td>
  284. <td>no</td>
  285. <td>Title to be displayed when the user hovers over the node.
  286. The title can contain HTML code.</td>
  287. </tr>
  288. <tr>
  289. <td>value</td>
  290. <td>number</td>
  291. <td>no</td>
  292. <td>A value for the node.
  293. The radius of the nodes will be scaled automatically from minimum to
  294. maximum value.
  295. Only applicable when the style of the node is <code>dot</code>.
  296. If a <code>radius</code> is provided for the node too, it will override the
  297. radius calculated from the value.</td>
  298. </tr>
  299. <tr>
  300. <td>x</td>
  301. <td>number</td>
  302. <td>no</td>
  303. <td>Horizontal position in pixels.
  304. The horizontal position of the node will be fixed.
  305. The vertical position y may remain undefined.</td>
  306. </tr>
  307. <tr>
  308. <td>y</td>
  309. <td>number</td>
  310. <td>no</td>
  311. <td>Vertical position in pixels.
  312. The vertical position of the node will be fixed.
  313. The horizontal position x may remain undefined.</td>
  314. </tr>
  315. </table>
  316. <h3>Edges</h3>
  317. <p>
  318. Edges are connections between nodes.
  319. An edge must at least contain properties <code>from</code> and
  320. <code>to</code>, both referring to the <code>id</code> of a node.
  321. Edges can have extra properties, used to define the type and style.
  322. </p>
  323. <p>
  324. A JavaScript Array with edges is constructed as:
  325. </p>
  326. <pre class="prettyprint lang-js">
  327. var edges= [
  328. {
  329. 'from': 1,
  330. 'to': 3
  331. },
  332. // ... more data
  333. ];
  334. </pre>
  335. <p>
  336. Edges support the following properties:
  337. </p>
  338. <table>
  339. <tr>
  340. <th>Name</th>
  341. <th>Type</th>
  342. <th>Required</th>
  343. <th>Description</th>
  344. </tr>
  345. <tr>
  346. <td>action</td>
  347. <td>string</td>
  348. <td>no</td>
  349. <td>By specifying <code>action</code>, a link can be created, updated,
  350. or deleted. This is useful in combination with <code>timestamp</code>
  351. to animate history, or for dynamically updating the graph.
  352. An action on a link can only be used when the link has an id.
  353. Available values are: <code>create</code> (default),
  354. <code>update</code>, or <code>delete</code>.
  355. </td>
  356. </tr>
  357. <tr>
  358. <td>altdashlength</td>
  359. <td>number</td>
  360. <td>no</td>
  361. <td>Length of the alternated dash in pixels on a dashed line.
  362. Specifying <code>altdashlength</code> allows for creating
  363. a dashed line with a dash-dot style, for example when
  364. <code>dashlength=10</code> and <code>altdashlength=5</code>.
  365. See also the option <code>dashlength</code>.
  366. Only applicable when the line style is <code>dash-line</code>.</td>
  367. </tr>
  368. <tr>
  369. <td>color</td>
  370. <td>string</td>
  371. <td>no</td>
  372. <td>A HTML color for the link.</td>
  373. </tr>
  374. <tr>
  375. <td>dashlength</td>
  376. <td>number</td>
  377. <td>no</td>
  378. <td>Length of a dash in pixels on a dashed line.
  379. Only applicable when the line style is <code>dash-line</code>.</td>
  380. </tr>
  381. <tr>
  382. <td>dashgap</td>
  383. <td>number</td>
  384. <td>no</td>
  385. <td>Length of a gap in pixels on a dashed line.
  386. Only applicable when the line style is <code>dash-line</code>.</td>
  387. </tr>
  388. <tr>
  389. <td>fontColor</td>
  390. <td>String</td>
  391. <td>"black"</td>
  392. <td>Font color for the text label of the link.
  393. Only applicable when "text" is defined.</td>
  394. </tr>
  395. <tr>
  396. <td>fontFace</td>
  397. <td>String</td>
  398. <td>"sans"</td>
  399. <td>Font face for the text label of the link,
  400. for example "verdana" or "arial".
  401. Only applicable when "text" is defined.</td>
  402. </tr>
  403. <tr>
  404. <td>fontSize</td>
  405. <td>Number</td>
  406. <td>14</td>
  407. <td>Font size in pixels for the text label of the link.
  408. Only applicable when "text" is defined.</td>
  409. </tr>
  410. <tr>
  411. <td>from</td>
  412. <td>*</td>
  413. <td>yes</td>
  414. <td>The id of a node where the link starts. The type must correspond with
  415. the type of the node id's. This is normally a number, but can be any
  416. type.</td>
  417. </tr>
  418. <tr>
  419. <td>length</td>
  420. <td>number</td>
  421. <td>no</td>
  422. <td>The length of the link in pixels.</td>
  423. </tr>
  424. <tr>
  425. <td>style</td>
  426. <td>string</td>
  427. <td>no</td>
  428. <td>Define a drawing style for the link.
  429. Choose from <code>line</code> (default), <code>arrow</code>,
  430. <code>arrow-end</code>, or <code>dash-line</code>.
  431. </td>
  432. </tr>
  433. <tr>
  434. <td>text</td>
  435. <td>string</td>
  436. <td>no</td>
  437. <td>Text to be displayed halfway the link.</td>
  438. </tr>
  439. <tr>
  440. <td>timestamp</td>
  441. <td>Date | Number</td>
  442. <td>no</td>
  443. <td>Timestamp used for filtering edges when animating.
  444. See section <a href="#Animation">Animation</a> for more information.</td>
  445. </tr>
  446. <tr>
  447. <td>title</td>
  448. <td>string</td>
  449. <td>no</td>
  450. <td>Title to be displayed when the user hovers over the link.
  451. The title can contain HTML code.</td>
  452. </tr>
  453. <tr>
  454. <td>to</td>
  455. <td>*</td>
  456. <td>yes</td>
  457. <td>The id of a node where the link ends. The type must correspond with
  458. the type of the node id's. This is normally a number, but can be any
  459. type.</td>
  460. </tr>
  461. <tr>
  462. <td>value</td>
  463. <td>number</td>
  464. <td>no</td>
  465. <td>A value for the link.
  466. The width of the edges will be scaled automatically from minimum to
  467. maximum value.
  468. If a <code>width</code> is provided for the link too, it will override the
  469. width calculated from the value.</td>
  470. </tr>
  471. <tr>
  472. <td>width</td>
  473. <td>number</td>
  474. <td>no</td>
  475. <td>Width of the line in pixels. The <code>width</code> will
  476. override a specified <code>value</code>, if a <code>value</code> is
  477. specified too.</td>
  478. </tr>
  479. </table>
  480. <h2><a name="Data_Import"></a>Data Import</h2>
  481. <p>
  482. Graph contains parser to import data in the
  483. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  484. There following methods are available:
  485. </p>
  486. <table>
  487. <tr>
  488. <th>Method</th>
  489. <th>Return Type</th>
  490. <th>Description</th>
  491. </tr>
  492. <tr>
  493. <td>vis.Graph.util.parseDOT(data)</td>
  494. <td>Object</td>
  495. <td>
  496. Parse a string containing data in DOT language into a JSON object.
  497. The returned object contains two arrays, <code>nodes</code>,
  498. <code>edges</code>, containing the parsed nodes and edges.
  499. </td>
  500. </tr>
  501. <tr>
  502. <td>vis.Graph.util.DOTToGraph(data)</td>
  503. <td>Object</td>
  504. <td>
  505. Convert a string containing a graph in DOT language into a map
  506. containing with nodes and edges in the format of Graph.
  507. The returned object contains parameters <code>nodes</code>,
  508. <code>edges</code>, and <code>options</code>, which can be used
  509. directly to draw a graph using <code>setData(data)</code>.
  510. </td>
  511. </tr>
  512. </table>
  513. <p>
  514. Example usage:
  515. </p>
  516. <pre class="prettyprint lang-js">
  517. // parse data in DOT-notation
  518. var dot = 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }';
  519. var data = vis.Graph.util.DOTToGraph(dot);
  520. // create a graph
  521. var graph = new vis.Graph(container, data);
  522. </pre>
  523. <h2><a name="Configuration_Options"></a>Configuration Options</h2>
  524. <p>
  525. Options can be used to customize the graph. Options are defined as a JSON object.
  526. All options are optional.
  527. </p>
  528. <pre class="prettyprint lang-js">
  529. var options = {
  530. 'width': '100%',
  531. 'height': '400px',
  532. 'edges': {
  533. 'color': 'red',
  534. 'width': 2
  535. }
  536. };
  537. </pre>
  538. <p>
  539. The following options are available.
  540. </p>
  541. <table>
  542. <tr>
  543. <th>Name</th>
  544. <th>Type</th>
  545. <th>Default</th>
  546. <th>Description</th>
  547. </tr>
  548. <tr>
  549. <td>backgroundColor</td>
  550. <td>String or Object</td>
  551. <td>"white"</td>
  552. <td>The background color for the main area of the chart.
  553. Can be either a simple HTML color string, for example: 'red' or '#00cc00',
  554. or an object with optional properties stroke, strokeWidth, and fill.</td>
  555. </tr>
  556. <tr>
  557. <td>backgroundColor.stroke</td>
  558. <td>String</td>
  559. <td>"#666"</td>
  560. <td>The color of the chart border, as an HTML color string.</td>
  561. </tr>
  562. <tr>
  563. <td>backgroundColor.strokeWidth</td>
  564. <td>Number</td>
  565. <td>1</td>
  566. <td>The border width, in pixels.</td>
  567. </tr>
  568. <tr>
  569. <td>backgroundColor.fill</td>
  570. <td>String</td>
  571. <td>"white"</td>
  572. <td>The chart fill color, as an HTML color string.</td>
  573. </tr>
  574. <tr>
  575. <td>groups</td>
  576. <td>Object</td>
  577. <td>none</td>
  578. <td>It is possible to specify custom styles for groups.
  579. Each node assigned a group gets the specified style.
  580. See <a href="#Groups">Groups</a> for an overview of the available styles
  581. and an example.
  582. </td>
  583. </tr>
  584. <tr>
  585. <td>height</td>
  586. <td>String</td>
  587. <td>"400px"</td>
  588. <td>The height of the graph in pixels or as a percentage.</td>
  589. </tr>
  590. <tr>
  591. <td>edges.altdashlength</td>
  592. <td>number</td>
  593. <td>none</td>
  594. <td>Length of the alternated dash in pixels on a dashed line.
  595. Specifying <code>altdashlength</code> allows for creating
  596. a dashed line with a dash-dot style, for example when
  597. <code>dashlength=10</code> and <code>altdashlength=5</code>.
  598. See also the option <code>dashlength</code>.
  599. Only applicable when the line style is <code>dash-line</code>.</td>
  600. </tr>
  601. <tr>
  602. <td>edges.color</td>
  603. <td>String</td>
  604. <td>"#2B7CE9"</td>
  605. <td>The default color of a link.</td>
  606. </tr>
  607. <tr>
  608. <td>edges.dashlength</td>
  609. <td>number</td>
  610. <td>10</td>
  611. <td>Length of a dash in pixels on a dashed line.
  612. Only applicable when the line style is <code>dash-line</code>.</td>
  613. </tr>
  614. <tr>
  615. <td>edges.dashgap</td>
  616. <td>number</td>
  617. <td>5</td>
  618. <td>Length of a gap in pixels on a dashed line.
  619. Only applicable when the line style is <code>dash-line</code>.</td>
  620. </tr>
  621. <tr>
  622. <td>edges.length</td>
  623. <td>Number</td>
  624. <td>100</td>
  625. <td>The default length of a link.</td>
  626. </tr>
  627. <tr>
  628. <td>edges.style</td>
  629. <td>String</td>
  630. <td>"line"</td>
  631. <td>The default style of a link.
  632. Choose from <code>line</code> (default), <code>arrow</code>,
  633. <code>arrow-end</code>, <code>dash-line</code>.</td>
  634. </tr>
  635. <tr>
  636. <td>edges.width</td>
  637. <td>Number</td>
  638. <td>1</td>
  639. <td>The default width of a link.</td>
  640. </tr>
  641. <tr>
  642. <td>nodes.borderColor</td>
  643. <td>String</td>
  644. <td>"#2B7CE9"</td>
  645. <td>Default border color of the nodes</td>
  646. </tr>
  647. <tr>
  648. <td>nodes.backgroundColor</td>
  649. <td>String</td>
  650. <td>"#97C2FC"</td>
  651. <td>Default background color of the nodes</td>
  652. </tr>
  653. <tr>
  654. <td>nodes.highlightColor</td>
  655. <td>String</td>
  656. <td>"#D2E5FF"</td>
  657. <td>Default background color of the node when the node is selected.</td>
  658. </tr>
  659. <tr>
  660. <td>nodes.fontColor</td>
  661. <td>String</td>
  662. <td>"black"</td>
  663. <td>Default font color for text in the nodes.</td>
  664. </tr>
  665. <tr>
  666. <td>nodes.fontFace</td>
  667. <td>String</td>
  668. <td>"sans"</td>
  669. <td>Default font face for text in the nodes, for example "verdana" or "arial".</td>
  670. </tr>
  671. <tr>
  672. <td>nodes.fontSize</td>
  673. <td>Number</td>
  674. <td>14</td>
  675. <td>Default font size in pixels for text in the nodes.</td>
  676. </tr>
  677. <tr>
  678. <td>nodes.group</td>
  679. <td>String</td>
  680. <td>none</td>
  681. <td>Default group for the nodes.</td>
  682. </tr>
  683. <tr>
  684. <td>nodes.image</td>
  685. <td>String</td>
  686. <td>none</td>
  687. <td>Default image url for the nodes. only applicable with style <code>image</code>.</td>
  688. </tr>
  689. <tr>
  690. <td>nodes.widthMin</td>
  691. <td>Number</td>
  692. <td>16</td>
  693. <td>The minimum width for a scaled image. Only applicable with style <code>image</code>.</td>
  694. </tr>
  695. <tr>
  696. <td>nodes.widthMax</td>
  697. <td>Number</td>
  698. <td>64</td>
  699. <td>The maximum width for a scaled image. Only applicable with style <code>image</code>.</td>
  700. </tr>
  701. <tr>
  702. <td>nodes.style</td>
  703. <td>String</td>
  704. <td>"rect"</td>
  705. <td>The default style for all nodes.
  706. Choose from <code>rect</code> (default), <code>circle</code>,
  707. <code>database</code>, <code>image</code>, <code>text</code>, <code>dot</code>.
  708. This style can be overridden by a group style, or by a style of an individual node.</td>
  709. </tr>
  710. <tr>
  711. <td>nodes.radius</td>
  712. <td>Number</td>
  713. <td>5</td>
  714. <td>The default radius for a node. Only applicable with style <code>dot</code>.</td>
  715. </tr>
  716. <tr>
  717. <td>nodes.radiusMin</td>
  718. <td>Number</td>
  719. <td>5</td>
  720. <td>The minimum radius for a scaled node. Only applicable with style <code>dot</code>.</td>
  721. </tr>
  722. <tr>
  723. <td>nodes.radiusMax</td>
  724. <td>Number</td>
  725. <td>20</td>
  726. <td>The maximum radius for a scaled node. Only applicable with style <code>dot</code>.</td>
  727. </tr>
  728. <tr>
  729. <td>selectable</td>
  730. <td>Boolean</td>
  731. <td>true</td>
  732. <td>If true, nodes in the graph can be selected by clicking them, or
  733. by keeping the <code>Shift</code> key down and dragging a selection area around them.
  734. When the <code>Ctrl</code> key is down, the new selection is appended to the
  735. previous selection. If not, the new selection replaces the previous selection.</td>
  736. </tr>
  737. <tr>
  738. <td>stabilize</td>
  739. <td>Boolean</td>
  740. <td>true</td>
  741. <td>If true, the graph is stabilized before displaying it. If false,
  742. the nodes move to a stabe position visibly in an animated way.</td>
  743. </tr>
  744. <tr>
  745. <td>width</td>
  746. <td>String</td>
  747. <td>"400px"</td>
  748. <td>The width of the graph in pixels or as a percentage.</td>
  749. </tr>
  750. </table>
  751. <br>
  752. <h3><a name="Groups"></a>Groups</h3>
  753. <p>It is possible to specify custom styles for groups of nodes.
  754. Each node having assigned to this group gets the specified style.
  755. The options <code>groups</code> is an object containing one or multiple groups,
  756. identified by a unique string, the groupname.
  757. </p>
  758. <p>
  759. A group can have the following styles:
  760. </p>
  761. <pre class="prettyprint lang-js">
  762. var options = {
  763. // ...
  764. 'groups': {
  765. 'mygroup': {
  766. 'style': 'circle',
  767. 'borderColor': 'black',
  768. 'backgroundColor': 'white',
  769. 'fontColor': 'red',
  770. 'fontSize': 18,
  771. 'highlightColor': 'yellow'
  772. }
  773. // add more groups here
  774. }
  775. };
  776. var nodes = [
  777. {id: 1, text: 'Node 1'}, // will get the default style
  778. {id: 2, text: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  779. // ... more data
  780. ];
  781. </pre>
  782. <p>The following styles are available for groups:</p>
  783. <table>
  784. <tr>
  785. <th>Name</th>
  786. <th>Type</th>
  787. <th>Default</th>
  788. <th>Description</th>
  789. </tr>
  790. <tr>
  791. <td>borderColor</td>
  792. <td>String</td>
  793. <td>"#2B7CE9"</td>
  794. <td>Border color of the node</td>
  795. </tr>
  796. <tr>
  797. <td>backgroundColor</td>
  798. <td>String</td>
  799. <td>"#97C2FC"</td>
  800. <td>Background color of the node</td>
  801. </tr>
  802. <tr>
  803. <td>highlightColor</td>
  804. <td>String</td>
  805. <td>"#D2E5FF"</td>
  806. <td>Background color of the node when the node is selected.</td>
  807. </tr>
  808. <tr>
  809. <td>image</td>
  810. <td>String</td>
  811. <td>none</td>
  812. <td>Default image for the nodes. Only applicable in combination with
  813. style <code>image</code>.</td>
  814. </tr>
  815. <tr>
  816. <td>fontColor</td>
  817. <td>String</td>
  818. <td>"black"</td>
  819. <td>Font color of the node.</td>
  820. </tr>
  821. <tr>
  822. <td>fontFace</td>
  823. <td>String</td>
  824. <td>"sans"</td>
  825. <td>Font name of the node, for example "verdana" or "arial".</td>
  826. </tr>
  827. <tr>
  828. <td>fontSize</td>
  829. <td>Number</td>
  830. <td>14</td>
  831. <td>Font size for the node in pixels.</td>
  832. </tr>
  833. <tr>
  834. <td>style</td>
  835. <td>String</td>
  836. <td>"rect"</td>
  837. <td>Choose from <code>rect</code> (default), <code>circle</code>,
  838. <code>database</code>, <code>image</code>, <code>text</code>,
  839. <code>dot</code>.
  840. In case of image, a property with name image must be provided, containing
  841. image urls.</td>
  842. </tr>
  843. <tr>
  844. <td>radius</td>
  845. <td>Number</td>
  846. <td>5</td>
  847. <td>Default radius for the node. Only applicable in combination with
  848. styles <code>rect</code> and <code>dot</code>.</td>
  849. </tr>
  850. </table>
  851. <h2><a name="Methods"></a>Methods</h2>
  852. <p>
  853. Graph supports the following methods.
  854. </p>
  855. <table>
  856. <tr>
  857. <th>Method</th>
  858. <th>Return Type</th>
  859. <th>Description</th>
  860. </tr>
  861. <tr>
  862. <td>animationSetAcceleration(acceleration)</td>
  863. <td>none</td>
  864. <td>Set the time acceleration for animation of history.
  865. Only applicable when packages with a timestamp are available.
  866. When acceleration is 1, history is played in real time.
  867. And for example acceleration of 10 will play history then times the speed of
  868. real time.</td>
  869. </tr>
  870. <tr>
  871. <td>animationSetDuration(duration)</td>
  872. <td>none</td>
  873. <td>Duration of the animation in seconds.
  874. Only applicable when packages with a timestamp are available.
  875. The animation speed is scaled such that the total duration of playing the
  876. history equals the set duration.</td>
  877. </tr>
  878. <tr>
  879. <td>animationSetFramerate(framerate)</td>
  880. <td>none</td>
  881. <td>Set the framerate in frames per second for animation of history.
  882. Only applicable when packages with a timestamp are available.
  883. </td>
  884. </tr>
  885. <tr>
  886. <td>animationStart()</td>
  887. <td>none</td>
  888. <td>Start animation of history.
  889. Only applicable when packages with a timestamp are available.
  890. </td>
  891. </tr>
  892. <tr>
  893. <td>animationStop()</td>
  894. <td>none</td>
  895. <td>Stop animation of history.
  896. Only applicable when packages with a timestamp are available.
  897. </td>
  898. </tr>
  899. <tr>
  900. <td>setData(data)</td>
  901. <td>none</td>
  902. <td>Loads data. Parameter <code>data</code> is an object containing
  903. nodes, edges, and options. Parameters nodes, edges are an Array.
  904. Options is a name-value map and is optional.
  905. </td>
  906. </tr>
  907. <tr>
  908. <td>setOptions(options)</td>
  909. <td>none</td>
  910. <td>Set options for the graph. The available options are described in
  911. the section <a href="#Configuration_Options">Configuration Options</a>.
  912. </td>
  913. </tr>
  914. <tr>
  915. <td>getSelection()</td>
  916. <td>Array of selection elements</td>
  917. <td>Standard <code>getSelection()</code> implementation.
  918. Returns an array with one or multiple selections. Each selection contains
  919. the property <code>row</code>. The selections are not ordered.
  920. </td>
  921. </tr>
  922. <tr>
  923. <td>redraw()</td>
  924. <td>none</td>
  925. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  926. </tr>
  927. <tr>
  928. <td>setSelection(selection)</td>
  929. <td>none</td>
  930. <td>Standard <code>setSelection(selection)</code> implementation.
  931. <code>selection</code> is an array with selection elements. The visualization
  932. accepts one or multiple selection elements, which must have the property <code>row</code>.
  933. Example usage: <code>graph.setSelection([{"row": 3}]);</code>.
  934. </td>
  935. </tr>
  936. <tr>
  937. <td>setSize(width, height)</td>
  938. <td>none</td>
  939. <td>Parameters <code>width</code> and <code>height</code> are strings,
  940. containing a new size for the visualization. Size can be provided in pixels
  941. or in percentages.</td>
  942. </tr>
  943. <tr>
  944. <td>start()</td>
  945. <td>none</td>
  946. <td>Start animation.
  947. Only applicable when there are animated edges or nodes,
  948. or when the nodes are not yet moved to a stable position.</td>
  949. </tr>
  950. <tr>
  951. <td>stop()</td>
  952. <td>none</td>
  953. <td>Stop animation.
  954. Only applicable when there are animated edges or nodes.</td>
  955. </tr>
  956. </table>
  957. <h2><a name="Events"></a>Events</h2>
  958. <p>
  959. Graph fires events after one or multiple nodes are selected.
  960. The event can be catched by creating a listener.
  961. </p>
  962. <p>
  963. Here an example on how to catch a <code>select</code> event.
  964. </p>
  965. <pre class="prettyprint lang-js">
  966. function onselect() {
  967. var sel = graph.getSelection();
  968. var info = 'selected row(s): ';
  969. for (var i = 0; i &lt; sel.length; i++) {
  970. info += sel[i].row + ' ';
  971. }
  972. alert(info);
  973. }
  974. vis.events.addListener(graph, 'select', onselect);
  975. </pre>
  976. <p>
  977. The following events are available.
  978. </p>
  979. <table>
  980. <col width="10%">
  981. <col width="60%">
  982. <col width="30%">
  983. <tr>
  984. <th>name</th>
  985. <th>Description</th>
  986. <th>Properties</th>
  987. </tr>
  988. <tr>
  989. <td>select</td>
  990. <td>Fired after the user selects or unselects a node by clicking it,
  991. or when selecting a number of nodes by dragging a selection area
  992. around them. Not fired when the method <code>setSelection</code>
  993. is executed. The corresponding rows in the Array are selected.
  994. <br>
  995. The selected rows can be retrieved via the method <code>getSelection</code>.
  996. </td>
  997. <td>none</td>
  998. </tr>
  999. <tr>
  1000. <td>ready</td>
  1001. <td>The graph is loaded and ready for external method calls.
  1002. If you want to interact with the graph, and call methods after you draw it,
  1003. you should set up a listener for this event before you call the setData method,
  1004. and call them only after the event was fired.</td>
  1005. <td>none</td>
  1006. </tr>
  1007. </table>
  1008. <h2><a name="Data_Policy"></a>Data Policy</h2>
  1009. <p>
  1010. All code and data are processed and rendered in the browser. No data is sent to any server.
  1011. </p>
  1012. </div>
  1013. </body>
  1014. </html>