npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

portraycanvas

v1.1.1

Published

Parameterizable canvas library that allows you to draw on it, and get the drawn points.

Downloads

14

Readme

PortrayCanvas

A library that allows the user to draw on a canvas, and extract the drawn points. Useful for getting handwritten user input.

Live demo

Download

npm install portraycanvas --save

or

yarn add portraycanvas

Usage

Your html:

<canvas id="canvas-main" style="width: 100%; border: 1px solid black;" height="200"></canvas>

Your Javascript:


import PortrayCanvas from 'portraycanvas';

var canvas = new PortrayCanvas(document.getElementById("canvas-main"), {

  // All these attributes are optional.

  // Stroke size
  lineWidth: 2,

  // Set the color
  color: '#00ff00',

  // Period in which it collects points. The lower, the more points it collects.
  // If it's too high, you might not get curved lines accurately.
  period: 5,

  // Some events...

  onLineFinish: function(c){
    console.log("A line was finished, here are all the lines:");
    console.log(c.getLines());
  },

  onClear: function(){
    console.log("The canvas was cleared");
  },

  onUndo: function(line){
    console.log("This line was deleted:");
    console.log(line);
  }
});

You can programmatically call these methods:


canvas.getLines(); // Get all lines

canvas.clear(); // Clear the canvas

canvas.undo(); // Remove last line you drew

canvas.setColor('#ff0000'); // Change the stroke color

canvas.revertDefaultColor(); // If you had changed the color, go back to the default one.

Issues

It seems it's necessary that the canvas element defines width and height.

<canvas id="main-canvas" width="500" height="700">

This issue is being investigated. It might still work without them in some situations, but make sure the canvas works correctly even after resizing the window.

Styling

You can initialize the canvas using the color option (as explained above), but you can use a css class in order to keep it consistent with the rest of your application:

.green-canvas {
  /* If you include the 'color' property, it'll be
  used as the stroke color */
  color: #006600;
  background-color: #fafafa;
  border: 3px solid black;
  cursor: crosshair;
}

And then in your HTML:

<canvas id="canvas-main" class="green-canvas" width="800" height="500"></canvas>

Recommended CSS

You can make the canvas unselectable by applying the following CSS:

.my-canvas{
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */
  user-select: none;          /* Likely future */      
}

You can make the canvas unscrollable, which is useful for mobile pages, so that it doesn't unintentionally scroll while touching it, by applying the following CSS to your canvas.

.my-canvas{
  touch-action: none;
}

In future versions, these CSS rules will be applied automatically by the library.