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

text-chart

v1.0.8

Published

Generate simple text-based charts

Downloads

16

Readme

Text Charts

npm CircleCI

Generate text-based bar charts and histograms.

Usage - basic

Bar charts

TypeScript

import { BarChart } from "text-chart";

const barChart = new BarChart();
barChart.setData([["apples", 15], ["oranges", 3], ["bananas", 12]]);
console.log(barChart.render());
/*
 apples | ■■■■■■■■■■■■■■■ 15
oranges | ■■■ 3
bananas | ■■■■■■■■■■■■ 12
*/

Node.js

const TextChart = require("text-chart");
const barChart = new TextChart.BarChart();
barChart.setData([["apples", 15], ["oranges", 3], ["bananas", 12]]);
console.log(barChart.render());
/*
 apples | ■■■■■■■■■■■■■■■ 15
oranges | ■■■ 3
bananas | ■■■■■■■■■■■■ 12
*/

Histograms

TypeScript

import { Histogram } from "text-chart";
const histogramDefault = new Histogram().setProperties({
    width: 20, // Limit chart's max width
});
const histogramDefaultData: number[] = [];
for (let i = 0; i < 1000; i++) {
    histogramDefaultData.push(Math.random() * 60);
}
for (let i = 0; i < 1000; i++) {
    histogramDefaultData.push(40 + Math.random() * 25);
}
histogramDefault.setData(histogramDefaultData);
console.log(histogramDefault.render());
/*
  0.01 - 6.51 | ■■■■■■ 106
 6.51 - 13.01 | ■■■■■ 103
13.01 - 19.51 | ■■■■■■ 117
19.51 - 26.01 | ■■■■■ 102
 26.01 - 32.5 | ■■■■■■■ 125
    32.5 - 39 | ■■■■■ 101
    39 - 45.5 | ■■■■■■■■■■■■■■■■■ 320
    45.5 - 52 | ■■■■■■■■■■■■■■■■■■■ 353
    52 - 58.5 | ■■■■■■■■■■■■■■■■■■■■ 381
 58.5 - 64.99 | ■■■■■■■■■■■■■■■ 292
*/

Node.js

const TextChart = require("text-chart");
const histogramDefault = new TextChart.Histogram().setProperties({
    width: 20,
});
const histogramDefaultData = [];
for (let i = 0; i < 1000; i++) {
    histogramDefaultData.push(Math.random() * 60);
}
for (let i = 0; i < 1000; i++) {
    histogramDefaultData.push(40 + Math.random() * 25);
}
histogramDefault.setData(histogramDefaultData);
console.log(histogramDefault.render());
/*
  0.21 - 6.69 | ■■■■■■ 110
 6.69 - 13.17 | ■■■■■■ 106
13.17 - 19.64 | ■■■■■■ 107
19.64 - 26.12 | ■■■■■■ 116
 26.12 - 32.6 | ■■■■■ 97
 32.6 - 39.08 | ■■■■■■ 114
39.08 - 45.56 | ■■■■■■■■■■■■■■■■■■■ 348
45.56 - 52.04 | ■■■■■■■■■■■■■■■■■■■■ 372
52.04 - 58.51 | ■■■■■■■■■■■■■■■■■■■ 352
58.51 - 64.99 | ■■■■■■■■■■■■■■■ 278
*/

Instance methods

(BarChart) setData(data: Array<[string, number]>): BarChart;

data is an array of arrays with each sub-array's first element being the bar's label (string) and second element being the value of that bar.

(Histogram) setData(data: number[]): Histogram

data is an array of numbers.

(Histogram, BarChart) setProperties(properties): BarChart | Histogram

properties.width (optional): Sets maximum width (number of characters) of chart. If not given, bars will be rendered according to values in setData.

properties.barCharacter (optional): Character used to render bars.

properties.min, properties.max, properties.interval (optional, histogram only): Set minimum, maximum and interval values for histogram. If left out, estimates will be calculated from the data.