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

@pvotly/charts

v0.1.1

Published

Chart-ready data normalization + a pluggable rendering adapter API for pvotly. Ships a zero-dependency built-in SVG adapter and bring-your-own adapters (Chart.js, ECharts, D3, …).

Readme

@pvotly/charts

Turn a pvotly pivot grid into a chart — with your charting library.

@pvotly/charts does two things and nothing else:

  1. Normalizes a computed pivot grid into a stable, library-agnostic ChartData shape (categories × series + axis metadata).
  2. Hands that data to a pluggable ChartAdapter that renders it.

It ships a zero-dependency built-in SVG adapter as the default, so it works out of the box. To use Chart.js, ECharts, Highcharts, D3, Recharts, or anything else, you write (or import) a small adapter. pvotly never talks to your chart library directly.

pnpm add @pvotly/charts @pvotly/core

Required runtime dependencies: none (besides @pvotly/core, the engine). The built-in SVG adapter needs nothing else.

Quick start (built-in SVG, zero deps)

import { PivotEngine } from '@pvotly/core';
import { PivotChart } from '@pvotly/charts';

const engine = new PivotEngine({
  dataSource: { data },
  slice: {
    rows: [{ uniqueName: 'Country' }],
    columns: [{ uniqueName: 'Category' }],
    measures: [{ uniqueName: 'Sales', aggregation: 'sum' }],
  },
});

const chart = new PivotChart(document.getElementById('chart')!, engine, undefined, {
  type: 'bar', // 'bar' | 'line' | 'area' | 'pie'
});

// The chart auto-updates whenever the engine's report changes.
chart.setType('line');
chart.destroy();

Just want the data? Skip the controller:

import { gridToChartData } from '@pvotly/charts';
const data = gridToChartData(engine.getGrid(), { type: 'line' });

ChartData

The stable contract every adapter receives:

type ChartType = 'bar' | 'line' | 'area' | 'pie' | 'scatter';

interface ChartSeries {
  name: string;                  // column-leaf caption and/or measure caption
  values: Array<number | null>;  // aligned 1:1 with categories; null = gap
  measure?: string;              // source measure uniqueName
}

interface ChartData {
  type: ChartType;               // requested kind (a hint)
  categories: string[];          // x labels (one per row leaf)
  series: ChartSeries[];         // (column leaf × measure)
  axes: {
    category: { title?: string; min: number; max: number };
    value: { title?: string; min: number; max: number };
  };
  title?: string;
}

ChartAdapter

The single plug-in point — three lifecycle methods over an opaque instance:

interface ChartRenderOptions {
  type?: ChartType;
  width?: number;
  height?: number;
  title?: string;
  palette?: string[];
  [key: string]: unknown;        // adapter-specific escape hatch
}

interface ChartAdapter<TInstance = unknown> {
  name?: string;
  render(container: HTMLElement, data: ChartData, options: ChartRenderOptions): TInstance;
  update(instance: TInstance, data: ChartData, options: ChartRenderOptions): TInstance | void;
  destroy(instance: TInstance): void;
}

Bring your own library

Chart.js (reference adapter, optional peer)

Chart.js is an optional peer dependency@pvotly/charts never imports it. You pass the Chart class in, so you stay in control of tree-shaking and which controllers/scales are registered:

import Chart from 'chart.js/auto';
import { PivotChart, createChartJsAdapter } from '@pvotly/charts';

const adapter = createChartJsAdapter(Chart);
const chart = new PivotChart(el, engine, adapter, { type: 'line' });

Write a custom adapter (e.g. ECharts)

Implement the interface and hand pvotly's normalized ChartData to your lib:

import * as echarts from 'echarts';
import type { ChartAdapter } from '@pvotly/charts';

const echartsAdapter: ChartAdapter<echarts.ECharts> = {
  name: 'echarts',
  render(container, data, options) {
    const instance = echarts.init(container, undefined, {
      width: options.width,
      height: options.height,
    });
    instance.setOption(toEChartsOption(data, options));
    return instance;
  },
  update(instance, data, options) {
    instance.setOption(toEChartsOption(data, options));
  },
  destroy(instance) {
    instance.dispose();
  },
};

function toEChartsOption(data, options) {
  return {
    title: { text: options.title ?? data.title },
    xAxis: { type: 'category', data: data.categories },
    yAxis: { type: 'value' },
    series: data.series.map((s) => ({
      name: s.name,
      type: options.type ?? data.type,
      data: s.values,
    })),
  };
}

// Use it:
const chart = new PivotChart(el, engine, echartsAdapter);

You can also register adapters by name and reference them as strings:

import { registerAdapter, PivotChart } from '@pvotly/charts';

registerAdapter('echarts', echartsAdapter);
new PivotChart(el, engine, 'echarts'); // 'svg' is always registered too

API

| Export | Description | | ------ | ----------- | | gridToChartData(grid, opts?) | Normalize a PivotGridChartData. | | engineToChartData(engine, opts?) | Normalize the engine's current grid. | | PivotChart | Controller: normalize → render → auto-update → destroy. | | builtinSvgAdapter | Default zero-dependency SVG adapter. | | createChartJsAdapter(Chart) | Reference Chart.js adapter factory. | | registerAdapter / getAdapter / listAdapters | Optional name registry. | | ChartAdapter, ChartData, ChartType, ChartRenderOptions, NormalizeOptions, … | Types for TS consumers. |

License

MIT