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.

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