Giter VIP home page Giter VIP logo

lucas-silbernagel-react-canvas-draw's Introduction

React Canvas Draw

Forked from https://github.com/embiem/react-canvas-draw

Installation

Install via NPM:

npm install lucas-silbernagel-react-canvas-draw

or YARN:

yarn add lucas-silbernagel-react-canvas-draw

Usage

import React from "react";
import ReactDOM from "react-dom";
import CanvasDraw from "lucas-silbernagel-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.

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.

lucas-silbernagel-react-canvas-draw's People

Contributors

embiem avatar lucassilbernagel avatar dependabot[bot] avatar ern-arrowsmith avatar markbiddlecom avatar code-crash avatar dyarfaradj avatar erikgaas avatar guillaumeamat avatar joel-gfdez avatar laeckerv avatar tooolbox avatar mttcnnff avatar tamerin-tech avatar sbeltran10 avatar tnordberg avatar daiyi avatar henrych4 avatar vaneavasco 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.