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

mpredict.js

v1.1.6

Published

A JavaScript library for realtime mouse position prediction

Downloads

3

Readme

MPredict.js

A JavaScript library for realtime mouse position prediction

http://cudbg.github.io/mpredict.js

Download

You can download a copy of MPredict.js from:

1) The github repository: git clone [email protected]:cudbg/mpredict.js.git

2) Using npm npm install mpredict.js --save, notice that you need to create a directory node_modules if you want to download it to your current directory.

Usage

MPredict.js can be added to your web page in the three steps:

1) Include mpredict.js in your page.

2) Put mpredict-templates.json in the same directory as the HTML file that includes 'mpredict.js'

3) Call this JavaScript function:

mPredict.start();

You can pass one object parameter to start function to set the options.

For example mPredict.start({'pathToTemplates': '../data/templates.json', 'targetElement': '#main-container'}) loads the template data from the given path rather than the default path above.

Then MPredict.js will automatically record the current mouse trace and sample it on the target DOM element(the document object by default)

Demo

Click here to see the demo of predicting mouse position. The grey line is the current trace, the orange circles are the predicted positions(20ms to 300ms in future), and the radius of orange circles indicates the standard deviations of predictions by each matched template.

Documentation

###Options:

  • sampleInterval: The time interval(by milliseconds) of sampling the mouse trace; default: 10
  • pauseThreshold: The time threshold of pausing; when the time between two consecutive mouse events is larger than this threshold, the second mouse event will be regarded as the beginning of a new trace; default: 50
  • K: The number of nearest neighbors in the KNN algorithm; default: 5
  • pathToTemplates: The path to the JSON file of templates used for the KNN algorithm; default: '/mpredict-templates.json'
  • targetElement: The selector of target element to record mouse trace from; default: document

API

####mPredict.start(options)

Start the introduction for defined element(s).

Parameters:

  • options : Object(optional) Object that contains option keys with values.

Returns:

  • mPredict object.

Example:

mPredict.start({
    'pathToTemplates': '../data/templates.json',
    'targetElement': '#main-container'
})

####mPredict.getCurrentTrace()

Get the current mouse trace recorded and sampled by MPredict.js on the target DOM element

Parameters:

  • None

Returns:

  • Array: [[x0, y0, t0], ..., [xn, yn, tn]], xi and yi are mouse positions(in pixels), t0 is always 0(ms)

Example:

var curTrace = mPredict.getCurrentTrace()

####mPredict.sampleTrace(trace)

Sample a mouse trace for prediction

Parameters:

  • trace : Array: [[x0, y0, t0], ..., [xn, yn, tn]], xi and yi are mouse positions(in pixels), ti is the timestamp

Returns:

  • Array: [[x0, y0, t0], ..., [xn, yn, tn]], xi and yi are mouse positions(in pixels), t0 is always 0(ms)

Example:

var sampledTrace = mPredict.sampleTrace(unsampledTrace)

####mPredict.predictPosition(trace, deltaTime, option)

Predict the mouse position for the given trace after deltaTime

Parameters:

  • trace : sampled mouse trace
  • deltaTime : integer(in milliseconds), deltaTime <= 0 means predicting the endpoint for the given trace
  • option : Object(optional) Object that contains option keys with values for prediction. - type: prediction type: '1D' or '2D'; default: '2D' - constraint: a vector that indicates the moving direction if prediction type is '1D'

Returns:

  • Array: [x, y, std] (in pixels)

Example:

mPredict.predictPosition(mPredict.getCurrentTrace(), 0)
mPredict.predictPosition(mPredict.getCurrentTrace(), 100, {'type': '1D', 'constraint': [1, 0]});