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.

361 lines
11 KiB

11 years ago
11 years ago
11 years ago
8 years ago
9 years ago
  1. # vis.js
  2. [![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)
  3. <a href="https://github.com/almende/vis/blob/develop/misc/we_need_help.md">
  4. <img align="right" src="https://raw.githubusercontent.com/almende/vis/master/misc/we_need_help.png">
  5. </a>
  6. Vis.js is a dynamic, browser based visualization library.
  7. The library is designed to be easy to use, handle large amounts
  8. of dynamic data, and enable manipulation of the data.
  9. The library consists of the following components:
  10. - DataSet and DataView. A flexible key/value based data set. Add, update, and
  11. remove items. Subscribe on changes in the data set. A DataSet can filter and
  12. order items, and convert fields of items.
  13. - DataView. A filtered and/or formatted view on a DataSet.
  14. - Graph2d. Plot data on a timeline with lines or barcharts.
  15. - Graph3d. Display data in a three dimensional graph.
  16. - Network. Display a network (force directed graph) with nodes and edges.
  17. - Timeline. Display different types of data on a timeline.
  18. The vis.js library was initially developed by [Almende B.V](http://almende.com).
  19. ## Badges
  20. [![NPM](https://nodei.co/npm/vis.png?downloads=true&downloadRank=true)](https://nodei.co/npm/vis/)
  21. [![Dependency Status](https://david-dm.org/almende/vis/status.svg)](https://david-dm.org/almende/vis)
  22. [![devDependency Status](https://david-dm.org/almende/vis/dev-status.svg)](https://david-dm.org/almende/vis?type=dev)
  23. [![last version on CDNJS](https://img.shields.io/cdnjs/v/vis.svg)](https://cdnjs.com/libraries/vis)
  24. [![GitHub contributors](https://img.shields.io/github/contributors/almende/vis.svg)](https://github.com/almende/vis/graphs/contributors)
  25. [![GitHub stars](https://img.shields.io/github/stars/almende/vis.svg)](https://github.com/almende/vis/stargazers)
  26. [![GitHub issues](https://img.shields.io/github/issues/almende/vis.svg)](https://github.com/almende/vis/issues)
  27. [![Pending Pull-Requests](http://githubbadges.herokuapp.com/almende/vis/pulls.svg)](https://github.com/almende/vis/pulls)
  28. [![Code Climate](https://codeclimate.com/github/almende/vis/badges/gpa.svg)](https://codeclimate.com/github/almende/vis)
  29. ## Install
  30. Install via npm:
  31. $ npm install vis
  32. Install via bower:
  33. $ bower install vis
  34. Link via cdnjs: http://cdnjs.com
  35. Or download the library from the github project:
  36. [https://github.com/almende/vis.git](https://github.com/almende/vis.git).
  37. ## Load
  38. To use a component, include the javascript and css files of vis in your web page:
  39. ```html
  40. <!DOCTYPE HTML>
  41. <html>
  42. <head>
  43. <script src="webroot/vis/dist/vis.js"></script>
  44. <link href="webroot/vis/dist/vis.css" rel="stylesheet" type="text/css" />
  45. </head>
  46. <body>
  47. <script type="text/javascript">
  48. // ... load a visualization
  49. </script>
  50. </body>
  51. </html>
  52. ```
  53. or load vis.js using require.js. Note that vis.css must be loaded too.
  54. ```js
  55. require.config({
  56. paths: {
  57. vis: 'path/to/vis/dist',
  58. }
  59. });
  60. require(['vis'], function (math) {
  61. // ... load a visualization
  62. });
  63. ```
  64. A timeline can be instantiated as:
  65. ```js
  66. var timeline = new vis.Timeline(container, data, options);
  67. ```
  68. Where `container` is an HTML element, `data` is an Array with data or a DataSet,
  69. and `options` is an optional object with configuration options for the
  70. component.
  71. ## Example
  72. A basic example on loading a Timeline is shown below. More examples can be
  73. found in the [examples directory](https://github.com/almende/vis/tree/master/examples)
  74. of the project.
  75. ```html
  76. <!DOCTYPE HTML>
  77. <html>
  78. <head>
  79. <title>Timeline basic demo</title>
  80. <script src="vis/dist/vis.js"></script>
  81. <link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
  82. <style type="text/css">
  83. body, html {
  84. font-family: sans-serif;
  85. }
  86. </style>
  87. </head>
  88. <body>
  89. <div id="visualization"></div>
  90. <script type="text/javascript">
  91. var container = document.getElementById('visualization');
  92. var data = [
  93. {id: 1, content: 'item 1', start: '2013-04-20'},
  94. {id: 2, content: 'item 2', start: '2013-04-14'},
  95. {id: 3, content: 'item 3', start: '2013-04-18'},
  96. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  97. {id: 5, content: 'item 5', start: '2013-04-25'},
  98. {id: 6, content: 'item 6', start: '2013-04-27'}
  99. ];
  100. var options = {};
  101. var timeline = new vis.Timeline(container, data, options);
  102. </script>
  103. </body>
  104. </html>
  105. ```
  106. ## Build
  107. To build the library from source, clone the project from github
  108. $ git clone git://github.com/almende/vis.git
  109. The source code uses the module style of node (require and module.exports) to
  110. organize dependencies. To install all dependencies and build the library,
  111. run `npm install` in the root of the project.
  112. $ cd vis
  113. $ npm install
  114. Then, the project can be build running:
  115. $ npm run build
  116. To automatically rebuild on changes in the source files, once can use
  117. $ npm run watch
  118. This will both build and minify the library on changes. Minifying is relatively
  119. slow, so when only the non-minified library is needed, one can use the
  120. `watch-dev` script instead:
  121. $ npm run watch-dev
  122. ## Custom builds
  123. 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*.
  124. 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.
  125. *Note that hammer.js version 2 is required as of v4.*
  126. ### Prerequisites
  127. Before you can do a build:
  128. - Install *node.js* and *npm* on your system: https://nodejs.org/
  129. - Install the following modules using npm: `browserify`, `babelify`, and `uglify-js`:
  130. ```
  131. $ [sudo] npm install -g browserify babelify uglify-js
  132. ```
  133. - Download or clone the vis.js project:
  134. ```
  135. $ git clone https://github.com/almende/vis.git
  136. ```
  137. - Install the dependencies of vis.js by running `npm install` in the root of the project:
  138. ```
  139. $ cd vis
  140. $ npm install
  141. ```
  142. ### Examples of custom builds
  143. #### Example 1: Bundle only a single visualization type
  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 dist/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 dist/vis-custom.js -o dist/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="dist/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 dist/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.js* and *hammer.js* excluded. The generated bundle can be minified with uglifyjs:
  170. $ uglifyjs dist/vis-custom.js -o dist/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.17.1/moment.min.js"></script>
  178. <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
  179. <!-- load vis.js -->
  180. <script src="dist/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. The application can be bundled and minified:
  207. $ browserify app.js -o dist/app-bundle.js -t babelify
  208. $ uglifyjs dist/app-bundle.js -o dist/app-bundle.min.js
  209. And loaded into a webpage:
  210. ```html
  211. <!DOCTYPE HTML>
  212. <html>
  213. <head>
  214. <link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
  215. </head>
  216. <body>
  217. <div id="visualization"></div>
  218. <script src="dist/app-bundle.min.js"></script>
  219. </body>
  220. </html>
  221. ```
  222. #### Example 4: Integrate vis.js components directly in your webpack build
  223. You can integrate e.g. the timeline component directly in you webpack build.
  224. Therefor you just import the component-files from root direcory (starting with "index-").
  225. ```js
  226. var visTimeline = require('vis/index-timeline-graph2d');
  227. var container = document.getElementById('visualization');
  228. var data = new DataSet();
  229. var timeline = new Timeline(container, data, {});
  230. ```
  231. To get this to work you'll need to add the some babel-loader-setting:
  232. ```js
  233. module: {
  234. loaders: [{
  235. test: /node_modules[\\\/]vis[\\\/].*\.js$/,
  236. loader: 'babel',
  237. query: {
  238. cacheDirectory: true,
  239. presets: ["es2015"],
  240. plugins: [
  241. "transform-es3-property-literals",
  242. "transform-es3-member-expression-literals",
  243. "transform-runtime"
  244. ]
  245. }
  246. }]
  247. }
  248. ```
  249. ## Test
  250. To test the library, install the project dependencies once:
  251. $ npm install
  252. Then run the tests:
  253. $ npm run test
  254. ## License
  255. Copyright (C) 2010-2016 Almende B.V. and Contributors
  256. Vis.js is dual licensed under both
  257. * The Apache 2.0 License
  258. http://www.apache.org/licenses/LICENSE-2.0
  259. and
  260. * The MIT License
  261. http://opensource.org/licenses/MIT
  262. Vis.js may be distributed under either license.