npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

g2-for-vue

v0.3.6

Published

G2 Charts for Vue.js

Downloads

7

Readme

G2-for-Vue

G2 Charts for Vue.js.

Built upon G2 v3.2.7+ and depends on Vue.js v2.5.17+.

Install

Manual

download lib/G2VChart.js and include it in your HTML file

<script src="path/to/g2-for-vue/lib/index.js"></script>

The component is exposed as window.G2VChart.

// register component to use
Vue.component('g2-vchart', G2VChart)

Use npm(Recommended)

npm install g2-for-vue

Register Component

import Vue from 'vue'
import G2VChart from 'g2-for-vue/components/G2VChart'

// register component to use
Vue.component('g2-vchart', G2VChart)

Using the Component

<template>
  <div class='bar-chart'>
    <G2VChart
      ref="bar"
      :height="chartHeight"
      :plotCfg="barPlotCfg"
      :chartData="barData"
      :createChart="createBarChart"
      :addGuide="addBarGuide"
    />
    <div class='btn' @click="refresh">refresh</div>
  </div>
</template>
<script>
import G2VChart from 'g2-for-vue'
// or import G2VChart from 'g2-for-vue/components/G2VChart'

export default {
  components: {
    G2VChart
  },
  data () {
    return {
      chartHeight: 220,
      selectedMonth: '9月',
      barData: [
        {month: '4月', value: 10},
        {month: '5月', value: 310},
        {month: '6月', value: 450},
        {month: '7月', value: 60},
        {month: '8月', value: 110},
        {month: '9月', value: 100}
      ],
      barPlotCfg: {},
      typeMap: {
        OUT: '支出',
        IN: '收入'
      }
    }
  },
  methods: {
   createBarChart(chart) {
    const self = this;
    chart.interval().position('month*value').size(20).color('month', month => {
      if (month === self.selectedMonth) {
        return '#108ee9';
      }
      return '#108ee969';
    });
    chart.legend(false);
    chart.tooltip(false);
    return chart;
  },

  addBarGuide(chart, barData) {
    if (!chart || !barData) { return; }
    // 辅助文本
    let diffVal = 0;
    barData.map(item => {
      chart.guide().text({
        position: item,
        content: item.value,
        offsetX: -9,
        offsetY: -8
      });
    });
  },
    refresh () {
      this.barData = [
        {month: '4月', value: Math.floor(Math.random() * 100) + 30},
        {month: '5月', value: Math.floor(Math.random() * 100) + 110},
        {month: '6月', value: Math.floor(Math.random() * 100) + 450},
        {month: '7月', value: Math.floor(Math.random() * 100) + 340},
        {month: '8月', value: Math.floor(Math.random() * 100) + 210},
        {month: '9月', value: Math.floor(Math.random() * 100) + 680}
      ]
    }
  }
}
</script>
<style>
.bar-chart {
  width: 100%;
  height: 100%;
  min-width: 200px;
}
</style>

See more examples here

Props

  • autoResize (default: false)

    This prop indicates G2 Chart instance should be resized automatically whenever its root is resized

  • plotCfg

  • chartData

  • createChart

  • addGuide

Computed

  • width [readonly]

    Used to retrieve the current width of the G2Chart instance.

  • height [readonly]

    Used to retrieve the current height of the G2Chart instance.

Usages
<g2-vchart
  ref="g2-vchart"
  autoResize
  @resize="onResize"
/>
onResize() {
  const g2VChart = this.$refs['g2-vchart'];
  const width = g2VChart.width;
  const height = g2VChart.height;
  console.log('onResize:width:%d, height:%d',  width, height)
}

Methods

  • downloadImage (name: string)

    图表导出功能,通过传入 name 来指定下载图片的文件名。

  • getDataURL

  • changeVisible

  • resize

  • clear

  • repaint

  • destroy

  • dispatchAction (name: string, ...args: any[]) To see more actions support: G2.Chart Methods

    example

    this.vchart.dispatchAction('getXScale')

Events

G2VChart support the following events:

basic canvas events

  • mousedown
  • mousemove
  • mouseleave
  • mouseup
  • click
  • dblclick
  • touchstart
  • touchmove
  • touchend

basic plot events

  • plotenter
  • plotmove
  • plotleave
  • plotclick
  • plotdblclick

resize event

  • resize

tooltip events

  • tooltip:show
  • tooltip:hide
  • tooltip:change

Usages:

<g2-vchart
  ref="g2-vchart"
  @click="onClick"
  @tooltip:change="onTooltipChange"
/>
onTooltipChange(evt) {
  // handle evt
}

For more details, see G2's API - Events

  • [ ] any other events,like shape*basic, components*basic will be added soon~

Local development

npm i
npm run demo

浏览器打开http://localhost:8080/demo.html

Plan

  • [ ] 分包引入G2,目前会将整个G2引入,打包后的common.js大小为1542.79 kb,压缩后的大小为327.42 kb
    • [ ] use G2 as exterval
import G2 from '@antv/g2/src/core.js'

// import G2 modules manually to reduce bundle size,such as Geoms,Facets, Interaction
// geoms
require('./geom/area');
require('./geom/edge');
require('./geom/heatmap');
require('./geom/interval');
require('./geom/line');
require('./geom/path');
require('./geom/point');
require('./geom/polygon');
require('./geom/schema');
require('./geom/venn');

// facets
require('./facet/index');

// interaction
require('./interaction/index');
  • [x] use resize-detector
  • [ ] add more examples
  • [ ] run lint before git push