项目作者: catdad

项目描述 :
:chart_with_upwards_trend: boxes and whiskers
高级语言: JavaScript
项目地址: git://github.com/catdad/plain-text-box-plot.git
创建时间: 2016-06-05T21:39:03Z
项目社区:https://github.com/catdad/plain-text-box-plot

开源协议:

下载


plain-text-box-plot

Build
Code Climate
Downloads
Version
ISC License

A small Node library that creates box plots in plain text. Great for outputting box plots from CLI tools.

API

  1. var ptBox = require('plain-text-box-plot');
  2. var data = {
  3. min: 1,
  4. q1: 2,
  5. q2: 3,
  6. q3: 4,
  7. max: 5
  8. };
  9. var boxplotString = ptBox(data);

Example output:

  1. +--------+--------+
  2. |--------| | |--------|
  3. +--------+--------+

By default, the width of the output will be at most 75 characters. (Note: sometimes it can be 74, depending on the data.) You can also set this value with an optional second parameter:

  1. var ptBox = require('plain-text-box-plot');
  2. var data = { ... };
  3. var boxplotString = ptBox(data, 120);

If you are going to console.log it, and would like to match the console width, you can figure that out as such:

  1. var tty = require('tty');
  2. var isatty = tty.isatty(1) && tty.isatty(2);
  3. var width;
  4. // if we are not in a tty session, you don't want to do this
  5. if (isatty) {
  6. width = process.stdout.getWindowSize ?
  7. process.stdout.getWindowSize(1)[0] :
  8. tty.getWindowSize()[1];
  9. }
  10. var ptBox = require('plain-text-box-plot');
  11. var data = { ... };
  12. var boxplotString = ptBox(data, width);

License

ISC