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

canvas-draw-table

v1.0.9

Published

canvas编辑table插件

Downloads

13

Readme

canvas-draw-table

使用 canvas 实现画表格,以及移动,拖拽,拉伸,删除,回撤等功能

体验地址

也可以在 github 上 clone 代码,直接打开 index.html

项目由来:有个报表识别的项目,识别结果可能不准确,需要在图片上二次编辑。在网上找了一圈,也没找到合适的框架,因此自己封装了一个,使用 canvas 绘制 table,并实现批量移动,拉伸,拖拽,删除,等功能

使用方式

import Draw from 'canvas-draw-table'

const draw = Draw({
    url: '', // 图片url,可不传
    dom: '', // canvas容器id或者dom,
    selectColor: "",
    selectActiveColor: "",
    drawSelectColor: "",
    defaultData: [
        {
            type: "cell",
            location: [
                [114, 100],
                [347, 100],
                [347, 229],
                [114, 229],
            ],
        }
    ]
}, modeChange: fn)

| 参数 | 类型 | 说明 | | ----------------- | ---------- | -------------------- | | url | string | 背景图片地址(可省略) | | dom | string dom | canvas 容器 | | selectColor | string | 线条颜色(可省略) | | selectActiveColor | string | 选中颜色(可省略) | | drawSelectColor | string | 多选框颜色(可省略) | | defaultData | array | 初始数据(可省略) |

(如果传了 url,则 defaultData 数据是相对图片的坐标,否则是相对容器的坐标)

modeChange 模式改变的回调函数,模式一共有【选择,移动,拉伸,绘制】, 默认为选择模式(背景图片不可选中,不可删除)

想要手动改变模式,可以通过

draw.setMode(mode)

使用方式

          draw.setMode("draw", {
            type: "table",
            tr: 3,
            td: 4,
          });

绘制 table 的时候,setMode 需要第二个参数,并传入绘制的行列

删除

if(draw.current || draw.currentArray.length > 0) {
	draw.delete();
}

保存

if(!draw.noUpdate) {
	draw.saveDraw()
}

撤销/反撤销


if(draw.history.length > 0) {
	draw.revoke()
}

if(draw.deleteHistory.length > 0) {
	draw.reRevoke()
}

放大/缩小


draw.zoom('up')

draw.zoom('down')