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.

349 lines
9.9 KiB

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