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

console-plot

v1.1.0

Published

Draw graph based on X/Y data in console

Readme

console-plot

npm version npm downloads License: MIT TypeScript

A lightweight library for drawing console-based graphs from X/Y data with intelligent downsampling and TypeScript support.

🔗 Links

🚀 Features

  • Smart Data Handling: Intelligent downsampling for large datasets
  • Multiple Formats: ESM, CommonJS, and TypeScript support
  • Zero Dependencies: Lightweight with no external dependencies
  • Customizable: Adjustable height, width, and pointer characters
  • Type Safe: Full TypeScript definitions included

📦 Installation

npm install console-plot

🎯 Quick Start

import { plotGraph } from 'console-plot';

plotGraph({
  yData: [1.4, 2.4, 2.8, 8.1, 8.4, 8.6, 8.7, 8.9, 10.5, 10.7],
  xData: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
});

Output:

 10.70                    *
 10.38                  *
 10.06
  9.74
  9.42
  9.10
  8.78              * *
  8.46          * *
  8.13        *
  7.81
  7.49
  7.17
  6.85
  6.53
  6.21
  5.89
  5.57
  5.25
  4.93
  4.61
  4.29
  3.97
  3.64
  3.32
  3.00
  2.68      *
  2.36    *
  2.04
  1.72
  1.40  *

        A B C D E F G H I J

📊 API Reference

plotGraph(params)

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | yData | number[] | required | Y-axis values (numeric data points) | | xData | (string\|number)[] | required | X-axis labels | | maxHeight | number | 30 | Maximum graph height in lines | | maxWidth | number | 30 | Maximum graph width (smart downsampling) | | pointer | string | '*' | Character used for data points |

Smart MaxWidth Handling

When your data exceeds maxWidth, console-plot intelligently downsamples by:

  • Averaging Y values within each bucket for better representation
  • Preserving data distribution across the entire dataset
  • Maintaining visual accuracy rather than just truncating
// Large dataset (100 points) → Downsampled to 10 points
const largeData = Array.from({length: 100}, (_, i) => Math.sin(i * 0.1) * 10);
const labels = Array.from({length: 100}, (_, i) => `P${i}`);

plotGraph({
  yData: largeData,
  xData: labels,
  maxWidth: 10,  // Intelligently reduces 100 points to 10
  pointer: '●'
});

🔧 Usage Examples

TypeScript Support

import { plotGraph, PlotGraphParams } from 'console-plot';

const config: PlotGraphParams = {
  yData: [1, 2, 3, 4, 5],
  xData: ['Q1', 'Q2', 'Q3', 'Q4', 'Q5'],
  maxHeight: 15,
  maxWidth: 20,
  pointer: '■',
};

plotGraph(config);

CommonJS Support

const { plotGraph } = require('console-plot');

plotGraph({
  yData: [10, 25, 30, 15, 40],
  xData: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
  maxHeight: 12,
  pointer: '@',
});

Custom Styling

plotGraph({
  yData: [1, 50, 25, 75, 100],
  xData: ['Start', 'Low', 'Mid', 'High', 'Peak'],
  maxHeight: 20,
  maxWidth: 15,
  pointer: '█',
});

🧪 Development

Running Tests

# Test different module formats
npm run test:esm        # ES Modules
npm run test:cjs        # CommonJS
npm run test:ts         # TypeScript

# Test with installed package
npm run test:installed:esm
npm run test:installed:cjs
npm run test:installed:ts

Test Categories

  • Basic Functionality: Core plotting and configuration
  • Input Validation: Error handling and parameter checking
  • Parameter Safety: Type validation and edge cases
  • MaxWidth Downsampling: Smart data reduction algorithms
  • Module Compatibility: Cross-format testing

🗺️ Roadmap

Future enhancements planned for console-plot:

🎨 Visual Improvements

  • Line Connections: Connect data points with lines using ASCII characters (, , /, \) for better trend visualization

    plotGraph({ yData, xData, showLines: true })
  • Terminal Colors: Add ANSI color support for enhanced visual appeal

    plotGraph({ yData, xData, color: 'green' })

📈 Advanced Features

  • Multiple Data Series: Plot multiple datasets on the same graph with different markers

    plotGraph({
      series: [
        { yData: [1, 2, 3], label: 'Series 1', pointer: '*' },
        { yData: [2, 4, 1], label: 'Series 2', pointer: 'o' }
      ],
      xData: ['A', 'B', 'C']
    })
  • String Output API: Return graph as string instead of printing to console

    const graph = plotGraph({ yData, xData, returnString: true })
    // Use for logging, file output, or web APIs

🔬 Algorithm Enhancements

  • Advanced Downsampling Modes: Improve data reduction quality
    • 'average' - Current averaging method (default)
    • 'min-max' - Preserve extremes for spike detection
    • 'lttb' - Largest-Triangle-Three-Buckets algorithm for better visual shape preservation
    plotGraph({ yData, xData, downsampleMode: 'lttb' })

Want to contribute? Check out issues or suggest new features!

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Run tests: npm run test:esm && npm run test:cjs && npm run test:ts
  4. Commit changes: git commit -m 'Add feature'
  5. Push to branch: git push origin feature-name
  6. Submit a pull request

📄 License

MIT © Anton Bazhenov