Coder Social home page Coder Social logo

shipmatserjack / canvas-draw-table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yeshaojun/canvas-draw-table

0.0 0.0 0.0 386 KB

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

JavaScript 84.70% HTML 15.30%

canvas-draw-table's Introduction

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

canvas-draw-table's People

Contributors

yeshaojun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.