Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@antv/chart-node-g6

Package Overview
Dependencies
Maintainers
34
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@antv/chart-node-g6

The Chart Toolkit of G6 Graph Node

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-77.92%
Maintainers
34
Weekly downloads
 
Created
Source

@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')

Keywords

FAQs

Package last updated on 25 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc