Skip to content

Commit

Permalink
Removed the light version of vis.js, added documentation on custom bu…
Browse files Browse the repository at this point in the history
…ilds
  • Loading branch information
josdejong committed Jul 22, 2014
1 parent ada3e1f commit 2bde144
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 26,725 deletions.
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
misc
node_modules
src
test
tools
.idea
Expand Down
134 changes: 117 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"ignore": [
"misc",
"node_modules",
"lib",
"test",
"tools",
".idea",
Expand Down
Loading

0 comments on commit 2bde144

Please sign in to comment.