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.

1053 lines
28 KiB

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