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.

319 lines
8.5 KiB

11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
  1. vis.js
  2. ==================
  3. Vis.js is a dynamic, browser based visualization library.
  4. The library is designed to be easy to use, handle large amounts
  5. of dynamic data, and enable manipulation of the data.
  6. The library consists of the following components:
  7. - DataSet and DataView. A flexible key/value based data set. Add, update, and
  8. remove items. Subscribe on changes in the data set. A DataSet can filter and
  9. order items, and convert fields of items.
  10. - DataView. A filtered and/or formatted view on a DataSet.
  11. - Graph2d. Plot data on a timeline with lines or barcharts.
  12. - Graph3d. Display data in a three dimensional graph.
  13. - Network. Display a network (force directed graph) with nodes and edges.
  14. - Timeline. Display different types of data on a timeline.
  15. The vis.js library is developed by [Almende B.V](http://almende.com).
  16. ## Install
  17. Install via npm:
  18. $ npm install vis
  19. Install via bower:
  20. $ bower install vis
  21. Link via cdnjs: http://cdnjs.com
  22. Or download the library from the github project:
  23. [https://github.com/almende/vis.git](https://github.com/almende/vis.git).
  24. ## Load
  25. To use a component, include the javascript and css files of vis in your web page:
  26. ```html
  27. <!DOCTYPE HTML>
  28. <html>
  29. <head>
  30. <script src="components/vis/dist/vis.js"></script>
  31. <link href="components/vis/dist/vis.css" rel="stylesheet" type="text/css" />
  32. </head>
  33. <body>
  34. <script type="text/javascript">
  35. // ... load a visualization
  36. </script>
  37. </body>
  38. </html>
  39. ```
  40. or load vis.js using require.js. Note that vis.css must be loaded too.
  41. ```js
  42. require.config({
  43. paths: {
  44. vis: 'path/to/vis/dist',
  45. }
  46. });
  47. require(['vis'], function (math) {
  48. // ... load a visualization
  49. });
  50. ```
  51. A timeline can be instantiated as:
  52. ```js
  53. var timeline = new vis.Timeline(container, data, options);
  54. ```
  55. Where `container` is an HTML element, `data` is an Array with data or a DataSet,
  56. and `options` is an optional object with configuration options for the
  57. component.
  58. ## Example
  59. A basic example on loading a Timeline is shown below. More examples can be
  60. found in the [examples directory](https://github.com/almende/vis/tree/master/examples)
  61. of the project.
  62. ```html
  63. <!DOCTYPE HTML>
  64. <html>
  65. <head>
  66. <title>Timeline basic demo</title>
  67. <script src="vis/dist/vis.js"></script>
  68. <link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
  69. <style type="text/css">
  70. body, html {
  71. font-family: sans-serif;
  72. }
  73. </style>
  74. </head>
  75. <body>
  76. <div id="visualization"></div>
  77. <script type="text/javascript">
  78. var container = document.getElementById('visualization');
  79. var data = [
  80. {id: 1, content: 'item 1', start: '2013-04-20'},
  81. {id: 2, content: 'item 2', start: '2013-04-14'},
  82. {id: 3, content: 'item 3', start: '2013-04-18'},
  83. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  84. {id: 5, content: 'item 5', start: '2013-04-25'},
  85. {id: 6, content: 'item 6', start: '2013-04-27'}
  86. ];
  87. var options = {};
  88. var timeline = new vis.Timeline(container, data, options);
  89. </script>
  90. </body>
  91. </html>
  92. ```
  93. ## Build
  94. To build the library from source, clone the project from github
  95. $ git clone git://github.com/almende/vis.git
  96. The source code uses the module style of node (require and module.exports) to
  97. organize dependencies. To install all dependencies and build the library,
  98. run `npm install` in the root of the project.
  99. $ cd vis
  100. $ npm install
  101. Then, the project can be build running:
  102. $ npm run build
  103. To automatically rebuild on changes in the source files, once can use
  104. $ npm run watch
  105. This will both build and minify the library on changes. Minifying is relatively
  106. slow, so when only the non-minified library is needed, one can use the
  107. `watch-dev` script instead:
  108. $ npm run watch-dev
  109. ## Custom builds
  110. The folder `dist` contains bundled versions of vis.js for direct use in the browser. These bundles contain the all visualizations and includes external dependencies such as hammer.js and moment.js.
  111. The source code of vis.js consists of commonjs modules, which makes it possible to create custom bundles using tools like [Browserify](http://browserify.org/) or [Webpack](http://webpack.github.io/). This can be bundling just one visualization like the Timeline, or bundling vis.js as part of your own browserified web application.
  112. *Note that hammer.js version 2 is required as of v4.*
  113. #### Prerequisites
  114. Before you can do a build:
  115. - Install node.js and npm on your system: https://nodejs.org/
  116. - Install the following modules using npm: `browserify`, `babelify`, and `uglify-js`:
  117. ```
  118. $ [sudo] npm install -g browserify babelify uglify-js
  119. ```
  120. - Download or clone the vis.js project:
  121. ```
  122. $ git clone https://github.com/almende/vis.git
  123. ```
  124. - Install the dependencies of vis.js by running `npm install` in the root of the project:
  125. ```
  126. $ cd vis
  127. $ npm install
  128. ```
  129. #### Example 1: Bundle a single visualization
  130. For example, to create a bundle with just the Timeline and DataSet, create an index file named **custom.js** in the root of the project, containing:
  131. ```js
  132. exports.DataSet = require('./lib/DataSet');
  133. exports.Timeline = require('./lib/timeline/Timeline');
  134. ```
  135. Then create a custom bundle using browserify, like:
  136. $ browserify custom.js -t babelify -o vis-custom.js -s vis
  137. This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis` containing only `DataSet` and `Timeline`. The generated bundle can be minified using uglifyjs:
  138. $ uglifyjs vis-custom.js -o vis-custom.min.js
  139. The custom bundle can now be loaded like:
  140. ```html
  141. <!DOCTYPE HTML>
  142. <html>
  143. <head>
  144. <script src="vis-custom.min.js"></script>
  145. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  146. </head>
  147. <body>
  148. ...
  149. </body>
  150. </html>
  151. ```
  152. #### Example 2: Exclude external libraries
  153. The default bundle `vis.js` is standalone and includes external dependencies such as hammer.js and moment.js. When these libraries are already loaded by the application, vis.js does not need to include these dependencies itself too. To build a custom bundle of vis.js excluding moment.js and hammer.js, run browserify in the root of the project:
  154. $ browserify index.js -t babelify -o vis-custom.js -s vis -x moment -x hammerjs
  155. This will generate a custom bundle *vis-custom.js*, which exposes the namespace `vis`, and has moment and hammerjs excluded. The generated bundle can be minified with uglifyjs:
  156. $ uglifyjs vis-custom.js -o vis-custom.min.js
  157. The custom bundle can now be loaded as:
  158. ```html
  159. <!DOCTYPE HTML>
  160. <html>
  161. <head>
  162. <!-- load external dependencies -->
  163. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
  164. <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/1.1.3/hammer.min.js"></script>
  165. <!-- load vis.js -->
  166. <script src="vis-custom.min.js"></script>
  167. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  168. </head>
  169. <body>
  170. ...
  171. </body>
  172. </html>
  173. ```
  174. #### Example 3: Bundle vis.js as part of your (commonjs) application
  175. When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file **app.js** containing:
  176. ```js
  177. var moment = require('moment');
  178. var DataSet = require('vis/lib/DataSet');
  179. var Timeline = require('vis/lib/timeline/Timeline');
  180. var container = document.getElementById('visualization');
  181. var data = new DataSet([
  182. {id: 1, content: 'item 1', start: moment('2013-04-20')},
  183. {id: 2, content: 'item 2', start: moment('2013-04-14')},
  184. {id: 3, content: 'item 3', start: moment('2013-04-18')},
  185. {id: 4, content: 'item 4', start: moment('2013-04-16'), end: moment('2013-04-19')},
  186. {id: 5, content: 'item 5', start: moment('2013-04-25')},
  187. {id: 6, content: 'item 6', start: moment('2013-04-27')}
  188. ]);
  189. var options = {};
  190. var timeline = new Timeline(container, data, options);
  191. ```
  192. Install the application dependencies via npm:
  193. $ npm install vis moment
  194. The application can be bundled and minified:
  195. $ browserify app.js -o app-bundle.js -t babelify
  196. $ uglifyjs app-bundle.js -o app-bundle.min.js
  197. And loaded into a webpage:
  198. ```html
  199. <!DOCTYPE HTML>
  200. <html>
  201. <head>
  202. <link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
  203. </head>
  204. <body>
  205. <div id="visualization"></div>
  206. <script src="app-bundle.min.js"></script>
  207. </body>
  208. </html>
  209. ```
  210. ## Test
  211. To test the library, install the project dependencies once:
  212. $ npm install
  213. Then run the tests:
  214. $ npm test
  215. ## License
  216. Copyright (C) 2010-2015 Almende B.V.
  217. Vis.js is dual licensed under both
  218. * The Apache 2.0 License
  219. http://www.apache.org/licenses/LICENSE-2.0
  220. and
  221. * The MIT License
  222. http://opensource.org/licenses/MIT
  223. Vis.js may be distributed under either license.