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.

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