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.

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