Giter Site home page Giter Site logo

gribnoysup / wunderbar Goto Github PK

View Code? Open in Web Editor NEW
574.0 13.0 21.0 1.5 MB

Simple horizontal bar chart printer for your terminal

Home Page: https://npm.im/@gribnoysup/wunderbar

License: MIT License

JavaScript 100.00%
nodejs cli bar chart bar-chart terminal library

wunderbar's Introduction

@gribnoysup/wunderbar

Have you ever wanted to print some pretty bar charts in your terminal? You are in the right place!

wunder-bar-cli-all

Wunderbar can print horisontal bar chart with legend and chart scale straight to your terminal. Or you can use it as a module in your code and get all the building blocks to print chart yourself.

Wunderbar uses partial block characters (▏▎▍▌▋▊▉█) to print the most precise charts possible:

wunder-bar-precise

Use in terminal

echo "[1, 2, 3, 4, 5]" | npx @gribnoysup/wunderbar --min 0

wunder-bar-echo-json

cat data.json | npx @gribnoysup/wunderbar --min 0

wunder-bar-cat-file

Use in your code

npm i --save @gribnoysup/wunderbar
const wunderbar = require('@gribnoysup/wunderbar');
const data = require('./data.json');

const printData = () => {
  const { chart, legend, scale, __raw } = wunderbar(data, {
    min: 0,
    length: 42,
  });

  console.log();
  console.log(chart);
  console.log();
  console.log(scale);
  console.log();
};

printData();

Limitations

  • Wunderbar supports only node >= 6

  • Wunderbar uses chalk.hex to add color to your charts. Chalk is pretty smart to downgrade the color if it is not supported by your terminal, but output may vary in different terminals.

API

wunderbar(values, [options]) ⇒ OutputValue

Param Type Default Description
values Array<InputValue> Values to draw on a chart
[options] Object Chart drawing options
[options.min] number min value from values Min chart value (inclusive)
[options.max] number max value from values Max chart value (inclusive)
[options.length] number terminal width Chart length
[options.sort] "min" | "max" | "none" | (a: NormalizedValue, b: NormalizedValue) => number "none" Sort method for chart values
[options.randomColorOptions] Object {} randomColor options for color generation
[options.format] string | (a: number) => string "0.00" Value format method. String values are Numeral.js format strings

All options are also supported in the cli version:

echo "[1000, 3000, 5000, 7000, 9000, 11000]" | \
  npx @gribnoysup/wunderbar --min 0 --max 15000 --length 42 --sort min --randomColorOptions '{ "seed": "unicorn" }' --format "0a"

wunder-bar-cli-all

Types

InputValue : { value: number, color?: string, label?: string } | number | string

OutputValue : { legend: string, scale: string, chart: string, __raw: RawData }

RawData : { chartLength: number, minValue: number, minValueFormatted: string, maxValue: number, maxValueFormatted: string, normalizedValues: NormalizedValue[] }

NormalizedValue : { normalizedValue: number, rawValue: number, formattedValue: string, color: string, label: string, lineLength: number, chartBar: string, coloredChartBar: string }

License

MIT

wunderbar's People

Contributors

dependabot[bot] avatar gribnoysup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wunderbar's Issues

Configurable colors

I would like to be able to explicitly set the hex value or name of the color for each data value, is that possible?

[REQUEST] Show lowest and largest number

Would be pretty useful, if the inputs are below 0, it'd show the lowest and largest number on the scale and in legend. 💯

Right now, it only shows 0.00, but I'm working with numebrs like 0.0000001. 🌵

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.