Browse Source

Removed the light version of vis.js, added documentation on custom builds

v3_develop
jos 10 years ago
parent
commit
f6a9660239
10 changed files with 121 additions and 26727 deletions
  1. +0
    -1
      .npmignore
  2. +117
    -17
      README.md
  3. +0
    -1
      bower.json
  4. +0
    -26576
      dist/vis-light.js
  5. +0
    -1
      dist/vis-light.map
  6. +0
    -36
      dist/vis-light.min.js
  7. +1
    -1
      dist/vis.js
  8. +1
    -1
      dist/vis.min.js
  9. +0
    -55
      examples/timeline/19_vis_light_bundle.html
  10. +2
    -38
      gulpfile.js

+ 0
- 1
.npmignore View File

@ -1,6 +1,5 @@
misc
node_modules
src
test
tools
.idea

+ 117
- 17
README.md View File

@ -57,7 +57,7 @@ or load vis.js using require.js. Note that vis.css must be loaded too.
```js
require.config({
paths: {
vis: 'path/to/vis',
vis: 'path/to/vis/dist',
}
});
require(['vis'], function (math) {
@ -76,22 +76,6 @@ Where `container` is an HTML element, `data` is an Array with data or a DataSet,
and `options` is an optional object with configuration options for the
component.
### Bundles
The folder `dist` contains bundled versions of vis.js for direct use in the browser. In general, to use vis, load the files `vis.js` and `vis.css`.
vis.js offers various bundled files: default or light version, and minified or non-minified. 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. Note that hammer.js v1.0.6 or newer is required.
Bundle | Files | Description
------ | ----- | -----------
default | vis.js, vis.css | The default bundle, fully standalone. Code is not minified, use this version for development.
default minified | vis.min.js, vis.min.css | The default bundle, fully standalone. Code is minified, use this version for production.
light | vis-light.js, vis.css | The light bundle. External libraries [moment.js](http://momentjs.com/) and [hammer.js](http://hammerjs.github.io/) are excluded and need to be loaded before loading vis. Code is not minified, use this version for development.
light minified | vis-light.min.js, vis.min.css | The light bundle. External libraries [moment.js](http://momentjs.com/) and [hammer.js](http://hammerjs.github.io/) are excluded and need to be loaded before loading vis. Codee is minified, use this version for production.
## Example
@ -162,6 +146,122 @@ slow, so when only the non-minified library is needed, one can use the
npm run watch-dev
## Custom builds
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.
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. Note that hammer.js v1.0.6 or newer is required.
#### Example 1: Bundle a single visualization
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:
```js
exports.DataSet = require('./lib/DataSet');
exports.Timeline = require('./lib/timeline/Timeline');
```
Install browserify globally via `[sudo] npm install -g browserify`, then create a custom bundle like:
browserify custom.js -o vis-custom.js -s vis
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`):
uglifyjs vis-custom.js -o vis-custom.min.js
The custom bundle can now be loaded like:
```html
<!DOCTYPE HTML>
<html>
<head>
<script src="vis-custom.min.js"></script>
<link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
...
</body>
</html>
```
#### Example 2: Exclude external libraries
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:
browserify index.js -o vis-custom.js -s vis -x moment -x hammerjs
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:
uglifyjs vis-custom.js -o vis-custom.min.js
The custom bundle can now be loaded as:
```html
<!DOCTYPE HTML>
<html>
<head>
<!-- load external dependencies -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/1.1.3/hammer.min.js"></script>
<!-- load vis.js -->
<script src="vis-custom.min.js"></script>
<link href="dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
...
</body>
</html>
```
#### Example 3: Bundle vis.js as part of your (commonjs) application
When writing a web application with commonjs modules, vis.js can be packaged automatically into the application. Create a file **app.js** containing:
```js
var moment = require('moment');
var DataSet = require('vis/lib/DataSet');
var Timeline = require('vis/lib/timeline/Timeline');
var container = document.getElementById('visualization');
var data = new DataSet([
{id: 1, content: 'item 1', start: moment('2013-04-20')},
{id: 2, content: 'item 2', start: moment('2013-04-14')},
{id: 3, content: 'item 3', start: moment('2013-04-18')},
{id: 4, content: 'item 4', start: moment('2013-04-16'), end: moment('2013-04-19')},
{id: 5, content: 'item 5', start: moment('2013-04-25')},
{id: 6, content: 'item 6', start: moment('2013-04-27')}
]);
var options = {};
var timeline = new Timeline(container, data, options);
```
Install the application dependencies via npm:
npm install vis moment
The application can be bundled and minified:
browserify app.js -o app-bundle.js
uglifyjs app-bundle.js -o app-bundle.min.js
And loaded into a webpage:
```html
<!DOCTYPE HTML>
<html>
<head>
<link href="node_modules/vis/dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="visualization"></div>
<script src="app-bundle.min.js"></script>
</body>
</html>
```
## Test
To test the library, install the project dependencies once:

+ 0
- 1
bower.json View File

