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

@crisislab/timeline

v0.11.4

Published

Time-series graphing library

Downloads

7

Readme

TimeLine

Live demo | GitHub | NPM | JSR

TimeLine is the dependency-free time-series web realtime graphing library developed using Typescript in-house at CRISiSLab.

We use TimeLine in production here.

However, this library is designed for one use-case: rendering live seismograph data. It might not be ideal for your use-case. You should also check out huww98/TimeChart.

Usage

Installation

npm i @crisislab/timeline
# OR
pnpm add @crisislab/timeline
# OR
deno add @crisislab/timeline
# OR
npx jsr add @crisislab/timeline

Typescript definitions are included in the package.

Important notes!

  • data should be sorted by x-value, with smallest values first. If you always add new data onto the end, this shouldn't be a problem.
  • Call chart.recompute() whenever you've updated the data array. You can use this to batch changes by waiting until you're done modifying data before recomputing.
  • The chart won't draw anything if there are less than two points.

Examples

import {
	TimeLine,
	TimeLineDataPoint,
	timeAxisPlugin,
	axisLabelPlugin,
} from "@crisislab/timeline";

const data: TimeLineDataPoint[] = [];
const timeWindow = 30 * 1000;
const chart = new TimeLine({
	container: document.getElementById("chart-container") as HTMLElement,
	data,
	timeWindow,
	// Note that these aren't used by the chart itself, they're just used by plugins
	timeAxisLabel: "Time",
	valueAxisLabel: "Random numbers",
	plugins: [
		// By default, the chart doesn't draw an x or y axis.
		// You can use these built-in plugins though.
		timeAxisPlugin((x) => new Date(x).toLocaleTimeString()),
		axisLabelPlugin(),
	],
});

let prev = 0;
setInterval(() => {
	const y =
		prev + Math.floor(Math.random() * 10) * (Math.random() > 0.5 ? -1 : 1);
	prev = y;
	data.push({
		time: Date.now(),
		value: y,
	});

	// Call chart.recompute() when you're done updating `data`
	chart.recompute();
}, 50);

More examples in the examples folder.

Plugins

There are several plugins included:

  • timeAxisPlugin: Adds an x-axis (but not an axis label)
  • valueAxisPlugin: Adds an y-axis (but not an axis label)
  • axisLabelPlugin: Adds axis labels for the X and Y axis
  • pointerCrosshairPlugin: Adds a crosshair that follows the mouse
  • highlightNearestPointPlugin: Draws a marker on the nearest point to the mouse
  • doubleClickCopyPlugin: Makes double clicking on the canvas copy the values of the nearest point in tsv (csv) format to the clipboard

Credit

This project was inspired by TimeChart by huww98. We were originally using huww98's library, but found that webGL was excessive for our needs, and created too many problems to justify continuing to use it. Our library's API design is inspired by huww98's library, and the visuals are similar, but under the hood it's completly different. Our library uses the Canvas API instead of WebGL for rendering, so it won't be as performant for huge amounts of data.