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.

306 lines
8.4 KiB

11 years ago
11 years ago
11 years ago
11 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:
  22. http://cdnjs.com
  23. Or download the library from the github project:
  24. [https://github.com/almende/vis.git](https://github.com/almende/vis.git).
  25. ## Load
  26. To use a component, include the javascript and css files of vis in your web page:
  27. ```html
  28. <!DOCTYPE HTML>
  29. <html>
  30. <head>
  31. <script src="components/vis/dist/vis.js"></script>
  32. <link href="components/vis/dist/vis.css" rel="stylesheet" type="text/css" />
  33. </head>
  34. <body>
  35. <script type="text/javascript">
  36. // ... load a visualization
  37. </script>
  38. </body>
  39. </html>
  40. ```
  41. or load vis.js using require.js. Note that vis.css must be loaded too.
  42. ```js
  43. require.config({
  44. paths: {
  45. vis: 'path/to/vis/dist',
  46. }
  47. });
  48. require(['vis'], function (math) {
  49. // ... load a visualization
  50. });
  51. ```
  52. A timeline can be instantiated as:
  53. ```js
  54. var timeline = new vis.Timeline(container, data, options);
  55. ```
  56. Where `container` is an HTML element, `data` is an Array with data or a DataSet,
  57. and `options` is an optional object with configuration options for the
  58. component.
  59. ## Example
  60. A basic example on loading a Timeline is shown below. More examples can be
  61. found in the [examples directory](https://github.com/almende/vis/tree/master/examples)
  62. of the project.
  63. ```html
  64. <!DOCTYPE HTML>
  65. <html>
  66. <head>
  67. <title>Timeline basic demo</title>
  68. <script src="vis/dist/vis.js"></script>
  69. <link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
  70. <style type="text/css">
  71. body, html {
  72. font-family: sans-serif;
  73. }
  74. </style>
  75. </head>
  76. <body>
  77. <div id="visualization"></div>
  78. <script type="text/javascript">
  79. var container = document.getElementById('visualization');
  80. var data = [
  81. {id: 1, content: 'item 1', start: '2013-04-20'},
  82. {id: 2, content: 'item 2', start: '2013-04-14'},
  83. {id: 3, content: 'item 3', start: '2013-04-18'},
  84. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  85. {id: 5, content: 'item 5', start: '2013-04-25'},
  86. {id: 6, content: 'item 6', start: '2013-04-27'}
  87. ];
  88. var options = {};
  89. var timeline = new vis.Timeline(container, data, options);
  90. </script>
  91. </body>
  92. </html>
  93. ```
  94. ## Build
  95. To build the library from source, clone the project from github
  96. git clone git://github.com/almende/vis.git
  97. The source code uses the module style of node (require and module.exports) to
  98. organize dependencies. To install all dependencies and build the library,
  99. run `npm install` in the root of the project.
  100. cd vis
  101. npm install
  102. Then, the project can be build running:
  103. npm run build
  104. To automatically rebuild on changes in the source files, once can use
  105. npm run watch
  106. This will both build and minify the library on changes. Minifying is relatively
  107. slow, so when only the non-minified library is needed, one can use the
  108. `watch-dev` script instead:
  109. npm run watch-dev
  110. ## Custom builds
  111. 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.
  112. 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.
  113. *Note that hammer.js version 1 is required (v1.0.6-v1.1.3), version 2 is not yet supported.*
  114. #### Prerequisites
  115. Before you can do a build:
  116. - Install node.js, npm, and browserify on your system.
  117. - Download or clone the vis.js project.
  118. - Install the dependencies of vis.js by running `npm install` in the root of the project.
  119. #### Example 1: Bundle a single visualization
  120. 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:
  121. ```js
  122. exports.DataSet = require('./lib/DataSet');
  123. exports.Timeline = require('./lib/timeline/Timeline');
  124. ```
  125. Install browserify globally via `[sudo] npm install -g browserify`, then create a custom bundle like:
  126. browserify custom.js -o vis-custom.js -s vis
  127. 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 with uglifyjs (installed globally with `[sudo] npm install -g uglify-js`):
  128. uglifyjs vis-custom.js -o vis-custom.min.js
  129. The custom bundle can now be loaded like:
  130. ```html
  131. <!DOCTYPE HTML>
  132. <html>
  133. <head>
  134. <script src="vis-custom.min.js"></script>
  135. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  136. </head>
  137. <body>
  138. ...
  139. </body>
  140. </html>
  141. ```
  142. #### Example 2: Exclude external libraries
  143. 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:
  144. browserify index.js -o vis-custom.js -s vis -x moment -x hammerjs
  145. 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:
  146. uglifyjs vis-custom.js -o vis-custom.min.js
  147. The custom bundle can now be loaded as:
  148. ```html
  149. <!DOCTYPE HTML>
  150. <html>
  151. <head>
  152. <!-- load external dependencies -->
  153. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
  154. <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/1.1.3/hammer.min.js"></script>
  155. <!-- load vis.js -->
  156. <script src="vis-custom.min.js"></script>
  157. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  158. </head>
  159. <body>
  160. ...
  161. </body>
  162. </html>
  163. ```
  164. #### Example 3: Bundle vis.js as part of your (commonjs) application
  165. When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file **app.js** containing:
  166. ```js
  167. var moment = require('moment');
  168. var DataSet = require('vis/lib/DataSet');
  169. var Timeline = require('vis/lib/timeline/Timeline');
  170. var container = document.getElementById('visualization');
  171. var data = new DataSet([
  172. {id: 1, content: 'item 1', start: moment('2013-04-20')},
  173. {id: 2, content: 'item 2', start: moment('2013-04-14')},
  174. {id: 3, content: 'item 3', start: moment('2013-04-18')},
  175. {id: 4, content: 'item 4', start: moment('2013-04-16'), end: moment('2013-04-19')},
  176. {id: 5, content: 'item 5', start: moment('2013-04-25')},
  177. {id: 6, content: 'item 6', start: moment('2013-04-27')}
  178. ]);
  179. var options = {};
  180. var timeline = new Timeline(container, data, options);
  181. ```
  182. Install the application dependencies via npm:
  183. npm install vis moment
  184. The application can be bundled and minified:
  185. browserify app.js -o app-bundle.js
  186. uglifyjs app-bundle.js -o app-bundle.min.js
  187. And loaded into a webpage:
  188. ```html
  189. <!DOCTYPE HTML>
  190. <html>
  191. <head>
  192. <link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
  193. </head>
  194. <body>
  195. <div id="visualization"></div>
  196. <script src="app-bundle.min.js"></script>
  197. </body>
  198. </html>
  199. ```
  200. ## Test
  201. To test the library, install the project dependencies once:
  202. npm install
  203. Then run the tests:
  204. npm test
  205. ## License
  206. Copyright (C) 2010-2015 Almende B.V.
  207. Vis.js is dual licensed under both
  208. * The Apache 2.0 License
  209. http://www.apache.org/licenses/LICENSE-2.0
  210. and
  211. * The MIT License
  212. http://opensource.org/licenses/MIT
  213. Vis.js may be distributed under either license.