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.

368 lines
11 KiB

11 years ago
11 years ago
11 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. [![Percentage of issues still open](http://isitmaintained.com/badge/open/almende/vis.svg)](http://isitmaintained.com/project/almende/vis "Percentage of issues still open")
  28. [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/almende/vis.svg)](http://isitmaintained.com/project/almende/vis "Average time to resolve an issue")
  29. [![Pending Pull-Requests](http://githubbadges.herokuapp.com/almende/vis/pulls.svg)](https://github.com/almende/vis/pulls)
  30. [![Code Climate](https://codeclimate.com/github/almende/vis/badges/gpa.svg)](https://codeclimate.com/github/almende/vis)
  31. ## Install
  32. Install via npm:
  33. $ npm install vis
  34. Install via bower:
  35. $ bower install vis
  36. Link via cdnjs: http://cdnjs.com
  37. Or download the library from the github project:
  38. [https://github.com/almende/vis.git](https://github.com/almende/vis.git).
  39. ## Load
  40. To use a component, include the javascript and css files of vis in your web page:
  41. ```html
  42. <!DOCTYPE HTML>
  43. <html>
  44. <head>
  45. <script src="webroot/vis/dist/vis.js"></script>
  46. <link href="webroot/vis/dist/vis.css" rel="stylesheet" type="text/css" />
  47. </head>
  48. <body>
  49. <script type="text/javascript">
  50. // ... load a visualization
  51. </script>
  52. </body>
  53. </html>
  54. ```
  55. or load vis.js using require.js. Note that vis.css must be loaded too.
  56. ```js
  57. require.config({
  58. paths: {
  59. vis: 'path/to/vis/dist',
  60. }
  61. });
  62. require(['vis'], function (math) {
  63. // ... load a visualization
  64. });
  65. ```
  66. A timeline can be instantiated as:
  67. ```js
  68. var timeline = new vis.Timeline(container, data, options);
  69. ```
  70. Where `container` is an HTML element, `data` is an Array with data or a DataSet,
  71. and `options` is an optional object with configuration options for the
  72. component.
  73. ## Example
  74. A basic example on loading a Timeline is shown below. More examples can be
  75. found in the [examples directory](https://github.com/almende/vis/tree/master/examples)
  76. of the project.
  77. ```html
  78. <!DOCTYPE HTML>
  79. <html>
  80. <head>
  81. <title>Timeline basic demo</title>
  82. <script src="vis/dist/vis.js"></script>
  83. <link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
  84. <style type="text/css">
  85. body, html {
  86. font-family: sans-serif;
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <div id="visualization"></div>
  92. <script type="text/javascript">
  93. var container = document.getElementById('visualization');
  94. var data = [
  95. {id: 1, content: 'item 1', start: '2013-04-20'},
  96. {id: 2, content: 'item 2', start: '2013-04-14'},
  97. {id: 3, content: 'item 3', start: '2013-04-18'},
  98. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  99. {id: 5, content: 'item 5', start: '2013-04-25'},
  100. {id: 6, content: 'item 6', start: '2013-04-27'}
  101. ];
  102. var options = {};
  103. var timeline = new vis.Timeline(container, data, options);
  104. </script>
  105. </body>
  106. </html>
  107. ```
  108. ## Build
  109. To build the library from source, clone the project from github
  110. $ git clone git://github.com/almende/vis.git
  111. The source code uses the module style of node (require and module.exports) to
  112. organize dependencies. To install all dependencies and build the library,
  113. run `npm install` in the root of the project.
  114. $ cd vis
  115. $ npm install
  116. Then, the project can be build running:
  117. $ npm run build
  118. To automatically rebuild on changes in the source files, once can use
  119. $ npm run watch
  120. This will both build and minify the library on changes. Minifying is relatively
  121. slow, so when only the non-minified library is needed, one can use the
  122. `watch-dev` script instead:
  123. $ npm run watch-dev
  124. ## Custom builds
  125. 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*.
  126. 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.
  127. *Note that hammer.js version 2 is required as of v4.*
  128. ### Prerequisites
  129. Before you can do a build:
  130. - Install *node.js* and *npm* on your system: https://nodejs.org/
  131. - Install the following modules using npm: `browserify`, `babelify`, and `uglify-js`:
  132. ```
  133. $ [sudo] npm install -g browserify babelify uglify-js
  134. ```
  135. - Download or clone the vis.js project:
  136. ```
  137. $ git clone https://github.com/almende/vis.git
  138. ```
  139. - Install the dependencies of vis.js by running `npm install` in the root of the project:
  140. ```
  141. $ cd vis
  142. $ npm install
  143. ```
  144. ### Examples of custom builds
  145. #### Example 1: Bundle only a single visualization type
  146. 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:
  147. ```js
  148. exports.DataSet = require('./lib/DataSet');
  149. exports.Timeline = require('./lib/timeline/Timeline');
  150. ```
  151. Then create a custom bundle using browserify, like:
  152. $ browserify custom.js -t [ babelify --presets [es2015] ] -o dist/vis-custom.js -s vis
  153. 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:
  154. $ uglifyjs dist/vis-custom.js -o dist/vis-custom.min.js
  155. The custom bundle can now be loaded like:
  156. ```html
  157. <!DOCTYPE HTML>
  158. <html>
  159. <head>
  160. <script src="dist/vis-custom.min.js"></script>
  161. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  162. </head>
  163. <body>
  164. ...
  165. </body>
  166. </html>
  167. ```
  168. #### Example 2: Exclude external libraries
  169. 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:
  170. $ browserify index.js -t [ babelify --presets [es2015] ] -o dist/vis-custom.js -s vis -x moment -x hammerjs
  171. 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:
  172. $ uglifyjs dist/vis-custom.js -o dist/vis-custom.min.js
  173. The custom bundle can now be loaded as:
  174. ```html
  175. <!DOCTYPE HTML>
  176. <html>
  177. <head>
  178. <!-- load external dependencies -->
  179. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
  180. <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.8/hammer.min.js"></script>
  181. <!-- load vis.js -->
  182. <script src="dist/vis-custom.min.js"></script>
  183. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  184. </head>
  185. <body>
  186. ...
  187. </body>
  188. </html>
  189. ```
  190. #### Example 3: Bundle vis.js as part of your (commonjs) application
  191. When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file **app.js** containing:
  192. ```js
  193. var moment = require('moment');
  194. var DataSet = require('vis/lib/DataSet');
  195. var Timeline = require('vis/lib/timeline/Timeline');
  196. var container = document.getElementById('visualization');
  197. var data = new DataSet([
  198. {id: 1, content: 'item 1', start: moment('2013-04-20')},
  199. {id: 2, content: 'item 2', start: moment('2013-04-14')},
  200. {id: 3, content: 'item 3', start: moment('2013-04-18')},
  201. {id: 4, content: 'item 4', start: moment('2013-04-16'), end: moment('2013-04-19')},
  202. {id: 5, content: 'item 5', start: moment('2013-04-25')},
  203. {id: 6, content: 'item 6', start: moment('2013-04-27')}
  204. ]);
  205. var options = {};
  206. var timeline = new Timeline(container, data, options);
  207. ```
  208. The application can be bundled and minified:
  209. $ browserify app.js -o dist/app-bundle.js -t babelify
  210. $ uglifyjs dist/app-bundle.js -o dist/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="dist/app-bundle.min.js"></script>
  221. </body>
  222. </html>
  223. ```
  224. #### Example 4: Integrate vis.js components directly in your webpack build
  225. You can integrate e.g. the timeline component directly in you webpack build.
  226. Therefor you can e.g. import the component-files from root direcory (starting with "index-").
  227. ```js
  228. import { DataSet, Timeline } from 'vis/index-timeline-graph2d';
  229. var container = document.getElementById('visualization');
  230. var data = new DataSet();
  231. var timeline = new Timeline(container, data, {});
  232. ```
  233. To get this to work you'll need to add some babel-loader-setting to your webpack-config:
  234. ```js
  235. module: {
  236. module: {
  237. rules: [{
  238. test: /node_modules[\\\/]vis[\\\/].*\.js$/,
  239. loader: 'babel-loader',
  240. query: {
  241. cacheDirectory: true,
  242. presets: [ "babel-preset-es2015" ].map(require.resolve),
  243. plugins: [
  244. "transform-es3-property-literals", // #2452
  245. "transform-es3-member-expression-literals", // #2566
  246. "transform-runtime" // #2566
  247. ]
  248. }
  249. }]
  250. }
  251. }
  252. ```
  253. There is also an [demo-project](https://github.com/mojoaxel/vis-webpack-demo) showing the integration of vis.js using webpack.
  254. ## Test
  255. To test the library, install the project dependencies once:
  256. $ npm install
  257. Then run the tests:
  258. $ npm run test
  259. ## License
  260. Copyright (C) 2010-2017 Almende B.V. and Contributors
  261. Vis.js is dual licensed under both
  262. * The Apache 2.0 License
  263. http://www.apache.org/licenses/LICENSE-2.0
  264. and
  265. * The MIT License
  266. http://opensource.org/licenses/MIT
  267. Vis.js may be distributed under either license.