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-render

v0.0.6

Published

一个基于@antv/g2的chart webComponent组件,可直接用于vue,react,原生js等项目;区别于其他的组件, g2-render使用json配置,有几个好处:1. 你可以拷贝g2的demo立即使用,2.渲染逻辑在父组件控制,当有差别很大的新图表需求时,也不用改动原组件,3.支持json系列化,对于低代码项目友好;

Downloads

9

Readme

介绍

一个基于@antv/g2 的 chart webComponent 组件

g2-render 使用 json 配置,在父组件写渲染逻辑有几个好处:

  1. 直接使用 g2 的链式语法,可以拷贝 g2 的 demo 立即使用,
  2. 渲染逻辑在父组件控制,避免封装通用组件
  3. 支持 json 系列化, 对于低代码项目友好

缺点: 因为 webComponent 隔绝了 dom, 所以需要指定宽高, 元芳有什么好办法吗?

Install

pnpm add g2-render

import '@/assets/g2-render.es'
// or
import { parser } from '@/assets/g2-render.es'

vue

demo: stackblitz

因为 webComponent 隔绝了 dom, 所以需要指定宽高

<template>
  <g2-render
    :json.prop="json"
    :data.prop="data"
    :scope.prop="scope"
    :init-config.prop="{
      height: 300,
      width: 300,
    }"
    debug="true"
  ></g2-render>
</template>

// 记得使用.prop 绑定变量 https://vuejs.org/guide/extras/web-components.html#using-custom-elements-in-vue
<script setup>

const render = ({  chart, x, y, data }) => {

 //...
  chart.data(data).line().position(`${x}*${y}`);
  chart.render()
}
// 注意 stringify 接受一个对象, 具有值为函数的render属性
const json = parser.stringify({
  render
})

const data =[]
const scope = {x='x',y='y'}
</script>


// vite.config.js
defineConfig({
  plugins: [
      vue({
        template: {
          compilerOptions: {
            isCustomElement: (tag) => /^g2-render/.test(tag),
          },
        },
      }),
  ]
})