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.

325 lines
8.9 KiB

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