UNPKG

2.63 kBMarkdownView Raw
1# g2-brush
2
3![](https://img.shields.io/badge/language-javascript-red.svg)
4![](https://img.shields.io/badge/license-MIT-000000.svg)
5
6[![npm package](https://img.shields.io/npm/v/@antv/g2-brush.svg)](https://www.npmjs.com/package/@antv/g2-brush)
7[![NPM downloads](http://img.shields.io/npm/dm/@antv/g2-brush.svg)](https://npmjs.org/package/@antv/g2-brush)
8[![Percentage of issues still open](http://isitmaintained.com/badge/open/antvis/g2-brush.svg)](http://isitmaintained.com/project/antvis/g2-brush "Percentage of issues still open")
9
10
11## Install
12
13```bash
14$ npm install @antv/g2-brush
15```
16
17or use cdn:
18
19```html
20<script src="https://gw.alipayobjects.com/os/antv/assets/g2-brush/0.0.1/g2-brush.js"></script>
21```
22
23## Usage
24
25First of all, the brush instance must be created after the chart be rendered.
26
27```js
28import Brush from '@antv/g2-brush';
29// ...
30chart.render();
31
32new Brush({
33 canvas: chart.get('canvas'), // must be set
34 chart, // if you want to filter data by default, please set the chart
35 type: 'X', // set the brush type, default value is 'XY'
36});
37```
38
39### Example
40
41online demos: [https://antvis.github.io/g2-brush/demos/#](https://antvis.github.io/g2-brush/demos/#)
42
43![](https://gw.alipayobjects.com/zos/rmsportal/HRkzmAbHDcJYweUxDAlC.gif)
44
45```js
46$.getJSON('./data/top2000.json', data => {
47 const ds = new DataSet();
48 const dv = ds.createView('test')
49 .source(data)
50 .transform({
51 as: [ 'count' ],
52 groupBy: [ 'release' ],
53 operations: [ 'count' ],
54 type: 'aggregate'
55 });
56
57 const chart = new G2.Chart({
58 container: 'canvas',
59 forceFit: true,
60 height: window.innerHeight
61 });
62 chart.source(dv);
63 chart.scale({
64 count: {
65 alias: 'top2000 唱片总量'
66 },
67 release: {
68 tickInterval: 5,
69 alias: '唱片发行年份'
70 }
71 });
72 chart.interval()
73 .position('release*count')
74 .color('#e50000');
75
76 chart.render();
77
78 new Brush({
79 canvas: chart.get('canvas'),
80 chart,
81 type: 'X',
82 onBrushstart() {
83 chart.hideTooltip();
84 },
85 onBrushmove() {
86 chart.hideTooltip();
87 }
88 });
89 chart.on('plotdblclick', () => {
90 chart.get('options').filters = {};
91 chart.repaint();
92 });
93});
94```
95
96## API
97
98[API DOCS](https://github.com/antvis/g2-brush/blob/master/docs/brush.md)
99
100## Development
101
102```bash
103$ npm install
104
105$ npm run dev
106```
107
108## How to Contribute
109
110Please let us know how can we help. Do check out [issues](https://github.com/antvis/g2-brush/issues) for bug reports or suggestions first.
111
112To become a contributor, please follow our [contributing guide](https://github.com/antvis/g2-brush/blob/master/CONTRIBUTING.md).