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

@opendata-ai/openchart-core

v2.8.0

Published

Types, theme, colors, accessibility, and utilities for openchart

Readme

@opendata-ai/openchart-core

Types, spec builders, formatters, and palettes for the OpenChart visualization library.

This is the foundation package. It has no DOM dependencies and runs in any JavaScript environment. The framework packages (openchart-react, openchart-vue, openchart-svelte) all depend on it.

Install

npm install @opendata-ai/openchart-core

Spec builders

Convenience functions that create chart and table specs from data. They infer field types automatically (quantitative, temporal, nominal) by sampling your data, so you don't have to specify types manually.

import { lineChart, columnChart, barChart } from '@opendata-ai/openchart-core';

const line = lineChart(data, 'date', 'value');
const columns = columnChart(data, 'month', 'revenue');
const bars = barChart(data, 'category', 'count');

All chart builders accept an optional options argument for color encoding, annotations, chrome (title/subtitle/source), theme overrides, and dark mode.

const spec = lineChart(data, 'date', 'value', {
  color: 'region',
  chrome: { title: 'Sales by Region', subtitle: 'Q1 2025' },
});

Available builders

| Function | Chart type | Params | |----------|-----------|--------| | lineChart(data, x, y, options?) | Line | x/y position fields | | barChart(data, category, value, options?) | Horizontal bar | category on y-axis, value on x-axis | | columnChart(data, x, y, options?) | Vertical column | x/y position fields | | pieChart(data, category, value, options?) | Pie | category for color, value for size | | donutChart(data, category, value, options?) | Donut | category for color, value for size | | areaChart(data, x, y, options?) | Area | x/y position fields | | dotChart(data, x, y, options?) | Dot/strip | x/y position fields | | scatterChart(data, x, y, options?) | Scatter | x/y position fields | | dataTable(data, options?) | Data table | columns auto-generated if omitted |

Field refs can be a plain string (field name) or a full EncodingChannel object when you need control over type, axis, scale, or aggregation.

dataTable()

The table builder is worth calling out specifically. If you pass data without a columns config, it auto-generates column definitions from your data keys. It infers types from the values: numbers get right-aligned, text gets left-aligned.

import { dataTable } from '@opendata-ai/openchart-core';

// Columns auto-generated from data keys
const spec = dataTable([
  { name: 'Alice', age: 30, city: 'Portland' },
  { name: 'Bob', age: 25, city: 'Seattle' },
]);
// age column auto-detected as quantitative, right-aligned
// name and city columns detected as nominal, left-aligned

For more control, pass explicit column configs:

const spec = dataTable(data, {
  columns: [
    { key: 'name', label: 'Name' },
    { key: 'age', label: 'Age', align: 'right' },
  ],
  search: true,
  pagination: { pageSize: 20 },
});

StoredVizSpec types

When you need to persist specs without bulky data arrays (for storage, serialization, or database records), use the data-stripped type variants:

import type {
  StoredVizSpec,
  ChartSpecWithoutData,
  TableSpecWithoutData,
  GraphSpecWithoutData,
} from '@opendata-ai/openchart-core';

// Store the spec shape without data
const stored: ChartSpecWithoutData = {
  type: 'line',
  encoding: {
    x: { field: 'date', type: 'temporal' },
    y: { field: 'value', type: 'quantitative' },
  },
};

// StoredVizSpec is the union of all three
function saveSpec(spec: StoredVizSpec) {
  localStorage.setItem('viz', JSON.stringify(spec));
}

Type guards

Runtime narrowing for VizSpec values. Useful when you have a generic spec and need to branch on its type:

import { isChartSpec, isTableSpec, isGraphSpec } from '@opendata-ai/openchart-core';
import type { VizSpec } from '@opendata-ai/openchart-core';

function describe(spec: VizSpec): string {
  if (isChartSpec(spec)) return `Chart: ${spec.type}`;
  if (isTableSpec(spec)) return 'Data table';
  if (isGraphSpec(spec)) return 'Network graph';
}

Other exports

Beyond spec builders, this package provides:

  • Theme system - DEFAULT_THEME, resolveTheme(), adaptTheme() for dark mode adaptation
  • Color palettes - CATEGORICAL_PALETTE, SEQUENTIAL_PALETTES, DIVERGING_PALETTES
  • Accessibility - generateAltText(), generateAriaLabels(), contrast ratio utilities
  • Formatting - formatNumber(), formatDate(), abbreviateNumber()
  • Layout - computeChrome(), estimateTextWidth(), responsive breakpoints
  • Label collision - resolveCollisions() for automatic label placement