1 Star 0 Fork 0

gjTool / canvasPlot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

canvasPlot

npm version npm downloads npm downloads MIT GitHub issues GitHub stars GitHub forks

canvasplot.js canvas绘制矩形,拖动缩放,删除。

在线示例

https://www.gjtool.cn/canvasplot/index.html

快速使用(有两种方式)

一、script标签引入方式

<div id="demo" style="width:500px;height:500px;"></div>
  • 3.引入js
<script src="canvasPlot.min.js" type="text/javascript" charset="utf-8"></script>
  • 4.实例化
var canvasPlot = new CanvasPlot({
	parentNode: document.querySelector("#demo"),
	width: 500,
	height: 500,
	imagePath: '3.jpg'
});

二、npm安装方式

  • 1.安装
npm install canvasplot
  • 2.使用
<template>
  <div id="app">
	<div id="demo" style="width:500px;height:500px;"></div>
  </div>
</template>
<script>
import CanvasPlot from "canvasplot";
export default {
    name: 'App',
	data() {
	  return {
	  };
	},
	mounted() {
		var canvasPlot = new CanvasPlot({
			parentNode: document.querySelector("#demo"),
			width: 500,
			height: 500,
			imagePath: '3.jpg'
		});

		canvasPlot.addRect({
			x: 212,
			y: 119,
			w: 50,
			h: 50
		});
		canvasPlot.addRect({
			x: 280,
			y: 126,
			w: 60,
			h: 30
		});
		canvasPlot.drawRectBegin();
		canvasPlot.on("drawFinish",function(){
			//somecode
		})
	}
}
</script>

options配置项参数列表

参数名称 类型 取值 是否必须 作用
parentNode HTMLelement - canvasPlot的父元素
width Number - - canvasPlot的宽,不填默认跟随父元素宽度
height Number - - canvasPlot的高,不填默认跟随父元素高度
imagePath String - canvasPlot的图片路径
showMenu Boolean - - 是否显示右键菜单
rectBgColor String - - rect矩形内部填充颜色,不填默认中间透明
dragMoveButton String rightClick / midddleClick - 右键拖动画布或者中键拖动画布

methods 方法列表

方法名 传参 传参取值 作用
addRect Object {x:10,y:10,w:40,h:40} 手动添加矩形
delPlot Object plot 删除plot,不传参默认删除所有plot
drawRectBegin - - 开始绘制矩形
drawRectFinish - - 结束绘制矩形
setCanvasDragZoom Boolean true/false 设置允许拖动缩放
getPlotCaches - - 获取绘制的plot数据缓存
getSelection - - 获取当前选中的plot
getOffset - - 获取当前canvas偏移值,放大比例{scale:1,x:0,y:0}
setOffset Object {scale:1,x:0,y:0} 设置当前canvas偏移值,放大比例
getData - - 获取canvasPlot的默认绘制plot数据,偏移值和缩放比例。{offset:{scale:1,x:0,y:0},data:[]}
setData Object {offset:{scale:1,x:0,y:0},data:[]} canvasPlot的默认绘制plot数据,偏移值和缩放比例(可以用来回显上次的数据
screenshot String jpg/png等图片格式 当前canvas截图,返回base64
downLoad String jpg/png等图片格式 当前canvas截图,下载下来成为图片文件
on (String, Function, Boolean) String:监听的事件名,Function:监听的事件回调, Boolean: 为true时,不可与同类型的事件共存,当前事件函数会覆盖前面同类型的事件 on方法监听所有事件 ,所有类型事件默认可以同时存在多个,触发事件时会同时执行
off (String, Function) String:要卸载的事件名,Function:要卸载的事件函数 off方卸载on监听的所有事件,第一个参数为true时,卸载所有on监听的事件。第二个参数为空时,卸载第一个参数的同类型的所有事件

on方法监听所有事件-事件名列表

事件名 作用
drawFinish 监听plot绘制完成
dragMoveFinish 监听背景图拖拽完成
dragPlotMove 监听plot拖拽完成
drawing 监听plot绘制中
drawMove 监听plot绘制中(四角边沿拖拽绘制)
select 监听plot选择事件
zoom 监听缩放事件
dblclick 监听plot双击事件
rightClick 监听plot右键事件
removeAll 监听所有plot删除事件
removePlot 监听plot删除事件
MIT License Copyright (c) 2022 gjTool Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个canvas绘制矩形的插件,自由拖动缩放 展开 收起
HTML 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
HTML
1
https://gitee.com/gjTool/canvasPlot.git
git@gitee.com:gjTool/canvasPlot.git
gjTool
canvasPlot
canvasPlot
main

搜索帮助