@antv/g2-brush

0.0.2 • Public • Published

g2-brush

npm package NPM downloads Percentage of issues still open

Install

$ npm install @antv/g2-brush

or use cdn:

<script src="https://gw.alipayobjects.com/os/antv/assets/g2-brush/0.0.1/g2-brush.js"></script>

Usage

First of all, the brush instance must be created after the chart be rendered.

import Brush from '@antv/g2-brush';
// ...
chart.render();

new Brush({
  canvas: chart.get('canvas'), // must be set
  chart, // if you want to filter data by default, please set the chart
  type: 'X', // set the brush type, default value is 'XY'
});

Example

online demos: https://antvis.github.io/g2-brush/demos/#

$.getJSON('./data/top2000.json', data => {
  const ds = new DataSet();
  const dv = ds.createView('test')
    .source(data)
    .transform({
      as: [ 'count' ],
      groupBy: [ 'release' ],
      operations: [ 'count' ],
      type: 'aggregate'
    });

  const chart = new G2.Chart({
    container: 'canvas',
    forceFit: true,
    height: window.innerHeight
  });
  chart.source(dv);
  chart.scale({
    count: {
      alias: 'top2000 唱片总量'
    },
    release: {
      tickInterval: 5,
      alias: '唱片发行年份'
    }
  });
  chart.interval()
    .position('release*count')
    .color('#e50000');

  chart.render();

  new Brush({
    canvas: chart.get('canvas'),
    chart,
    type: 'X',
    onBrushstart() {
      chart.hideTooltip();
    },
    onBrushmove() {
      chart.hideTooltip();
    }
  });
  chart.on('plotdblclick', () => {
    chart.get('options').filters = {};
    chart.repaint();
  });
});

API

API DOCS

Development

$ npm install

$ npm run dev

How to Contribute

Please let us know how can we help. Do check out issues for bug reports or suggestions first.

To become a contributor, please follow our contributing guide.

Dependencies (0)

    Dev Dependencies (28)

    Package Sidebar

    Install

    npm i @antv/g2-brush

    Weekly Downloads

    3,995

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • lvisei
    • yisi.wang
    • basketduck
    • biupiubiupiu
    • flash1
    • dreammy23
    • laixingui.lxg
    • zhangjunjie-loki
    • rainy25ghz
    • zeyuwang
    • yanxiong
    • susiwen8
    • freestyle21
    • soundquiet
    • elaine.q.10
    • sturuby
    • sakuya223
    • serializedowen
    • xdzhao
    • yangzhanmei
    • wjgogogo
    • leungwensen
    • dori
    • iaaron
    • yard
    • simaq
    • dxq613
    • intchous
    • susan_ann
    • jinke.li
    • lzxue
    • army8735
    • atool
    • baizn
    • dengfuping
    • neoddish
    • jeffy2012
    • zqlu
    • afc163
    • pomelo-nwu
    • kopiluwaky
    • ccnuzindex
    • panyuqi
    • bubkoo
    • zengyue
    • kasmine
    • boyu.zlj
    • l1ud0ngq1
    • newbyvector
    • winniexing
    • chenluli
    • kn9117
    • xdddst
    • semious2020
    • esora
    • nadia_liu
    • bbsqq
    • mxz96102
    • openwayne
    • pearmini
    • pddpd
    • yiqianyao
    • zhanba
    • cxxxxxn