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.

292 lines
8.4 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  1. vis.js
  2. ==================
  3. Vis.js is a dynamic, browser based visualization library.
  4. The library is designed to be easy to use, handle large amounts
  5. of dynamic data, and enable manipulation of the data.
  6. The library consists of the following components:
  7. - DataSet and DataView. A flexible key/value based data set. Add, update, and
  8. remove items. Subscribe on changes in the data set. A DataSet can filter and
  9. order items, and convert fields of items.
  10. - DataView. A filtered and/or formatted view on a DataSet.
  11. - Graph2d. Plot data on a timeline with lines or barcharts.
  12. - Graph3d. Display data in a three dimensional graph.
  13. - Network. Display a network (force directed graph) with nodes and edges.
  14. - Timeline. Display different types of data on a timeline.
  15. The vis.js library is developed by [Almende B.V](http://almende.com).
  16. ## Install
  17. Install via npm:
  18. npm install vis
  19. Install via bower:
  20. bower install vis
  21. Or download the library from the github project:
  22. [https://github.com/almende/vis.git](https://github.com/almende/vis.git).
  23. ## Load
  24. To use a component, include the javascript and css files of vis in your web page:
  25. ```html
  26. <!DOCTYPE HTML>
  27. <html>
  28. <head>
  29. <script src="components/vis/dist/vis.js"></script>
  30. <link href="components/vis/dist/vis.css" rel="stylesheet" type="text/css" />
  31. </head>
  32. <body>
  33. <script type="text/javascript">
  34. // ... load a visualization
  35. </script>
  36. </body>
  37. </html>
  38. ```
  39. or load vis.js using require.js. Note that vis.css must be loaded too.
  40. ```js
  41. require.config({
  42. paths: {
  43. vis: 'path/to/vis/dist',
  44. }
  45. });
  46. require(['vis'], function (math) {
  47. // ... load a visualization
  48. });
  49. ```
  50. A timeline can be instantiated as:
  51. ```js
  52. var timeline = new vis.Timeline(container, data, options);
  53. ```
  54. Where `container` is an HTML element, `data` is an Array with data or a DataSet,
  55. and `options` is an optional object with configuration options for the
  56. component.
  57. ## Example
  58. A basic example on loading a Timeline is shown below. More examples can be
  59. found in the [examples directory](https://github.com/almende/vis/tree/master/examples)
  60. of the project.
  61. ```html
  62. <!DOCTYPE HTML>
  63. <html>
  64. <head>
  65. <title>Timeline basic demo</title>
  66. <script src="vis/dist/vis.js"></script>
  67. <link href="vis/dist/vis.css" rel="stylesheet" type="text/css" />
  68. <style type="text/css">
  69. body, html {
  70. font-family: sans-serif;
  71. }
  72. </style>
  73. </head>
  74. <body>
  75. <div id="visualization"></div>
  76. <script type="text/javascript">
  77. var container = document.getElementById('visualization');
  78. var data = [
  79. {id: 1, content: 'item 1', start: '2013-04-20'},
  80. {id: 2, content: 'item 2', start: '2013-04-14'},
  81. {id: 3, content: 'item 3', start: '2013-04-18'},
  82. {id: 4, content: 'item 4', start: '2013-04-16', end: '2013-04-19'},
  83. {id: 5, content: 'item 5', start: '2013-04-25'},
  84. {id: 6, content: 'item 6', start: '2013-04-27'}
  85. ];
  86. var options = {};
  87. var timeline = new vis.Timeline(container, data, options);
  88. </script>
  89. </body>
  90. </html>
  91. ```
  92. ## Build
  93. To build the library from source, clone the project from github
  94. git clone git://github.com/almende/vis.git
  95. The source code uses the module style of node (require and module.exports) to
  96. organize dependencies. To install all dependencies and build the library,
  97. run `npm install` in the root of the project.
  98. cd vis
  99. npm install
  100. Then, the project can be build running:
  101. npm run build
  102. To automatically rebuild on changes in the source files, once can use
  103. npm run watch
  104. This will both build and minify the library on changes. Minifying is relatively
  105. slow, so when only the non-minified library is needed, one can use the
  106. `watch-dev` script instead:
  107. npm run watch-dev
  108. ## Custom builds
  109. The folder `dist` contains bundled versions of vis.js for direct use in the browser. These bundles contain the all visualizations and includes external dependencies such as hammer.js and moment.js.
  110. 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.
  111. *Note that hammer.js version 1 is required (v1.0.6-v1.1.3), version 2 is not yet supported.*
  112. #### Example 1: Bundle a single visualization
  113. 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:
  114. ```js
  115. exports.DataSet = require('./lib/DataSet');
  116. exports.Timeline = require('./lib/timeline/Timeline');
  117. ```
  118. Install browserify globally via `[sudo] npm install -g browserify`, then create a custom bundle like:
  119. browserify custom.js -o vis-custom.js -s vis
  120. 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 with uglifyjs (installed globally with `[sudo] npm install -g uglify-js`):
  121. uglifyjs vis-custom.js -o vis-custom.min.js
  122. The custom bundle can now be loaded like:
  123. ```html
  124. <!DOCTYPE HTML>
  125. <html>
  126. <head>
  127. <script src="vis-custom.min.js"></script>
  128. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  129. </head>
  130. <body>
  131. ...
  132. </body>
  133. </html>
  134. ```
  135. #### Example 2: Exclude external libraries
  136. 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:
  137. browserify index.js -o vis-custom.js -s vis -x moment -x hammerjs
  138. 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:
  139. uglifyjs vis-custom.js -o vis-custom.min.js
  140. The custom bundle can now be loaded as:
  141. ```html
  142. <!DOCTYPE HTML>
  143. <html>
  144. <head>
  145. <!-- load external dependencies -->
  146. <script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
  147. <script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/1.1.3/hammer.min.js"></script>
  148. <!-- load vis.js -->
  149. <script src="vis-custom.min.js"></script>
  150. <link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
  151. </head>
  152. <body>
  153. ...
  154. </body>
  155. </html>
  156. ```
  157. #### Example 3: Bundle vis.js as part of your (commonjs) application
  158. When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file **app.js** containing:
  159. ```js
  160. var moment = require('moment');
  161. var DataSet = require('vis/lib/DataSet');
  162. var Timeline = require('vis/lib/timeline/Timeline');
  163. var container = document.getElementById('visualization');
  164. var data = new DataSet([
  165. {id: 1, content: 'item 1', start: moment('2013-04-20')},
  166. {id: 2, content: 'item 2', start: moment('2013-04-14')},
  167. {id: 3, content: 'item 3', start: moment('2013-04-18')},
  168. {id: 4, content: 'item 4', start: moment('2013-04-16'), end: moment('2013-04-19')},
  169. {id: 5, content: 'item 5', start: moment('2013-04-25')},
  170. {id: 6, content: 'item 6', start: moment('2013-04-27')}
  171. ]);
  172. var options = {};
  173. var timeline = new Timeline(container, data, options);
  174. ```
  175. Install the application dependencies via npm:
  176. npm install vis moment
  177. The application can be bundled and minified:
  178. browserify app.js -o app-bundle.js
  179. uglifyjs app-bundle.js -o app-bundle.min.js
  180. And loaded into a webpage:
  181. ```html
  182. <!DOCTYPE HTML>
  183. <html>
  184. <head>
  185. <link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
  186. </head>
  187. <body>
  188. <div id="visualization"></div>
  189. <script src="app-bundle.min.js"></script>
  190. </body>
  191. </html>
  192. ```
  193. ## Test
  194. To test the library, install the project dependencies once:
  195. npm install
  196. Then run the tests:
  197. npm test
  198. ## License
  199. Copyright (C) 2010-2014 Almende B.V.
  200. Licensed under the Apache License, Version 2.0 (the "License");
  201. you may not use this file except in compliance with the License.
  202. You may obtain a copy of the License at
  203. http://www.apache.org/licenses/LICENSE-2.0
  204. Unless required by applicable law or agreed to in writing, software
  205. distributed under the License is distributed on an "AS IS" BASIS,
  206. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  207. See the License for the specific language governing permissions and
  208. limitations under the License.