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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vislite/canvas

v1.1.0

Published

一个更灵活好用的数据驱动的画布

Readme

@vislite/canvas

一个更灵活好用的数据驱动的画布

如何使用?

npm install --save @vislite/canvas

安装后,准备好渲染位置

<div id="root" style="width:400px;height:400px"></div>

然后直接使用:

import Canvas from "@vislite/canvas"

let canvas = new Canvas({
    el: document.getElementById("root"),
    data: {
        radius: 100
    },
    time: 200, // 动画时长,可选(v1.1.0 新增)
    lifecycle: { // 生命周期,可选(v1.1.0 新增)
        resized(){} // 画布大小改变后
    },
    template: [{
        name: "circle",
        attr: {
            type: "fill",
            cx: 200,
            cy: 200,
            radius: _this => _this.data.radius
        },
        config: {
            fillStyle: "red"
        },
        event: {
            click(event) {
                console.log("你点击了我")
            }
        },
        children: []
    }]
})

这样,一个红色的球就绘制出来了。

如果希望改变球的大小,可以直接:

canvas.setData({
    radius : 200
})

还可以看出来,点击球的时候会触发点击事件,如果想在点击的时候修改球大小,就可以:

......
event: {
    click(event) {
        // console.log("你点击了我")
        this.setData({
            radius : 200
        })
    }
},
......

此外,其中config属性和vislite的canvas画笔配置一致。

下面是更多功能明细:

此外,获取的canvas对象还有如下方法或属性:

painter

画笔,和vislite的canvas画笔API一致,只读。

width

画布宽,只读。

height

画布高,只读。

sized

v1.1.0 新增

是否完成画布初始化,只读。

time

v1.1.0 新增

当前动画时长,可以修改此值以控制下次动画时长:

canvas.time = "一个新值"

data

数据,只读。

setData

设置数据,会触发新的绘制:

canvas.setData({
    // ...
})

startDida

v1.1.0 新增

开启滴答轮询动画:

canvas.startDida(time=500)

stopDida

v1.1.0 新增

停止滴答轮询动画:

canvas.stopDida()

版权

MIT License

Copyright (c) zxl20070701 走一步,再走一步