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.

1114 lines
30 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>color</td>
  203. <td>String | Object</td>
  204. <td>no</td>
  205. <td>Color for the node.</td>
  206. </tr>
  207. <tr>
  208. <td>color.background</td>
  209. <td>String</td>
  210. <td>no</td>
  211. <td>Background color for the node.</td>
  212. </tr>
  213. <tr>
  214. <td>color.border</td>
  215. <td>String</td>
  216. <td>no</td>
  217. <td>Border color for the node.</td>
  218. </tr>
  219. <tr>
  220. <td>color.highlight</td>
  221. <td>String | Object</td>
  222. <td>no</td>
  223. <td>Color of the node when selected.</td>
  224. </tr>
  225. <tr>
  226. <td>color.highlight.background</td>
  227. <td>String</td>
  228. <td>no</td>
  229. <td>Background color of the node when selected.</td>
  230. </tr>
  231. <tr>
  232. <td>color.highlight.border</td>
  233. <td>String</td>
  234. <td>no</td>
  235. <td>Border color of the node when selected.</td>
  236. </tr>
  237. <tr>
  238. <td>group</td>
  239. <td>Number | String</td>
  240. <td>no</td>
  241. <td>A group number or name. The type can be <code>number</code>,
  242. <code>string</code>, or an other type. All nodes with the same group get
  243. the same color schema.</td>
  244. </tr>
  245. <tr>
  246. <td>fontColor</td>
  247. <td>String</td>
  248. <td>no</td>
  249. <td>Font color for label in the node.</td>
  250. </tr>
  251. <tr>
  252. <td>fontFace</td>
  253. <td>String</td>
  254. <td>no</td>
  255. <td>Font face for label in the node, for example "verdana" or "arial".</td>
  256. </tr>
  257. <tr>
  258. <td>fontSize</td>
  259. <td>Number</td>
  260. <td>no</td>
  261. <td>Font size in pixels for label in the node.</td>
  262. </tr>
  263. <tr>
  264. <td>id</td>
  265. <td>Number | String</td>
  266. <td>yes</td>
  267. <td>A unique id for this node.
  268. Nodes may not have duplicate id's.
  269. Id's do not need to be consecutive.
  270. An id is normally a number, but may be any type.</td>
  271. </tr>
  272. <tr>
  273. <td>image</td>
  274. <td>string</td>
  275. <td>no</td>
  276. <td>Url of an image. Only applicable when the shape of the node is
  277. <code>image</code>.</td>
  278. </tr>
  279. <tr>
  280. <td>radius</td>
  281. <td>number</td>
  282. <td>no</td>
  283. <td>Radius for the node. Applicable for all shapes except <code>box</code>,
  284. <code>circle</code>, <code>ellipse</code> and <code>database</code>.
  285. The value of <code>radius</code> will override a value in
  286. property <code>value</code>.</td>
  287. </tr>
  288. <tr>
  289. <td>shape</td>
  290. <td>string</td>
  291. <td>no</td>
  292. <td>Define the shape for the node.
  293. Choose from
  294. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  295. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  296. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  297. <br><br>
  298. In case of <code>image</code>, a property with name <code>image</code> must
  299. be provided, containing image urls.
  300. <br><br>
  301. The shapes <code>dot</code>, <code>star</code>, <code>triangle</code>,
  302. <code>triangleDown</code>, and <code>square</code>, are scalable.
  303. The size is determined by the properties <code>radius</code> or
  304. <code>value</code>.
  305. <br><br>
  306. When a property <code>label</code> is provided,
  307. this label will be displayed inside the shape in case of shapes
  308. <code>box</code>, <code>circle</code>, <code>ellipse</code>,
  309. and <code>database</code>.
  310. For all other shapes, the label will be displayed right below the shape.
  311. </td>
  312. </tr>
  313. <tr>
  314. <td>label</td>
  315. <td>string</td>
  316. <td>no</td>
  317. <td>Text label to be displayed in the node or under the image of the node.
  318. Multiple lines can be separated by a newline character <code>\n</code> .</td>
  319. </tr>
  320. <tr>
  321. <td>title</td>
  322. <td>string</td>
  323. <td>no</td>
  324. <td>Title to be displayed when the user hovers over the node.
  325. The title can contain HTML code.</td>
  326. </tr>
  327. <tr>
  328. <td>value</td>
  329. <td>number</td>
  330. <td>no</td>
  331. <td>A value for the node.
  332. The radius of the nodes will be scaled automatically from minimum to
  333. maximum value.
  334. Only applicable when the shape of the node is <code>dot</code>.
  335. If a <code>radius</code> is provided for the node too, it will override the
  336. radius calculated from the value.</td>
  337. </tr>
  338. <tr>
  339. <td>x</td>
  340. <td>number</td>
  341. <td>no</td>
  342. <td>Horizontal position in pixels.
  343. The horizontal position of the node will be fixed.
  344. The vertical position y may remain undefined.</td>
  345. </tr>
  346. <tr>
  347. <td>y</td>
  348. <td>number</td>
  349. <td>no</td>
  350. <td>Vertical position in pixels.
  351. The vertical position of the node will be fixed.
  352. The horizontal position x may remain undefined.</td>
  353. </tr>
  354. </table>
  355. <h3 id="Edges">Edges</h3>
  356. <p>
  357. Edges are connections between nodes.
  358. An edge must at least contain properties <code>from</code> and
  359. <code>to</code>, both referring to the <code>id</code> of a node.
  360. Edges can have extra properties, used to define the type and style.
  361. </p>
  362. <p>
  363. A JavaScript Array with edges is constructed as:
  364. </p>
  365. <pre class="prettyprint lang-js">
  366. var edges = [
  367. {
  368. from: 1,
  369. to: 3
  370. },
  371. // ... more edges
  372. ];
  373. </pre>
  374. <p>
  375. Edges support the following properties:
  376. </p>
  377. <table>
  378. <tr>
  379. <th>Name</th>
  380. <th>Type</th>
  381. <th>Required</th>
  382. <th>Description</th>
  383. </tr>
  384. <tr>
  385. <td>altdashlength</td>
  386. <td>number</td>
  387. <td>no</td>
  388. <td>Length of the alternated dash in pixels on a dashed line.
  389. Specifying <code>altdashlength</code> allows for creating
  390. a dashed line with a dash-dot style, for example when
  391. <code>dashlength=10</code> and <code>altdashlength=5</code>.
  392. See also the option <code>dashlength</code>.
  393. Only applicable when the line style is <code>dash-line</code>.</td>
  394. </tr>
  395. <tr>
  396. <td>color</td>
  397. <td>string</td>
  398. <td>no</td>
  399. <td>A HTML color for the edge.</td>
  400. </tr>
  401. <tr>
  402. <td>dashlength</td>
  403. <td>number</td>
  404. <td>no</td>
  405. <td>Length of a dash in pixels on a dashed line.
  406. Only applicable when the line style is <code>dash-line</code>.</td>
  407. </tr>
  408. <tr>
  409. <td>dashgap</td>
  410. <td>number</td>
  411. <td>no</td>
  412. <td>Length of a gap in pixels on a dashed line.
  413. Only applicable when the line style is <code>dash-line</code>.</td>
  414. </tr>
  415. <tr>
  416. <td>fontColor</td>
  417. <td>String</td>
  418. <td>no</td>
  419. <td>Font color for the text label of the edge.
  420. Only applicable when property <code>label</code> is defined.</td>
  421. </tr>
  422. <tr>
  423. <td>fontFace</td>
  424. <td>String</td>
  425. <td>no</td>
  426. <td>Font face for the text label of the edge,
  427. for example "verdana" or "arial".
  428. Only applicable when property <code>label</code> is defined.</td>
  429. </tr>
  430. <tr>
  431. <td>fontSize</td>
  432. <td>Number</td>
  433. <td>no</td>
  434. <td>Font size in pixels for the text label of the edge.
  435. Only applicable when property <code>label</code> is defined.</td>
  436. </tr>
  437. <tr>
  438. <td>from</td>
  439. <td>Number | String</td>
  440. <td>yes</td>
  441. <td>The id of a node where the edge starts. The type must correspond with
  442. the type of the node id's. This is normally a number, but can be any
  443. type.</td>
  444. </tr>
  445. <tr>
  446. <td>length</td>
  447. <td>number</td>
  448. <td>no</td>
  449. <td>The length of the edge in pixels.</td>
  450. </tr>
  451. <tr>
  452. <td>style</td>
  453. <td>string</td>
  454. <td>no</td>
  455. <td>Define a line style for the edge.
  456. Choose from <code>line</code> (default), <code>arrow</code>,
  457. <code>arrow-center</code>, or <code>dash-line</code>.
  458. </td>
  459. </tr>
  460. <tr>
  461. <td>label</td>
  462. <td>string</td>
  463. <td>no</td>
  464. <td>Text label to be displayed halfway the edge.</td>
  465. </tr>
  466. <tr>
  467. <td>title</td>
  468. <td>string</td>
  469. <td>no</td>
  470. <td>Title to be displayed when the user hovers over the edge.
  471. The title can contain HTML code.</td>
  472. </tr>
  473. <tr>
  474. <td>to</td>
  475. <td>Number | String</td>
  476. <td>yes</td>
  477. <td>The id of a node where the edge ends. The type must correspond with
  478. the type of the node id's. This is normally a number, but can be any
  479. type.</td>
  480. </tr>
  481. <tr>
  482. <td>value</td>
  483. <td>number</td>
  484. <td>no</td>
  485. <td>A value for the edge.
  486. The width of the edges will be scaled automatically from minimum to
  487. maximum value.
  488. If a <code>width</code> is provided for the edge too, it will override the
  489. width calculated from the value.</td>
  490. </tr>
  491. <tr>
  492. <td>width</td>
  493. <td>number</td>
  494. <td>no</td>
  495. <td>Width of the line in pixels. The <code>width</code> will
  496. override a specified <code>value</code>, if a <code>value</code> is
  497. specified too.</td>
  498. </tr>
  499. </table>
  500. <h3 id="DOT_language">DOT language</h3>
  501. <p>
  502. Graph supports data in the
  503. <a href="http://en.wikipedia.org/wiki/DOT_language" target="_blank">DOT language</a>.
  504. To provide data in the DOT language, the <code>data</code> object must contain
  505. a property <code>dot</code> with a String containing the data.
  506. </p>
  507. <p>
  508. Example usage:
  509. </p>
  510. <pre class="prettyprint lang-js">
  511. // provide data in the DOT language
  512. var data = {
  513. dot: 'digraph {1 -> 1 -> 2; 2 -> 3; 2 -- 4; 2 -> 1 }'
  514. };
  515. // create a graph
  516. var graph = new vis.Graph(container, data);
  517. </pre>
  518. <h2 id="Configuration_Options">Configuration Options</h2>
  519. <p>
  520. Options can be used to customize the graph. Options are defined as a JSON object.
  521. All options are optional.
  522. </p>
  523. <pre class="prettyprint lang-js">
  524. var options = {
  525. width: '100%',
  526. height: '400px',
  527. edges: {
  528. color: 'red',
  529. width: 2
  530. }
  531. };
  532. </pre>
  533. <p>
  534. The following options are available.
  535. </p>
  536. <table>
  537. <tr>
  538. <th>Name</th>
  539. <th>Type</th>
  540. <th>Default</th>
  541. <th>Description</th>
  542. </tr>
  543. <tr>
  544. <td>groups</td>
  545. <td>Object</td>
  546. <td>none</td>
  547. <td>It is possible to specify custom styles for groups.
  548. Each node assigned a group gets the specified style.
  549. See <a href="#Groups">Groups</a> for an overview of the available styles
  550. and an example.
  551. </td>
  552. </tr>
  553. <tr>
  554. <td>height</td>
  555. <td>String</td>
  556. <td>"400px"</td>
  557. <td>The height of the graph in pixels or as a percentage.</td>
  558. </tr>
  559. <tr>
  560. <td>edges.altdashlength</td>
  561. <td>number</td>
  562. <td>none</td>
  563. <td>Length of the alternated dash in pixels on a dashed line.
  564. Specifying <code>altdashlength</code> allows for creating
  565. a dashed line with a dash-dot style, for example when
  566. <code>dashlength=10</code> and <code>altdashlength=5</code>.
  567. See also the option <code>dashlength</code>.
  568. Only applicable when the line style is <code>dash-line</code>.</td>
  569. </tr>
  570. <tr>
  571. <td>edges.color</td>
  572. <td>String</td>
  573. <td>"#2B7CE9"</td>
  574. <td>The default color of a edge.</td>
  575. </tr>
  576. <tr>
  577. <td>edges.dashlength</td>
  578. <td>number</td>
  579. <td>10</td>
  580. <td>Length of a dash in pixels on a dashed line.
  581. Only applicable when the line style is <code>dash-line</code>.</td>
  582. </tr>
  583. <tr>
  584. <td>edges.dashgap</td>
  585. <td>number</td>
  586. <td>5</td>
  587. <td>Length of a gap 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.length</td>
  592. <td>Number</td>
  593. <td>100</td>
  594. <td>The default length of a edge.</td>
  595. </tr>
  596. <tr>
  597. <td>edges.style</td>
  598. <td>String</td>
  599. <td>"line"</td>
  600. <td>The default style of a edge.
  601. Choose from <code>line</code> (default), <code>arrow</code>,
  602. <code>arrow-center</code>, <code>dash-line</code>.</td>
  603. </tr>
  604. <tr>
  605. <td>edges.width</td>
  606. <td>Number</td>
  607. <td>1</td>
  608. <td>The default width of a edge.</td>
  609. </tr>
  610. <tr>
  611. <td>nodes.color</td>
  612. <td>String | Object</td>
  613. <td>Object</td>
  614. <td>Default color of the nodes. When color is a string, the color is applied
  615. to both background as well as the border of the node.</td>
  616. </tr>
  617. <tr>
  618. <td>nodes.color.background</td>
  619. <td>String</td>
  620. <td>"#97C2FC"</td>
  621. <td>Default background color of the nodes</td>
  622. </tr>
  623. <tr>
  624. <td>nodes.color.border</td>
  625. <td>String</td>
  626. <td>"#2B7CE9"</td>
  627. <td>Default border color of the nodes</td>
  628. </tr>
  629. <tr>
  630. <td>nodes.color.highlight</td>
  631. <td>String | Object</td>
  632. <td>Object</td>
  633. <td>Default color of the node when the node is selected. Applied to
  634. both border and background of the node.</td>
  635. </tr>
  636. <tr>
  637. <td>nodes.color.highlight.background</td>
  638. <td>String</td>
  639. <td>"#D2E5FF"</td>
  640. <td>Default background color of the node when selected.</td>
  641. </tr>
  642. <tr>
  643. <td>nodes.color.highlight.border</td>
  644. <td>String</td>
  645. <td>"#2B7CE9"</td>
  646. <td>Default border color of the node when selected.</td>
  647. </tr>
  648. <tr>
  649. <td>nodes.fontColor</td>
  650. <td>String</td>
  651. <td>"black"</td>
  652. <td>Default font color for the text label in the nodes.</td>
  653. </tr>
  654. <tr>
  655. <td>nodes.fontFace</td>
  656. <td>String</td>
  657. <td>"sans"</td>
  658. <td>Default font face for the text label in the nodes, for example "verdana" or "arial".</td>
  659. </tr>
  660. <tr>
  661. <td>nodes.fontSize</td>
  662. <td>Number</td>
  663. <td>14</td>
  664. <td>Default font size in pixels for the text label in the nodes.</td>
  665. </tr>
  666. <tr>
  667. <td>nodes.group</td>
  668. <td>String</td>
  669. <td>none</td>
  670. <td>Default group for the nodes.</td>
  671. </tr>
  672. <tr>
  673. <td>nodes.image</td>
  674. <td>String</td>
  675. <td>none</td>
  676. <td>Default image url for the nodes. only applicable with shape <code>image</code>.</td>
  677. </tr>
  678. <tr>
  679. <td>nodes.widthMin</td>
  680. <td>Number</td>
  681. <td>16</td>
  682. <td>The minimum width for a scaled image. Only applicable with shape <code>image</code>.</td>
  683. </tr>
  684. <tr>
  685. <td>nodes.widthMax</td>
  686. <td>Number</td>
  687. <td>64</td>
  688. <td>The maximum width for a scaled image. Only applicable with shape <code>image</code>.</td>
  689. </tr>
  690. <tr>
  691. <td>nodes.shape</td>
  692. <td>String</td>
  693. <td>"ellipse"</td>
  694. <td>The default shape for all nodes.
  695. Choose from
  696. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  697. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  698. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  699. This shape can be overridden by a group shape, or by a shape of an individual node.</td>
  700. </tr>
  701. <tr>
  702. <td>nodes.radius</td>
  703. <td>Number</td>
  704. <td>5</td>
  705. <td>The default radius for a node. Only applicable with shape <code>dot</code>.</td>
  706. </tr>
  707. <tr>
  708. <td>nodes.radiusMin</td>
  709. <td>Number</td>
  710. <td>5</td>
  711. <td>The minimum radius for a scaled node. Only applicable with shape <code>dot</code>.</td>
  712. </tr>
  713. <tr>
  714. <td>nodes.radiusMax</td>
  715. <td>Number</td>
  716. <td>20</td>
  717. <td>The maximum radius for a scaled node. Only applicable with shape <code>dot</code>.</td>
  718. </tr>
  719. <tr>
  720. <td>selectable</td>
  721. <td>Boolean</td>
  722. <td>true</td>
  723. <td>If true, nodes in the graph can be selected by clicking them, or
  724. by keeping the <code>Shift</code> key down and dragging a selection area around them.
  725. When the <code>Ctrl</code> key is down, the new selection is appended to the
  726. previous selection. If not, the new selection replaces the previous selection.</td>
  727. </tr>
  728. <tr>
  729. <td>stabilize</td>
  730. <td>Boolean</td>
  731. <td>true</td>
  732. <td>If true, the graph is stabilized before displaying it. If false,
  733. the nodes move to a stabe position visibly in an animated way.</td>
  734. </tr>
  735. <tr>
  736. <td>width</td>
  737. <td>String</td>
  738. <td>"400px"</td>
  739. <td>The width of the graph in pixels or as a percentage.</td>
  740. </tr>
  741. </table>
  742. <br>
  743. <h3 id="Groups">Groups</h3>
  744. <p>It is possible to specify custom styles for groups of nodes.
  745. Each node having assigned to this group gets the specified style.
  746. The options <code>groups</code> is an object containing one or multiple groups,
  747. identified by a unique string, the groupname.
  748. </p>
  749. <p>
  750. A group can have the following styles:
  751. </p>
  752. <pre class="prettyprint lang-js">
  753. var options = {
  754. // ...
  755. groups: {
  756. mygroup: {
  757. shape: 'circle',
  758. color: {
  759. border: 'black',
  760. background: 'white',
  761. highlight: {
  762. border: 'yellow',
  763. background: 'orange'
  764. }
  765. }
  766. fontColor: 'red',
  767. fontSize: 18
  768. }
  769. // add more groups here
  770. }
  771. };
  772. var nodes = [
  773. {id: 1, label: 'Node 1'}, // will get the default style
  774. {id: 2, label: 'Node 2', group: 'mygroup'}, // will get the style from 'mygroup'
  775. // ... more nodes
  776. ];
  777. </pre>
  778. <p>The following styles are available for groups:</p>
  779. <table>
  780. <tr>
  781. <th>Name</th>
  782. <th>Type</th>
  783. <th>Default</th>
  784. <th>Description</th>
  785. </tr>
  786. <tr>
  787. <td>color</td>
  788. <td>String | Object</td>
  789. <td>Object</td>
  790. <td>Color of the node</td>
  791. </tr>
  792. <tr>
  793. <td>color.border</td>
  794. <td>String</td>
  795. <td>"#2B7CE9"</td>
  796. <td>Border color of the node</td>
  797. </tr>
  798. <tr>
  799. <td>color.background</td>
  800. <td>String</td>
  801. <td>"#97C2FC"</td>
  802. <td>Background color of the node</td>
  803. </tr>
  804. <tr>
  805. <td>color.highlight</td>
  806. <td>String</td>
  807. <td>"#D2E5FF"</td>
  808. <td>Color of the node when selected.</td>
  809. </tr>
  810. <tr>
  811. <td>color.highlight.background</td>
  812. <td>String</td>
  813. <td>"#D2E5FF"</td>
  814. <td>Background color of the node when selected.</td>
  815. </tr>
  816. <tr>
  817. <td>color.highlight.border</td>
  818. <td>String</td>
  819. <td>"#D2E5FF"</td>
  820. <td>Border color of the node when selected.</td>
  821. </tr>
  822. <tr>
  823. <td>image</td>
  824. <td>String</td>
  825. <td>none</td>
  826. <td>Default image for the nodes. Only applicable in combination with
  827. shape <code>image</code>.</td>
  828. </tr>
  829. <tr>
  830. <td>fontColor</td>
  831. <td>String</td>
  832. <td>"black"</td>
  833. <td>Font color of the node.</td>
  834. </tr>
  835. <tr>
  836. <td>fontFace</td>
  837. <td>String</td>
  838. <td>"sans"</td>
  839. <td>Font name of the node, for example "verdana" or "arial".</td>
  840. </tr>
  841. <tr>
  842. <td>fontSize</td>
  843. <td>Number</td>
  844. <td>14</td>
  845. <td>Font size for the node in pixels.</td>
  846. </tr>
  847. <tr>
  848. <td>shape</td>
  849. <td>String</td>
  850. <td>"ellipse"</td>
  851. <td>Choose from
  852. <code>ellipse</code> (default), <code>circle</code>, <code>box</code>,
  853. <code>database</code>, <code>image</code>, <code>label</code>, <code>dot</code>,
  854. <code>star</code>, <code>triangle</code>, <code>triangleDown</code>, and <code>square</code>.
  855. In case of image, a property with name image must be provided, containing
  856. image urls.</td>
  857. </tr>
  858. <tr>
  859. <td>radius</td>
  860. <td>Number</td>
  861. <td>5</td>
  862. <td>Default radius for the node. Only applicable in combination with
  863. shapes <code>box</code> and <code>dot</code>.</td>
  864. </tr>
  865. </table>
  866. <h2 id="Methods">Methods</h2>
  867. <p>
  868. Graph supports the following methods.
  869. </p>
  870. <table>
  871. <tr>
  872. <th>Method</th>
  873. <th>Return Type</th>
  874. <th>Description</th>
  875. </tr>
  876. <tr>
  877. <td>setData(data)</td>
  878. <td>none</td>
  879. <td>Loads data. Parameter <code>data</code> is an object containing
  880. nodes, edges, and options. Parameters nodes, edges are an Array.
  881. Options is a name-value map and is optional.
  882. </td>
  883. </tr>
  884. <tr>
  885. <td>setOptions(options)</td>
  886. <td>none</td>
  887. <td>Set options for the graph. The available options are described in
  888. the section <a href="#Configuration_Options">Configuration Options</a>.
  889. </td>
  890. </tr>
  891. <tr>
  892. <td>getSelection()</td>
  893. <td>Array of selection elements</td>
  894. <td>Standard <code>getSelection()</code> implementation.
  895. Returns an array with one or multiple selections. Each selection contains
  896. the property <code>row</code>. The selections are not ordered.
  897. </td>
  898. </tr>
  899. <tr>
  900. <td>redraw()</td>
  901. <td>none</td>
  902. <td>Redraw the graph. Useful when the layout of the webpage changed.</td>
  903. </tr>
  904. <tr>
  905. <td>setSelection(selection)</td>
  906. <td>none</td>
  907. <td>Standard <code>setSelection(selection)</code> implementation.
  908. <code>selection</code> is an array with selection elements. The visualization
  909. accepts one or multiple selection elements, which must have the property <code>row</code>.
  910. Example usage: <code>graph.setSelection([{"row": 3}]);</code>.
  911. </td>
  912. </tr>
  913. <tr>
  914. <td>setSize(width, height)</td>
  915. <td>none</td>
  916. <td>Parameters <code>width</code> and <code>height</code> are strings,
  917. containing a new size for the visualization. Size can be provided in pixels
  918. or in percentages.</td>
  919. </tr>
  920. </table>
  921. <h2 id="Events">Events</h2>
  922. <p>
  923. Graph fires events after one or multiple nodes are selected.
  924. The event can be catched by creating a listener.
  925. </p>
  926. <p>
  927. Here an example on how to catch a <code>select</code> event.
  928. </p>
  929. <pre class="prettyprint lang-js">
  930. function onselect() {
  931. var sel = graph.getSelection();
  932. var info = 'selected row(s): ';
  933. for (var i = 0; i &lt; sel.length; i++) {
  934. info += sel[i].row + ' ';
  935. }
  936. alert(info);
  937. }
  938. vis.events.addListener(graph, 'select', onselect);
  939. </pre>
  940. <p>
  941. The following events are available.
  942. </p>
  943. <table>
  944. <col width="10%">
  945. <col width="60%">
  946. <col width="30%">
  947. <tr>
  948. <th>name</th>
  949. <th>Description</th>
  950. <th>Properties</th>
  951. </tr>
  952. <tr>
  953. <td>select</td>
  954. <td>Fired after the user selects or unselects a node by clicking it,
  955. or when selecting a number of nodes by dragging a selection area
  956. around them. Not fired when the method <code>setSelection</code>
  957. is executed. The corresponding rows in the Array are selected.
  958. <br>
  959. The selected rows can be retrieved via the method <code>getSelection</code>.
  960. </td>
  961. <td>none</td>
  962. </tr>
  963. </table>
  964. <h2 id="Data_Policy">Data Policy</h2>
  965. <p>
  966. All code and data are processed and rendered in the browser. No data is sent to any server.
  967. </p>
  968. </div>
  969. </body>
  970. </html>