wunderbar

Simple horizontal bar chart printer for your terminal

Github星跟踪图

@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

主要指标

概览
名称与所有者gribnoysup/wunderbar
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2018-03-05 17:56:25
推送于2023-01-06 01:32:50
最后一次提交2021-05-07 16:20:07
发布数14
最新版本名称v2.2.2 (发布于 2019-05-12 12:16:30)
第一版名称v1.0.1 (发布于 2018-03-07 16:27:27)
用户参与
星数571
关注者数11
派生数12
提交数58
已启用问题?
问题数4
打开的问题数0
拉请求数8
打开的拉请求数8
关闭的拉请求数4
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?