Skip to content

Commit 4ee3fd0

Browse files
committed
New GitBook documentation
1 parent f623a6b commit 4ee3fd0

File tree

10 files changed

+195
-49
lines changed

10 files changed

+195
-49
lines changed

README.md

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,50 @@
1-
# Defer initial chart updates
1+
<div align="center">
2+
<img src="docs/assets/banner.png"/>
3+
</div>
24

3-
[![npm](https://img.shields.io/npm/v/chartjs-plugin-deferred.svg?style=flat-square)](https://npmjs.com/package/chartjs-plugin-deferred) [![bower](https://img.shields.io/bower/v/chartjs-plugin-deferred.svg?style=flat-square)](https://libraries.io/bower/chartjs-plugin-deferred) [![travis](https://img.shields.io/travis/chartjs/chartjs-plugin-deferred.svg?style=flat-square)](https://travis-ci.org/chartjs/chartjs-plugin-deferred) [![codeclimate](https://img.shields.io/codeclimate/maintainability/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://codeclimate.com/github/chartjs/chartjs-plugin-deferred)
5+
[![github](https://img.shields.io/github/release/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest) [![travis](https://img.shields.io/travis/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://travis-ci.org/chartjs/chartjs-plugin-deferred) [![codeclimate](https://img.shields.io/codeclimate/maintainability/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://codeclimate.com/github/chartjs/chartjs-plugin-deferred)
46

57
[Chart.js](http://www.chartjs.org/) plugin to defer initial chart updates until the user scrolls and the canvas appears inside the viewport, and thus trigger the initial chart animations when the user is likely to see them.
68

79
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **2.6.0** or later.
810

9-
## Usage
11+
## Documentation
1012

11-
You can download the latest version of [chartjs-plugin-deferred on GitHub](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest)
13+
- [Installation](https://chartjs-plugin-deferred.netlify.com/installation)
14+
- [Options](https://chartjs-plugin-deferred.netlify.com/options)
1215

13-
## Configuration
16+
## Example
1417

15-
To configure this plugin, you can simply add the following entries to your chart options:
16-
17-
| Name | Type | Default | Description |
18-
| ---- | ---- | ------- | ----------- |
19-
| `plugins.deferred` | `Object/Boolean` | `true` | The deferred options (see `plugins.deferred.*` options). Also accepts a boolean, in which case if `true`, the chart will be deferred using the **global options**, else if `false`, the chart will not be deferred.
20-
| `plugins.deferred.xOffset` | `Number/String` | `0` | Number of pixels (or percent of the canvas width) from which the chart is considered inside the viewport.
21-
| `plugins.deferred.yOffset` | `Number/String` | `0` | Number of pixels (or percent of the canvas height) from which the chart is considered inside the viewport.
22-
| `plugins.deferred.delay` | `Number` | `0` | Number of milliseconds to delay the loading after the chart is considered inside the viewport.
23-
24-
> **Global options** can be change through `Chart.defaults.global.plugins.deferred`, which by default defer the chart loading until the first line of pixels of the canvas appears in the viewport.
25-
26-
For example:
27-
28-
```
29-
{
18+
```javascript
19+
new Chart(ctx, {
20+
// ... data ...
21+
options: {
22+
// ... other options ...
3023
plugins: {
31-
deferred: { // enabled by default
32-
xOffset: 150, // defer until 150px of the canvas width are inside the viewport
33-
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport
34-
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport
35-
}
24+
deferred: {
25+
xOffset: 150, // defer until 150px of the canvas width are inside the viewport
26+
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport
27+
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport
28+
}
3629
}
37-
}
30+
}
31+
});
3832
```
3933

4034
## Development
4135

4236
You first need to install node dependencies (requires [Node.js](https://nodejs.org/)):
4337

44-
```shell
45-
> npm install
46-
```
38+
> npm install
4739

4840
The following commands will then be available from the repository root:
4941

50-
```shell
51-
> gulp build // build dist files
52-
> gulp build --watch // build and watch for changes
53-
> gulp lint // perform code linting
54-
> gulp package // create an archive with dist files and samples
55-
```
42+
> gulp build // build dist files
43+
> gulp build --watch // build and watch for changes
44+
> gulp lint // perform code linting
45+
> gulp docs // generate GitBook documentation (`dist/docs`)
46+
> gulp package // create an archive with dist files and samples
5647

5748
## License
5849

59-
chartjs-plugin-deferred is available under the [MIT license](LICENSE.md).
50+
`chartjs-plugin-deferred` is available under the [MIT license](LICENSE.md).

book.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"root": "docs",
3+
"author": "chartjs",
4+
"gitbook": "3.2.2",
5+
"plugins": [
6+
"-lunr",
7+
"-search",
8+
"search-plus",
9+
"anchorjs",
10+
"ga"
11+
],
12+
"pluginsConfig": {
13+
"anchorjs": {
14+
"icon": "#",
15+
"placement": "left",
16+
"visible": "always"
17+
},
18+
"ga": {
19+
"token": "UA-99068522-3",
20+
"configuration": "auto"
21+
},
22+
"theme-default": {
23+
"showLevel": false,
24+
"styles": {
25+
"website": "assets/style.css"
26+
}
27+
}
28+
}
29+
}

docs/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
![chartjs-plugin-deferred](assets/banner.png)
2+
3+
[Chart.js](http://www.chartjs.org/) plugin to defer initial chart updates until the user scrolls and the canvas appears inside the viewport, and thus trigger the initial chart animations when the user is likely to see them.
4+
5+
**Important:** requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **2.6.0** or later.
6+
7+
## Table of Contents
8+
9+
{% include "SUMMARY.md" %}
10+
11+
## Example
12+
13+
```javascript
14+
new Chart(ctx, {
15+
// ... data ...
16+
options: {
17+
// ... other options ...
18+
plugins: {
19+
deferred: {
20+
xOffset: 150, // defer until 150px of the canvas width are inside the viewport
21+
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport
22+
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport
23+
}
24+
}
25+
}
26+
});
27+
```
28+
29+
## License
30+
31+
`chartjs-plugin-deferred` is available under the [MIT license](https://github.com/chartjs/chartjs-plugin-deferred/blob/master/LICENSE.md).

docs/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* [Installation](installation.md)
2+
* [Options](options.md)

docs/assets/banner.png

18 KB
Loading

docs/assets/style.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
a.anchorjs-link {
2+
color: rgba(65, 131, 196, 0.1);
3+
font-weight: 400;
4+
text-decoration: none;
5+
transition: color 100ms ease-out;
6+
z-index: 999;
7+
}
8+
9+
a.anchorjs-link:hover {
10+
color: rgba(65, 131, 196, 1);
11+
}
12+
13+
sup {
14+
font-size: 0.75em !important;
15+
}

docs/installation.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Installation
2+
3+
## npm
4+
5+
[![npm](https://img.shields.io/npm/v/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://npmjs.com/package/chartjs-plugin-deferred) [![npm downloads](https://img.shields.io/npm/dm/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://npmjs.com/package/chartjs-plugin-deferred)
6+
7+
npm install chartjs-plugin-deferred --save
8+
9+
## Bower
10+
11+
[![bower](https://img.shields.io/bower/v/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://libraries.io/bower/chartjs-plugin-deferred)
12+
13+
bower install chartjs-plugin-deferred --save
14+
15+
## CDN
16+
17+
[![jsdelivr](https://img.shields.io/npm/v/chartjs-plugin-deferred.svg?label=jsdelivr&style=flat-square&maxAge=600)](https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred@latest/dist/) [![jsdelivr hits](https://data.jsdelivr.com/v1/package/npm/chartjs-plugin-deferred/badge)](https://www.jsdelivr.com/package/npm/chartjs-plugin-deferred)
18+
19+
By default, `https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred` returns the latest (minified) version, however it's [**highly recommended**](https://www.jsdelivr.com/features) to always specify a version in order to avoid breaking changes. This can be achieved by appending `@{version}` to the url:
20+
21+
https://cdn.jsdelivr.net/npm/[email protected] // exact version
22+
https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred@1 // latest 1.x.x
23+
24+
Read more about jsDeliver versioning on their [website](http://www.jsdelivr.com/).
25+
26+
## Download
27+
28+
[![github](https://img.shields.io/github/release/chartjs/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest) [![github downloads](https://img.shields.io/github/downloads/chartjs/chartjs-plugin-deferred/total.svg?style=flat-square&maxAge=600)](http://www.somsubhra.com/github-release-stats/?username=chartjs&repository=chartjs-plugin-deferred)
29+
30+
You can download the latest version of `chartjs-plugin-deferred` from the [GitHub releases](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest):
31+
32+
- `chartjs-plugin-deferred.js` (recommended for development)
33+
- `chartjs-plugin-deferred.min.js` (recommended for production)
34+
- `chartjs-plugin-deferred.zip` (contains `.js` and `.min.js` versions + samples)

docs/options.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Options
2+
3+
The plugin options can be changed at 2 different levels and with the following priority:
4+
5+
- per chart: `options.plugins.deferred.*`
6+
- globally: `Chart.defaults.global.plugins.deferred.*`
7+
8+
Available options:
9+
10+
| Name | Type | Default
11+
| ---- | ---- | ----
12+
| [`delay`](#delay) | `Number` | `0`
13+
| [`xOffset`](#xoffset) | `Number/String` | `0`
14+
| [`yOffset`](#yoffset) | `Number/String` | `0`
15+
16+
> **Note:** default options defer the chart loading until the first line of pixels of the canvas appears in the viewport
17+
18+
## `delay`
19+
Number of milliseconds to delay the loading after the chart is considered inside the viewport.
20+
21+
## `xOffset`
22+
Number of pixels (or percent of the canvas width) from which the chart is considered inside the viewport.
23+
24+
## `yOffset`
25+
Number of pixels (or percent of the canvas height) from which the chart is considered inside the viewport.

gulpfile.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var argv = require('yargs').argv;
43
var gulp = require('gulp');
54
var eslint = require('gulp-eslint');
65
var file = require('gulp-file');
@@ -14,11 +13,13 @@ var merge = require('merge2');
1413
var path = require('path');
1514
var rollup = require('rollup-stream');
1615
var source = require('vinyl-source-stream');
16+
var {exec} = require('mz/child_process');
1717
var pkg = require('./package.json');
1818

19-
var srcDir = './src/';
20-
var outDir = './dist/';
21-
var samplesDir = './samples/';
19+
var argv = require('yargs')
20+
.option('output', {alias: 'o', default: 'dist'})
21+
.option('docs-dir', {default: 'docs'})
22+
.argv;
2223

2324
function watch(glob, task) {
2425
gutil.log('Waiting for changes...');
@@ -33,27 +34,28 @@ function watch(glob, task) {
3334
gulp.task('default', ['build']);
3435

3536
gulp.task('build', function() {
37+
var out = argv.output;
3638
var task = function() {
3739
return rollup('rollup.config.js')
3840
.pipe(source(pkg.name + '.js'))
39-
.pipe(gulp.dest(outDir))
41+
.pipe(gulp.dest(out))
4042
.pipe(rename(pkg.name + '.min.js'))
4143
.pipe(streamify(uglify({output: {comments: 'some'}})))
42-
.pipe(gulp.dest(outDir));
44+
.pipe(gulp.dest(out));
4345
};
4446

4547
var tasks = [task()];
4648
if (argv.watch) {
47-
tasks.push(watch(srcDir + '**/*.js', task));
49+
tasks.push(watch('src/**/*.js', task));
4850
}
4951

5052
return tasks;
5153
});
5254

5355
gulp.task('lint', function() {
5456
var files = [
55-
samplesDir + '**/*.js',
56-
srcDir + '**/*.js',
57+
'samples/**/*.js',
58+
'src/**/*.js',
5759
'*.js'
5860
];
5961

@@ -63,20 +65,35 @@ gulp.task('lint', function() {
6365
.pipe(eslint.failAfterError());
6466
});
6567

68+
gulp.task('docs', function(done) {
69+
var script = require.resolve('gitbook-cli/bin/gitbook.js');
70+
var out = path.join(argv.output, argv.docsDir);
71+
var cmd = process.execPath;
72+
73+
exec([cmd, script, 'install', './'].join(' ')).then(() => {
74+
return exec([cmd, script, 'build', './', out].join(' '));
75+
}).then(() => {
76+
done();
77+
}).catch((err) => {
78+
done(new Error(err.stdout || err));
79+
});
80+
});
81+
6682
gulp.task('package', function() {
83+
var out = argv.output;
6784
var streams = merge(
6885
// gather "regular" files landing in the package root
69-
gulp.src([outDir + '*.js', 'LICENSE.md']),
86+
gulp.src([out + '*.js', 'LICENSE.md']),
7087

7188
// dist files in the package are in the root, so we need to rewrite samples
7289
// src="../dist/ to src="../ and then copy them in the /samples directory.
73-
gulp.src(samplesDir + '**/*', {base: '.'})
90+
gulp.src('samples/**/*', {base: '.'})
7491
.pipe(streamify(replace('src="../dist/', 'src="../')))
7592
);
7693

7794
return streams
7895
.pipe(zip(pkg.name + '.zip'))
79-
.pipe(gulp.dest(outDir));
96+
.pipe(gulp.dest(out));
8097
});
8198

8299
gulp.task('bower', function() {
@@ -86,7 +103,7 @@ gulp.task('bower', function() {
86103
homepage: pkg.homepage,
87104
license: pkg.license,
88105
version: pkg.version,
89-
main: outDir + pkg.name + '.js'
106+
main: argv.output + pkg.name + '.js'
90107
}, null, 2);
91108

92109
return file('bower.json', json, {src: true})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
},
1212
"devDependencies": {
1313
"eslint-config-chartjs": "^0.1.0",
14+
"gitbook-cli": "^2.3.2",
1415
"gulp": "^3.9.1",
1516
"gulp-eslint": "^4.0.1",
1617
"gulp-file": "^0.4.0",
@@ -21,6 +22,7 @@
2122
"gulp-util": "^3.0.7",
2223
"gulp-zip": "^4.1.0",
2324
"merge2": "^1.2.1",
25+
"mz": "^2.7.0",
2426
"path": "^0.12.7",
2527
"rollup": "^0.53.4",
2628
"rollup-stream": "^1.24.1",

0 commit comments

Comments
 (0)