Code Monkey home page Code Monkey logo

literallycanvas-demos's Introduction

Literally Canvas Demos

This repository contains demonstrations of how to set up and use Literally Canvas.

classic_with_gui/: Plain JS files. No require() usage.

classic_without_gui/: Same as classic_with_gui, but this demo uses the "core build" that doesn't include any UI. Instead, there is custom JavaScript that controls the active tool, colors, etc.

npm_webpack: A modern setup that installs Literally Canvas from NPM, requires it and React with CommonJS, and produces a single JavaScript file. This is likely the best way to start if you're beginning a new project and not using React.

npm_webpack_react: Same as npm_webpack, but renders Literally Canvas as a React component. This is the best way to start if you're using React in your project outside of Literally Canvas.

literallycanvas-demos's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

literallycanvas-demos's Issues

How to save the data in loacalstorage in react example?

I'm using literallycanvas to build a whiteboard component for a small project. I went through the literallycanvas-demos repo and tried to integrate it in my react app. It renders the component without errors. But i need to use the events to save the data. in the example given in literallycanvas-demos repo the SVG data is not saved in localstorage. how can i save it in localstorage?. the demo in the official repo has this functionality but when i tried to implement the same functionality on the the example (npm_webpack_react) it gives an error as Uncaught TypeError: Cannot add property lc, object is not extensible.

this is my code

const React = require('react');
const ReactDOM = require('react-dom');
const LC = require('literallycanvas');


class MyApp extends React.Component{

  constructor(){
    super();
    this.state={
            isSetUp: true,
            svgText: "",
            lcOptions: {
                backgroundImage: null,
                toolbarPosition: 'bottom',
                snapshot: JSON.parse(localStorage.getItem('drawing')),
                onInit: this.onInit,
                imageURLPrefix:"/build/lc-assets/img"
    }
  }
}
 onInit(lc) {
      this.lc = lc;
      lc.on('drawingChange', this.save);
      lc.on('pan', this.save);
      lc.on('zoom', this.save);
      this.save();
  }

  save() {
    console.log('bum bum');
      localStorage.setItem('drawing', JSON.stringify(this.lc.getSnapshot()));
      this.setState({svgText: this.lc.getSVGString()});
  }

  actionOpenImage() {
    window.open(this.lc.getImage({
      // rect: {x: 0, y: 0, width: 100, height: 100}
      scale: 1, margin: {top: 10, right: 10, bottom: 10, left: 10}
    }).toDataURL());
  }

  actionChangeSize() {
      this.lc.setImageSize(null, 200)
  }

  actionSetUp() {
      this.setState({isSetUp: true});
  }

  actionTearDown() {
      this.setState({isSetUp: false});
  }

    render() {
        return <LC.LiterallyCanvasReactComponent  {...this.state.lcOptions} />;
    }
};


ReactDOM.render(<MyApp />, document.getElementById('main'));

classic_with_gui css issue

When the browser is set at 90% the tools on the left get jumbled. Recommend setting css to 65px instead of 61px.

image

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.