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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@shauny/chart

v0.1.1

Published

Lightweight TradingView-like chart engine core

Readme

@shauny/chart

A lightweight candlestick chart engine built on Canvas 2D with a composable layer architecture. Supports pan, zoom, crosshair, and real-time updates with zero dependencies. Add custom indicators instantly via addLayer().

React bindings are available separately as @shauny/chart-react. The core works framework-agnostically.

Installation

npm install @shauny/chart

Basic Usage

import { Chart } from '@shauny/chart'
import type { Candle } from '@shauny/chart'

const canvas = document.getElementById('chart') as HTMLCanvasElement

const chart = new Chart(canvas, {
  background: '#131722',
  grid: {
    lineColor: '#1e2530',
    labelColor: '#787b86',
  },
})

const candles: Candle[] = [
  { time: 1700000000000, open: 100, high: 110, low: 95,  close: 105, volume: 1000 },
  { time: 1700086400000, open: 105, high: 115, low: 100, close: 112, volume: 1200 },
  // time is Unix ms, must be sorted in ascending order
]

chart.setData(candles)
chart.start()

// on unmount
chart.destroy()

ChartOptions

interface ChartOptions {
  background?: string   // default: '#000000'
  padding?: { top: number; right: number; bottom: number; left: number }
  minZoom?: number      // minimum zoom scale
  maxZoom?: number      // maximum zoom scale
  grid?: {
    lineColor?: string    // grid line color (default: '#1e2530')
    labelColor?: string   // axis label color (default: '#787b86')
    borderColor?: string  // axis border color (default: '#2a2e39')
  }
}

API

chart.setData(candles, preserveViewport?)  // load data; pass true to keep current zoom/pan
chart.start()                               // start RAF loop
chart.destroy()                             // clean up events, RAF loop, and ResizeObserver
chart.fitToData()                           // reset viewport to show all data
chart.addLayer(layer)                       // add a custom layer on top
chart.removeLayer(layer)                    // remove a layer
chart.visibleRange                          // current visible { xMin, xMax, yMin, yMax }

Real-time Updates

Pass true as the second argument to setData to preserve the current zoom and pan position while replacing data.

function onTick(candles: Candle[]) {
  chart.setData(candles, true)
}

Custom Layers

Implement the Layer interface to render anything on top of the chart. Below is an example that draws a line connecting closing prices.

import type { Layer, ViewportRange, CanvasSize, Candle } from '@shauny/chart'

class ClosePriceLineLayer implements Layer {
  constructor(private candles: Candle[]) {}

  draw(ctx: CanvasRenderingContext2D, viewport: ViewportRange, size: CanvasSize) {
    if (this.candles.length === 0) return

    const chartW = size.width - 60   // subtract 60px for right price axis
    const chartH = size.height - 24  // subtract 24px for bottom time axis
    const xSpan  = viewport.xMax - viewport.xMin
    const ySpan  = viewport.yMax - viewport.yMin

    const toX = (t: number) => ((t - viewport.xMin) / xSpan) * chartW
    const toY = (p: number) => ((viewport.yMax - p) / ySpan) * chartH
    // note: y-axis is inverted — higher prices map to smaller pixel y values

    ctx.beginPath()
    ctx.strokeStyle = '#f0b90b'
    ctx.lineWidth = 1.5

    for (let i = 0; i < this.candles.length; i++) {
      const x = toX(this.candles[i].time)
      const y = toY(this.candles[i].close)
      i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y)
    }

    ctx.stroke()
  }
}

// register
chart.addLayer(new ClosePriceLineLayer(candles))

License

MIT