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.

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