@ -10,7 +10,6 @@
"ignore": [
"misc",
"node_modules",
"lib",
"test",
"tools",
".idea",

+ 0
- 26576
dist/vis-light.js
File diff suppressed because it is too large
View File


+ 0
- 1
dist/vis-light.map
File diff suppressed because it is too large
View File


+ 0
- 36
dist/vis-light.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
dist/vis.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 3.0.1-SNAPSHOT
* @date 2014-07-21
* @date 2014-07-22
*
* @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com

+ 1
- 1
dist/vis.min.js View File

@ -5,7 +5,7 @@
* A dynamic, browser-based visualization library.
*
* @version 3.0.1-SNAPSHOT
* @date 2014-07-21
* @date 2014-07-22
*
* @license
* Copyright (C) 2011-2014 Almende B.V, http://almende.com

+ 0
- 55
examples/timeline/19_vis_light_bundle.html View File

@ -1,55 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Timeline | Light bundle</title>
<style type="text/css">
body, html {
font-family: arial;
}
p {
max-width: 600px;
}
</style>
<!--
load external libraries
-->
<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.7.0/moment.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/hammer.js/1.0.5/hammer.min.js"></script>
<script src="../../dist/vis-light.min.js"></script>
<link href="../../dist/vis.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>
The light bundle of vis.js (<code>vis-light.js</code> or <code>vis-light.min.js</code>) don't have the external dependencies of moment.js and hammer.js bundled. You have to load these yourself before loading vis-light.js. This is useful in the case that your application is using moment.js and/or hammer.js itself too, in order not to load these libraries twice. Note that it is possible too to create your own vis.js bundle: the source code consists of common.js modules which is browserifiable.
</p>
<div id="visualization"></div>
<script type="text/javascript">
// DOM element where the Timeline will be attached
var container = document.getElementById('visualization');
// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet([
{id: 1, content: 'item 1', start: '2014-04-20'},
{id: 2, content: 'item 2', start: '2014-04-14'},
{id: 3, content: 'item 3', start: '2014-04-18'},
{id: 4, content: 'item 4', start: '2014-04-16', end: '2014-04-19'},
{id: 5, content: 'item 5', start: '2014-04-25'},
{id: 6, content: 'item 6', start: '2014-04-27', type: 'point'}
]);
// Configuration for the Timeline
var options = {
editable: true
};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
</script>
</body>
</html>

+ 2
- 38
gulpfile.js View File

@ -16,9 +16,6 @@ var DIST = './dist';
var VIS_JS = 'vis.js';
var VIS_MAP = 'vis.map';
var VIS_MIN_JS = 'vis.min.js';
var VIS_LIGHT_JS = 'vis-light.js';
var VIS_LIGHT_MAP = 'vis-light.map';
var VIS_LIGHT_MIN_JS = 'vis-light.min.js';
var VIS_CSS = 'vis.css';
var VIS_MIN_CSS = 'vis.min.css';
@ -55,23 +52,6 @@ var webpackConfig = {
cache: true
};
var webpackConfigLight = {
entry: ENTRY,
output: {
library: 'vis',
libraryTarget: 'umd',
path: DIST,
filename: VIS_LIGHT_JS,
sourcePrefix: ' '
},
externals: [
'hammerjs',
'moment'
],
plugins: [ bannerPlugin ],
cache: true
};
var uglifyConfig = {
outSourceMap: VIS_MAP,
output: {
@ -81,7 +61,6 @@ var uglifyConfig = {
// create a single instance of the compiler to allow caching
var compiler = webpack(webpackConfig);
var compilerLight = webpack(webpackConfigLight);
// clean the dist/img directory
gulp.task('clean', function (cb) {
@ -98,16 +77,6 @@ gulp.task('bundle-js', ['clean'], function (cb) {
});
});
gulp.task('bundle-js-light', ['clean'], function (cb) {
// update the banner contents (has a date in it which should stay up to date)
bannerPlugin.banner = createBanner();
compilerLight.run(function (err, stats) {
if (err) gutil.log(err);
cb();
});
});
// bundle and minify css
gulp.task('bundle-css', ['clean'], function () {
var files = [
@ -149,20 +118,15 @@ gulp.task('copy', ['clean'], function () {
});
gulp.task('minify', ['bundle-js'], function (cb) {
// minify full version of vis.js
var result = uglify.minify([DIST + '/' + VIS_JS], uglifyConfig);
fs.writeFileSync(DIST + '/' + VIS_MIN_JS, result.code);
fs.writeFileSync(DIST + '/' + VIS_MAP, result.map);
// minify light version of vis.js (external dependencies excluded)
var result = uglify.minify([DIST + '/' + VIS_LIGHT_JS], uglifyConfig);
fs.writeFileSync(DIST + '/' + VIS_LIGHT_MIN_JS, result.code);
fs.writeFileSync(DIST + '/' + VIS_LIGHT_MAP, result.map);
cb();
});
gulp.task('bundle', ['bundle-js', 'bundle-js-light', 'bundle-css', 'copy']);
gulp.task('bundle', ['bundle-js', 'bundle-css', 'copy']);
// read command line arguments --bundle and --minify
var bundle = 'bundle' in argv;

Loading…
Cancel
Save