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

react-path-recognizer

v1.0.2

Published

Path recognizing library

Downloads

2

Readme

react-path-recognizer

Demo

ScreenShot

Installation

yarn install react-path-recognizer --save

Basic usage

Import the PathRecongizer component. PathRecognizer is a container, it requires a child element to capture mouse moves. PathRecognizer do not draws the moves, for a full example with drawing, check the example/ folder of this repo.

import PathRecognizer from 'react-path-recognizer'

export default class App extends Component {
  render(){
    return (
      <div>
        <PathRecognizer>
          <div style={{width:256, height:256, background:'lightgrey'}}/>
        </PathRecognizer>
      </div>
    )
  }
}

Add some path model to the recognizer. Each path is defined by a direction-sequence and an associated data object (AnyObject).

models(){
    return [
      new PathRecognizerModel([7, 1], "A"),
      new PathRecognizerModel([2,6,0,1,2,3,4,0,1,2,3,4], "B"),
      new PathRecognizerModel([4,3,2,1,0], "C"),
      new PathRecognizerModel([2,6,7,0,1,2,3,4], "D"),
      new PathRecognizerModel([4,3,2,1,0,4,3,2,1,0], "E")
    ]
}

For example, here the model for the letter E :

ScreenShot

Set the models and the onGesture prop on the PathRecognizer component :

 <PathRecognizer models={this.models()} onGesture ={(datas)=>{console.log(datas)}}>
    <div style={{width:256, height:256, background:'lightgrey'}}/>
 </PathRecognizer>

Note that onGesture({datas}) is always invoked at the end of the drawing. If no gesture is recognized, this parametter is null.

Custom filter

While adding a model, you can specify a custom filter (third parametter of PathRecognizerModel). The filter callback method, if specified, will let you a last chance to modify / analyze the datas to determine a new score.

For example, the letter D & P have a similar draw-direction-path, however you can discriminate each one by detecting the position of the last point (up -> it's a P, down -> it's a D). The PathInfos struct transmited to the filter function will help you to determine the new score.

 filter(infos, model){
    let lastPoint
    switch (model.datas){
      case "P":
        lastPoint = [...infos.deltaPoints].pop()
        if (lastPoint.y > infos.boundingBox.top + infos.boundingBox.height * 0.6)return Number.POSITIVE_INFINITY
        return infos.cost
      case "D":
        lastPoint = [...infos.deltaPoints].pop()
        if (lastPoint.y < infos.boundingBox.top + infos.boundingBox.height * 0.6)return Number.POSITIVE_INFINITY
        return infos.cost
   }
}

For a full example, please consult the example folder of this repo.

API

PathRecognizer props

Free path

In this sample project I've used the Graffiti alphabet for the didactic aspect. However, reac-path-recognizer is a generic algorithm, you can add any free path to control an interface / game :

ScreenShot

License

MIT © Didier Brun