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

@antv/chart-node-g6

v0.0.4

Published

The Chart Toolkit of G6 Graph Node

Downloads

249

Readme

@antv/chart-node-g6

自定义 G6 图表节点的工具包。

在一些复杂的场景中,需要的节点类型也比较复杂,如在节点中展示某类数据的分布、趋势等,就像下面的节点:

为了方便用户在使用 G6 自定义节点时支持统计图表,我们基于 G2 封装了 @antv/chart-node-g6 工具包,该工具包支持将 G6.registerNode / G6.registerEdge / G6.registerCombo 方法中的第二个参数 group 作为容器。除过不支持交互外,其他使用方式基本和 G2 的用法完全一致。

自定义带有统计图表的节点

定义上面节点的代码如下所示。

import G6 from '@antv/g6'
import Chart from '@antv/chart-node-g6'

G6.registerNode('node-with-interval', {
  draw(cfg, group) {
    const keyShape = group.addShape('rect', {
      attrs: {
        x: 0,
        y: 0,
        width: 400,
        height: 200,
        fill: cfg.style.fill
      }
    })

    group.addShape('rect', {
      attrs: {
        x: 0,
        y: 0,
        width: 400,
        height: 40,
        fill: '#69c0ff'
      }
    })

    group.addShape('text', {
      attrs: {
        text: '浏览申请完成率',
        x: 10, 
        y:25,
        fontSize: 14,
        fill: '#fff' 
      }
    })

    group.addShape('text', {
      attrs: {
        text: '2020-06-07 ~ 2020-06-14 | 均值',
        x: 20,
        y: 70,
        fontSize: 13,
        fill: '#8c8c8c'
      }
    })

    group.addShape('text', {
      attrs: {
        text: '8.8%',
        x: 20,
        y: 110,
        fontSize: 30,
        fill: '#000'
      }
    })

    // 统计图表部分
    const view = new Chart({
      group,
      region: {
        start: {
          x: 0.01,
          y: 0.2
        },
        end: {
          x: 0.8,
          y: 0.35
        }
      },
    })
    
    
    view.data(cfg.trendData);
    
    view
      .interval()
      .position("genre*sold")
      .color("genre");
    
    view.legend("genre", false);
    
    view.scale({
      genre: {
        alias: "游戏种类" // 列定义,定义该属性显示的别名
      },
      sold: {
        alias: "销售量"
      }
    });

    view.axis('sold', false)
    
    view.render();

    keyShape.set('intervalView', view)

    return keyShape
  },
  update(cfg, item) {
    const keyShape = item.getKeyShape()
    const view = keyShape.get('intervalView')
    view.changeData(cfg.trendData)
  }
}, 'single-node')