MIT License

项目介绍

embiem/react-canvas-draw 是一个托管在 GitHub 上的开源项目,主要使用 JavaScript 编写,采用 MIT License 许可证,目前获得 930 个 Star、306 次 Fork。

仓库全名
embiem/react-canvas-draw
开源许可证
MIT License
Star 数
930
Fork 数
306
未关闭 Issue
37

README 摘要

React Canvas Draw A simple yet powerful canvas-drawing component for React (Demo) Installation Install via NPM: or YARN: Usage For more examples, like saving and loading a drawing ==> look into the /demo/src folder. Props These are the defaultProps of CanvasDraw. You can pass along any of these props to customize the CanvasDraw component. Examples of how to use the props are also shown in the /demo/src folder…

完整内容见 GitHub 原始 README 或本页 。

常见问题

react-canvas-draw 用什么语言开发?

主要使用 JavaScript 编写,采用 MIT License 许可证,目前有 930 个 Star。

react-canvas-draw 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 react-canvas-draw 的源码?

可以直接克隆仓库:git clone https://github.com/embiem/react-canvas-draw.git,默认分支为 develop;安装与运行步骤见仓库 README。

react-canvas-draw 最近还在维护吗?

仓库最近一次更新为 2022年7月22日,当前有 37 个未关闭 Issue;Star 数为 930,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

React Component for drawing in canvas

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
1544
价值分
648
活跃状态
归档

语言占比

JavaScript

Release

README

React Canvas Draw

A simple yet powerful canvas-drawing component for React (Demo)

Travis Coveralls npm package downloads MIT License

All Contributors PRs Welcome

Watch on GitHub Star on GitHub Tweet

Edit 6lv410914w

Installation

Install via NPM:

npm install react-canvas-draw --save

or YARN:

yarn add react-canvas-draw

Usage

import React from "react";
import ReactDOM from "react-dom";
import CanvasDraw from "react-canvas-draw";

ReactDOM.render(<CanvasDraw />, document.getElementById("root"));

For more examples, like saving and loading a drawing ==> look into the /demo/src folder.

Props

These are the defaultProps of CanvasDraw. You can pass along any of these props to customize the CanvasDraw component. Examples of how to use the props are also shown in the /demo/src folder.

  static defaultProps = {
    onChange: null
    loadTimeOffset: 5,
    lazyRadius: 30,
    brushRadius: 12,
    brushColor: "#444",
    catenaryColor: "#0a0302",
    gridColor: "rgba(150,150,150,0.17)",
    hideGrid: false,
    canvasWidth: 400,
    canvasHeight: 400,
    disabled: false,
    imgSrc: "",
    saveData: null,
    immediateLoading: false,
    hideInterface: false,
    gridSizeX: 25,
    gridSizeY: 25,
    gridLineWidth: 0.5,
    hideGridX: false,
    hideGridY: false
    enablePanAndZoom: false,
    mouseZoomFactor: 0.01,
    zoomExtents: { min: 0.33, max: 3 },
  };

Functions

Useful functions that you can call, e.g. when having a reference to this component:

  • getSaveData() returns the drawing’s save-data as a stringified object
  • loadSaveData(saveData: String, immediate: Boolean) loads a previously saved drawing using the saveData string, as well as an optional boolean flag to load it immediately, instead of live-drawing it.
  • getDataURL(fileType, useBgImage, backgroundColour) will export the canvas to a data URL, which can subsequently be used to share or manipulate the image file.
  • clear() clears the canvas completely, including previously erased lines, and resets the view. After a clear, undo() will have no effect.
  • eraseAll() clears the drawn lines but retains their data; calling undo() can restore the erased lines. Note: erased lines are not included in the save data.
  • resetView() resets the canvas’ view to defaults. Has no effect if the enablePanAndZoom property is false.
  • undo() removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.

Local Development

This repo was kickstarted by nwb’s awesome react-component starter.

You just need to clone it, yarn it & start it!

Tips

If you want to save large strings, like the stringified JSON of a drawing, I recommend you use pieroxy/lz-string for compression. It’s LZ compression will bring down your long strings to only ~10% of its original size.

Acknowledgement

The lazy-brush project as well as its demo app by dulnan have been a heavy influence.

I borrowed a lot of the logic and actually used lazy-brush during the push to v1 of react-canvas-draw. Without it, react-canvas-draw would most likely still be pre v1 and wouldn’t feel as good.

Contributors

Thanks goes to these wonderful people (emoji key):


Martin Beierling-Mutz

💻 📖 💡 🤔

Jan Hug

🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT, see LICENSE for details.

评论

暂无评论