Skip to content

Commit 3974065

Browse files
authored
Update README (#459)
1 parent e612e66 commit 3974065

File tree

1 file changed

+9
-160
lines changed

1 file changed

+9
-160
lines changed

README.md

Lines changed: 9 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,20 @@
11
# chartjs-plugin-zoom
22

3+
[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/chartjs/chartjs-plugin-zoom/Node.js%20CI)](https://github.com/chartjs/chartjs-plugin-zoom/actions/workflows/ci.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/chartjs/chartjs-plugin-zoom/badge.svg?branch=master)](https://coveralls.io/github/chartjs/chartjs-plugin-zoom?branch=master)
5+
[![release](https://img.shields.io/github/v/release/chartjs/chartjs-plugin-zoom?include_prereleases)](https://github.com/chartjs/chartjs-plugin-zoom/releases)
6+
[![npm (latest)](https://img.shields.io/npm/v/chartjs-plugin-zoom/latest)](https://www.npmjs.com/package/chartjs-plugin-zoom/v/latest)
7+
[![npm (next)](https://img.shields.io/npm/v/chartjs-plugin-zoom/next)](https://www.npmjs.com/package/chartjs-plugin-zoom/v/next)
8+
[![documentation](https://img.shields.io/static/v1?message=Documentation&color=informational)](https://www.chartjs.org/chartjs-plugin-zoom/index)
9+
<a href="https://github.com/chartjs/awesome"><img src="https://awesome.re/badge-flat2.svg" alt="Awesome"></a>
10+
311
A zoom and pan plugin for Chart.js >= 3.0.0
412

513
For Chart.js 2.6.0 to 2.9.x support, use [version 0.7.7 of this plugin](https://github.com/chartjs/chartjs-plugin-zoom/releases/tag/v0.7.7).
614

715
Panning can be done via the mouse or with a finger.
816
Zooming is done via the mouse wheel or via a pinch gesture. [Hammer.js](https://hammerjs.github.io/) is used for gesture recognition.
917

10-
[Live Codepen Demo](https://codepen.io/jledentu/pen/NWWZryv)
11-
12-
## Installation
13-
14-
Run `npm install --save chartjs-plugin-zoom` to install with `npm`.
15-
16-
If including via a `<script>` tag, make sure to include `Hammer.js` as well:
17-
18-
```html
19-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
20-
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
21-
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@next"></script>
22-
```
23-
24-
## Configuration
25-
26-
To configure the zoom and pan plugin, you can simply add new config options to your chart config.
27-
28-
```javascript
29-
plugins: {
30-
zoom: {
31-
// Container for pan options
32-
pan: {
33-
// Boolean to enable panning
34-
enabled: true,
35-
36-
// Panning directions. Remove the appropriate direction to disable
37-
// Eg. 'y' would only allow panning in the y direction
38-
// A function that is called as the user is panning and returns the
39-
// available directions can also be used:
40-
// mode: function({ chart }) {
41-
// return 'xy';
42-
// },
43-
mode: 'xy',
44-
45-
// Which of the enabled panning directions should only be available
46-
// when the mouse cursor is over one of scale.
47-
overScaleMode: 'xy',
48-
49-
rangeMin: {
50-
// Format of min pan range depends on scale type
51-
x: null,
52-
y: null
53-
},
54-
rangeMax: {
55-
// Format of max pan range depends on scale type
56-
x: null,
57-
y: null
58-
},
59-
60-
// On category scale, factor of pan velocity
61-
speed: 20,
62-
63-
// Minimal pan distance required before actually applying pan
64-
threshold: 10,
65-
66-
// Function called while the user is panning
67-
onPan: function({chart}) { console.log(`I'm panning!!!`); },
68-
// Function called once panning is completed
69-
onPanComplete: function({chart}) { console.log(`I was panned!!!`); },
70-
// Function called when pan fails because modifier key was not detected.
71-
// event is the a hammer event that failed - see https://hammerjs.github.io/api#event-object
72-
onPanRejected: function({chart, event}) { console.log(`I didn't start panning!`); }
73-
},
74-
75-
// Container for zoom options
76-
zoom: {
77-
// Boolean to enable zooming
78-
enabled: true,
79-
80-
// Enable drag-to-zoom behavior
81-
drag: true,
82-
83-
// Drag-to-zoom effect can be customized
84-
// drag: {
85-
// borderColor: 'rgba(225,225,225,0.3)'
86-
// borderWidth: 5,
87-
// backgroundColor: 'rgb(225,225,225)',
88-
// },
89-
90-
// Zooming directions. Remove the appropriate direction to disable
91-
// Eg. 'y' would only allow zooming in the y direction
92-
// A function that is called as the user is zooming and returns the
93-
// available directions can also be used:
94-
// mode: function({ chart }) {
95-
// return 'xy';
96-
// },
97-
mode: 'xy',
98-
99-
// Which of the enabled zooming directions should only be available
100-
// when the mouse cursor is over one of scale.
101-
overScaleMode: 'xy',
102-
103-
rangeMin: {
104-
// Format of min zoom range depends on scale type
105-
x: null,
106-
y: null
107-
},
108-
rangeMax: {
109-
// Format of max zoom range depends on scale type
110-
x: null,
111-
y: null
112-
},
113-
114-
// Speed of zoom via mouse wheel
115-
// (percentage of zoom on a wheel event)
116-
speed: 0.1,
117-
118-
// Minimal zoom distance required before actually applying zoom
119-
threshold: 2,
120-
121-
// Function called while the user is zooming
122-
onZoom: function({chart}) { console.log(`I'm zooming!!!`); },
123-
// Function called once zooming is completed
124-
onZoomComplete: function({chart}) { console.log(`I was zoomed!!!`); },
125-
// Function called when wheel input occurs without modifier key
126-
onZoomRejected: function({chart, event}) { console.log(`I didn't start zooming!`); }
127-
}
128-
}
129-
}
130-
```
131-
132-
### Animations
133-
134-
The drag-to-zoom animation can be customized by configuring the `zoom` transition in your chart config:
135-
136-
```javascript
137-
{
138-
options: {
139-
transitions: {
140-
zoom: {
141-
animation: {
142-
duration: 1000,
143-
easing: 'easeOutCubic'
144-
}
145-
}
146-
}
147-
}
148-
}
149-
```
150-
151-
If you want to disable zoom animations:
152-
153-
```javascript
154-
{
155-
options: {
156-
transitions: {
157-
zoom: {
158-
animation: {
159-
duration: 0
160-
}
161-
}
162-
}
163-
}
164-
}
165-
```
166-
16718
## API
16819

16920
### chart.resetZoom()
@@ -172,9 +23,7 @@ Programmatically resets the zoom to the default state. See [samples/zoom-time.ht
17223

17324
## Documentation
17425

175-
You can find documentation for Chart.js at [www.chartjs.org/docs](https://www.chartjs.org/docs).
176-
177-
Examples for this plugin are available in the [samples folder](samples).
26+
You can find documentation for chartjs-plugin-zoom at [www.chartjs.org/chartjs-plugin-zoom](https://www.chartjs.org/chartjs-plugin-zoom/).
17827

17928
Prior to v0.4.0, this plugin was known as 'Chart.Zoom.js'. Old versions are still available on npm under that name.
18029

0 commit comments

Comments
 (0)