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

infinite-canvas

v1.0.0

Published

an infinite html5 canvas

Downloads

27

Readme

infinite-canvas

an infinite html5 canvas

Build Status npm version

Description

Provides an interface to pan an html5 canvas vertically and horizontally infinitely. This works by creating a infinitely growing buffer canvas that adjusts it's size and position when moving the origin relatively with .move([x, y]) or absolutely with .setOrigin([x, y]). Essentially, the wrapped canvas becomes a window that you move around the buffer canvas. When moved beyond the dimensions of the buffer canvas, the buffer is resized and the image data is repositioned to compensate.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install infinite-canvas --save

Usage

// require module
import InfiniteCanvas from 'infinite-canvas'

let canvas = document.querySelector('#canvas')
let infiniteCanvas = new InfiniteCanvas(canvas) // make instance
let ctx = canvas.getContext('2d') // get canvas context
ctx = infiniteCanvas.canvasContext // or pull it from the instance
infiniteCanvas.setOrigin([-20, 40]) // move down 20 and right 40

// draw a circle on canvas
ctx.beginPath()
ctx.arc(100, 100, 50, 0, 2 * Math.PI)
ctx.stroke()
infiniteCanvas.commitToBuffer() // and commit it to buffer

// or draw directly to the buffer
let bufferCtx = infiniteCanvas.buffer.getContext('2d') // get buffer context
bufferCtx = infiniteCanvas.bufferContext // or pull it from the instance

// draw a circle on the buffer
bufferCtx.beginPath()
bufferCtx.arc(100, 100, 50, 0, 2 * Math.PI)
bufferCtx.stroke()
infiniteCanvas.refresh() // and update the canvas

infiniteCanvas.move([10, 20]) // move up 10 and right 20
infiniteCanvas.getOrigin() // [-10, 60] // check updated origin

API

Make an instance

new InfiniteCanvas(canvas:canvas):instance provided a canvas, returns a new InfiniteCanvas object

Methods

.setOrigin(pos:array):undefined provide an array with the absolute [x, y] position for the origin of the wrapped canvas on the buffer canvas

.move(posDiff:array):undefined provide an array with the relative [x, y] position for the origin of the wrapped canvas on the buffer canvas

.commitToBuffer():undefined draw new image data from the wrapped canvas to the buffer canvas. This is essentially saving it. Otherwise, it'll be lost when panning. Use when drawing to the wrapped canvas.

.refresh():undefined draws image data from the buffer canvas to the wrapped canvas. Use when drawing directly to the buffer canvas.

.getOrigin():array returns the current absolute origin [x, y] of the wrapped canvas on the buffer canvas

Properties

.canvas:canvas access to the wrapped canvas

.canvasContext:canvas access to the wrapped canvas's 2d context

.buffer:canvas access to the buffer canvas

.bufferContext:canvas access to the buffer canvas's 2d context

Notes

I can see it being useful to draw beyond the borders of the canvas or buffer canvas (draw off screen). So, I'm currently considering adding a padding option for the buffer canvas or providing a draw method that will update the buffer accordingly. Also, zooming ability would be nice as well.

License

ISC