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.

339 lines
9.9 KiB

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