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.

369 lines
12 KiB

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