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

@moxa/chart

v1.2.0

Published

This document provides development guidelines for the Chart Library based on [ECharts](https://echarts.apache.org/).

Readme

Moxa Chart - Developer Guide

This document provides development guidelines for the Chart Library based on ECharts.

Architecture Overview

The Chart Library is designed with a modular architecture that follows these key principles:

  • Core Base Class: All chart types extend from a shared CoreChart class
  • Type Safety: Comprehensive TypeScript interfaces for all configuration options
  • Component Reusability: Shared components and utilities across chart types
  • Adaptable Data Layer: Flexible data adapters for various input formats

Project Structure

libs/chart/
├── .storybook/               # Storybook configuration
├── src/
│   ├── lib/
│   │   ├── adapters/         # Data adapters for different formats
│   │   ├── charts/           # Chart implementations
│   │   │   ├── bar-chart/    # Bar chart implementation
│   │   │   └── line-chart/   # Line chart implementation
│   │   ├── components/       # Reusable UI components
│   │   │   └── tooltip/      # Tooltip component
│   │   ├── core/             # Core chart functionality
│   │   │   └── core-chart.ts # Base chart class
│   │   ├── types/            # TypeScript type definitions
│   │   │   ├── animation.type.ts
│   │   │   ├── axis.type.ts
│   │   │   ├── chart.type.ts
│   │   │   ├── data.type.ts
│   │   │   ├── grid.type.ts
│   │   │   ├── legend.type.ts
│   │   │   └── tooltip.type.ts
│   │   └── utils/            # Utility functions
│   └── stories/              # Storybook stories
├── package.json              # Package configuration
├── project.json              # Nx project configuration
├── tsconfig.json             # TypeScript configuration
└── vite.config.ts            # Vite configuration

Development Workflow

Setting Up the Development Environment

  1. Install dependencies:

    npm install
  2. Build the library:

    nx build chart
  3. Start Storybook for development:

    nx storybook chart

Creating a New Chart Type

To add a new chart type, follow these steps:

  1. Create a new directory under src/lib/charts/ for your chart type (e.g., pie-chart/)
  2. Create the following files:
    • [chart-name].type.ts - Type definitions specific to this chart
    • [chart-name].ts - The chart implementation class
    • index.ts - Export file
    • [chart-name].stories.ts - Storybook examples

Example implementation for a new chart type:

// pie-chart.type.ts
import { ChartData } from '../../types';

export interface PieChartData extends ChartData {
  values: number[];
  labels?: string[];
  radius?: string | number | string[] | number[];
}

// pie-chart.ts
import { EChartsOption } from 'echarts';
import { CoreChart } from '../../core';
import { PieChartData } from './pie-chart.type';

export class PieChart extends CoreChart {
  private data: PieChartData;

  constructor(domElement: HTMLElement, data: PieChartData) {
    super(domElement);
    this.data = data;
  }

  render(): void {
    const option: EChartsOption = {
      title: { text: this.data.title },
      series: [
        {
          type: 'pie',
          radius: this.data.radius || '50%',
          data: this.data.values.map((value, index) => ({
            value,
            name: this.data.labels?.[index] || `Item ${index + 1}`,
          })),
        },
      ],
    };
    this.setOption(option);
  }

  updateData(newData: PieChartData): void {
    this.data = newData;
    this.render();
  }
}

// index.ts
export * from './pie-chart';
export * from './pie-chart.type';
  1. Add your new chart to the main exports in src/lib/charts/index.ts

Extending Existing Components

When modifying existing components:

  1. Maintain backward compatibility
  2. Add new properties to the corresponding type definitions
  3. Update the rendering logic in the chart class
  4. Add Storybook examples for new features

Core Class Architecture

The CoreChart class provides the foundation for all chart types:

// Brief overview of core-chart.ts
export class CoreChart {
  chart: ECharts;

  constructor(domElement: HTMLElement, theme = 'light') {
    this.chart = echarts.init(domElement, theme);
  }

  setOption(option: echarts.EChartsOption): void {
    this.chart.setOption(option);
  }

  resize(): void {
    this.chart.resize();
  }

  dispose(): void {
    this.chart.dispose();
  }
}

When extending this class, always call the parent constructor and implement the render() method.

Type System

The type system is designed to be extensible:

  • ChartData - Base interface for all chart data
  • Specific chart types extend this base interface
  • Helper types for various chart components (axis, legend, etc.)

When adding new properties, add them to the appropriate type definition file.

Testing Guidelines

Create comprehensive tests for all components:

  1. Unit tests for individual functions
  2. Integration tests for chart rendering
  3. Visual regression tests using Storybook

Run tests with:

nx test chart

Build and Release Process

  1. Update version in package.json
  2. Build the library:
    nx build chart
  3. Test the build:
    nx test chart
  4. Create a pull request with your changes
  5. After approval and merge, the CI/CD pipeline will publish the new version

Development Commands

  • nx build chart - Build the library
  • nx test chart - Run unit tests
  • nx storybook chart - Start Storybook for development
  • nx build-storybook chart - Build Storybook to dist/storybook/chart
  • nx lint chart - Run lint checks