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.

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