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 🙏

© 2025 – Pkg Stats / Ryan Hefner

canvas-coords

v0.0.3

Published

Draw canvas coordinates and grid system

Downloads

7

Readme

Canvas Coords

A tiny library for drawing a customizable grid and/or mouse coordinates on an HTML5 Canvas element.

Intended for educational / developer use only, not for production code.

Demo

view the demo here

Code for the demo is inside the demo folder

Install

npm install canvas-coords

Usage

Mouse Arguments

new Mouse(ctx, canvas, color, font, x, y)

ctx // the context to use
canvas // canvas to use
color = 'gray', // set color to any CSS color value
font = '16px Monospace' // set the font
x = 0 // inital X position
y = 0 // initial Y position

Mouse Methods

const mouse = new Mouse(ctx, canvas, color, font, x, y)

// passing true enables tracking mouse x/y
// passing false disables it
// this does not draw the text
mouse.track(enabled?)

// can be used to access mouse X/Y and do custom functionality
mouse.track() // true by default
console.log(mouse.x, mouse.y)

// draws the X/Y position near the cursor
mouse.draw()

Grid Arguments

new Grid(color, lineWidth, step, boldNth, boldColor, boldWidth, font)

color = 'gray' // unbolded line color
lineWidth = 0.3 // normal line width
step = 10 // space between lines
boldNth = 5 // bold every nth line with boldColor
boldColor = 'DarkGray' // bolded line color & text color
boldWidth = 0.5 // bolded line size
font = '16px Monospace' // font for numbers

Grid Methods

const grid = new Grid() // use default values

// draws lines and text
grid.draw(ctx, canvas)

// creates a lines array on self
grid.createLines(canvas)

// can be used to manually draw lines without text
grid.lines.forEach(line => line.draw(ctx))

// draws text at each boldNth line
grid.drawText(ctx, canvas)

Example

import { Grid, Mouse } from 'canvas-coords'

;(function () {
  let ctx, canvas, mouse, grid

  function init () {
    canvas = document.getElementById('canvas')
    ctx = canvas.getContext('2d')
    mouse = new Mouse(ctx, canvas)
    grid = new Grid()

    mouse.track()
    window.requestAnimationFrame(update)
  }

  function update () {
    window.requestAnimationFrame(update)

    ctx.clearRect(0, 0, canvas.width, canvas.height)
    mouse.draw()
    grid.draw(ctx, canvas)
  }

  document.addEventListener('DOMContentLoaded', init)
})()