-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f623a6b
commit 4ee3fd0
Showing
10 changed files
with
195 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,50 @@ | ||
# Defer initial chart updates | ||
<div align="center"> | ||
<img src="docs/assets/banner.png"/> | ||
</div> | ||
|
||
[![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) | ||
[![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) | ||
|
||
[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. | ||
|
||
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **2.6.0** or later. | ||
|
||
## Usage | ||
## Documentation | ||
|
||
You can download the latest version of [chartjs-plugin-deferred on GitHub](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest) | ||
- [Installation](https://chartjs-plugin-deferred.netlify.com/installation) | ||
- [Options](https://chartjs-plugin-deferred.netlify.com/options) | ||
|
||
## Configuration | ||
## Example | ||
|
||
To configure this plugin, you can simply add the following entries to your chart options: | ||
|
||
| Name | Type | Default | Description | | ||
| ---- | ---- | ------- | ----------- | | ||
| `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. | ||
| `plugins.deferred.xOffset` | `Number/String` | `0` | Number of pixels (or percent of the canvas width) from which the chart is considered inside the viewport. | ||
| `plugins.deferred.yOffset` | `Number/String` | `0` | Number of pixels (or percent of the canvas height) from which the chart is considered inside the viewport. | ||
| `plugins.deferred.delay` | `Number` | `0` | Number of milliseconds to delay the loading after the chart is considered inside the viewport. | ||
|
||
> **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. | ||
For example: | ||
|
||
``` | ||
{ | ||
```javascript | ||
new Chart(ctx, { | ||
// ... data ... | ||
options: { | ||
// ... other options ... | ||
plugins: { | ||
deferred: { // enabled by default | ||
xOffset: 150, // defer until 150px of the canvas width are inside the viewport | ||
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport | ||
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport | ||
} | ||
deferred: { | ||
xOffset: 150, // defer until 150px of the canvas width are inside the viewport | ||
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport | ||
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
## Development | ||
|
||
You first need to install node dependencies (requires [Node.js](https://nodejs.org/)): | ||
|
||
```shell | ||
> npm install | ||
``` | ||
> npm install | ||
|
||
The following commands will then be available from the repository root: | ||
|
||
```shell | ||
> gulp build // build dist files | ||
> gulp build --watch // build and watch for changes | ||
> gulp lint // perform code linting | ||
> gulp package // create an archive with dist files and samples | ||
``` | ||
> gulp build // build dist files | ||
> gulp build --watch // build and watch for changes | ||
> gulp lint // perform code linting | ||
> gulp docs // generate GitBook documentation (`dist/docs`) | ||
> gulp package // create an archive with dist files and samples | ||
|
||
## License | ||
|
||
chartjs-plugin-deferred is available under the [MIT license](LICENSE.md). | ||
`chartjs-plugin-deferred` is available under the [MIT license](LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"root": "docs", | ||
"author": "chartjs", | ||
"gitbook": "3.2.2", | ||
"plugins": [ | ||
"-lunr", | ||
"-search", | ||
"search-plus", | ||
"anchorjs", | ||
"ga" | ||
], | ||
"pluginsConfig": { | ||
"anchorjs": { | ||
"icon": "#", | ||
"placement": "left", | ||
"visible": "always" | ||
}, | ||
"ga": { | ||
"token": "UA-99068522-3", | ||
"configuration": "auto" | ||
}, | ||
"theme-default": { | ||
"showLevel": false, | ||
"styles": { | ||
"website": "assets/style.css" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
![chartjs-plugin-deferred](assets/banner.png) | ||
|
||
[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. | ||
|
||
**Important:** requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **2.6.0** or later. | ||
|
||
## Table of Contents | ||
|
||
{% include "SUMMARY.md" %} | ||
|
||
## Example | ||
|
||
```javascript | ||
new Chart(ctx, { | ||
// ... data ... | ||
options: { | ||
// ... other options ... | ||
plugins: { | ||
deferred: { | ||
xOffset: 150, // defer until 150px of the canvas width are inside the viewport | ||
yOffset: '50%', // defer until 50% of the canvas height are inside the viewport | ||
delay: 500 // delay of 500 ms after the canvas is considered inside the viewport | ||
} | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
## License | ||
|
||
`chartjs-plugin-deferred` is available under the [MIT license](https://github.com/chartjs/chartjs-plugin-deferred/blob/master/LICENSE.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* [Installation](installation.md) | ||
* [Options](options.md) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
a.anchorjs-link { | ||
color: rgba(65, 131, 196, 0.1); | ||
font-weight: 400; | ||
text-decoration: none; | ||
transition: color 100ms ease-out; | ||
z-index: 999; | ||
} | ||
|
||
a.anchorjs-link:hover { | ||
color: rgba(65, 131, 196, 1); | ||
} | ||
|
||
sup { | ||
font-size: 0.75em !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Installation | ||
|
||
## npm | ||
|
||
[![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) | ||
|
||
npm install chartjs-plugin-deferred --save | ||
|
||
## Bower | ||
|
||
[![bower](https://img.shields.io/bower/v/chartjs-plugin-deferred.svg?style=flat-square&maxAge=600)](https://libraries.io/bower/chartjs-plugin-deferred) | ||
|
||
bower install chartjs-plugin-deferred --save | ||
|
||
## CDN | ||
|
||
[![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) | ||
|
||
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: | ||
|
||
https://cdn.jsdelivr.net/npm/[email protected] // exact version | ||
https://cdn.jsdelivr.net/npm/chartjs-plugin-deferred@1 // latest 1.x.x | ||
|
||
Read more about jsDeliver versioning on their [website](http://www.jsdelivr.com/). | ||
|
||
## Download | ||
|
||
[![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) | ||
|
||
You can download the latest version of `chartjs-plugin-deferred` from the [GitHub releases](https://github.com/chartjs/chartjs-plugin-deferred/releases/latest): | ||
|
||
- `chartjs-plugin-deferred.js` (recommended for development) | ||
- `chartjs-plugin-deferred.min.js` (recommended for production) | ||
- `chartjs-plugin-deferred.zip` (contains `.js` and `.min.js` versions + samples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Options | ||
|
||
The plugin options can be changed at 2 different levels and with the following priority: | ||
|
||
- per chart: `options.plugins.deferred.*` | ||
- globally: `Chart.defaults.global.plugins.deferred.*` | ||
|
||
Available options: | ||
|
||
| Name | Type | Default | ||
| ---- | ---- | ---- | ||
| [`delay`](#delay) | `Number` | `0` | ||
| [`xOffset`](#xoffset) | `Number/String` | `0` | ||
| [`yOffset`](#yoffset) | `Number/String` | `0` | ||
|
||
> **Note:** default options defer the chart loading until the first line of pixels of the canvas appears in the viewport | ||
## `delay` | ||
Number of milliseconds to delay the loading after the chart is considered inside the viewport. | ||
|
||
## `xOffset` | ||
Number of pixels (or percent of the canvas width) from which the chart is considered inside the viewport. | ||
|
||
## `yOffset` | ||
Number of pixels (or percent of the canvas height) from which the chart is considered inside the viewport. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters