GithubHelp home page GithubHelp logo

vpicone / barcli Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dtex/barcli

0.0 0.0 0.0 27 KB

A simple tool for displaying real time bar graphs in the console

License: MIT License

JavaScript 100.00%

barcli's Introduction

barcli [bahrk-lee]

Barcli is a simple tool for displaying real time data in the console. Multiple instances of barcli can be stacked to show multiple axes, sensors or other data sources in an easy to read horizontal bar graph.

Barcli exists because I needed a way to visualize Johnny-Five sensor data quickly and easily. console.log is hard to read, especially if you have more than one datapoint to track.

Installation

npm install barcli

Usage

This example uses all of barcli's default values.

var Barcli = require("barcli");

var graph = new Barcli();

graph.update(0.25); // Sets bar to 25%
graph.update(1.0); // Sets bar to 100%

Optionally, you can pass configuration parameters in an object.

var Barcli = require("barcli");

var graph = new Barcli({
  label: "My Graph",
  range: [0, 100],
});

graph.update(25); // Sets bar to 25%
graph.update(100); // Sets bar to 100%

Pro Tip: If you want to display the state of something as a string instead of a bar, just pass the string like this: graph.update("Cooking with gas"); Barcli will know what to do with it.

Configuration Options

label (String) - Label for the bar graph. Any length is fine, but make sure it will fit in your terminal window along with the bar graph (Default: "Input n")

range (Array) - The upper and lower limits for input values. This will be mapped to your bar length. One or both values can be set to null and the range will be found automatically (Default: [null, null])

autoRange (Boolean) - Grow the range to include the minimum and maximum values passed in calls to update() (Default: false. If no range is passed or null is passed then this defaults to true)

precision (Integer) - The number of digits after the decimal point to display (Default: 0)

constrain (Boolean) - Constrains displayed input value to given inputRange (Default: false)

percent (Boolean) - Displays the input value as a percentage of the inputRange (Default: false)

width (Integer) - The length of the bar in terminal characters (Default: 80)

color (String) - Colors will be assigned automatically, but you can override with your preference. Valid values are "red", "green", "yellow", "blue", "magenta", "cyan" or "white".

inline (Boolean) - When true, Barcli will not clear the console. This is ideal for single barcli instances that occur inline and maintain stdout output before and after the bar (i.e. an install or large data download). Note that you must call barcli.finish() to bump the cursor down when done with the bar graph.

Examples

Johnny-Five Sensor Input

var five = require("johnny-five");
var Barcli = require("barcli");

var board = new five.Board().on("ready", function() {

  var sensor = new five.Sensor({
    pin: "A0",
    freq: 250
  });

  var graph = new Barcli({
    label: "Sensor",
    range: [0, 100]
  });

  sensor.scale([0, 100]);

  sensor.on("data", function() {
    graph.update(this.value);
  });
});

Leap Motion Controller Input

var Leap = require("leapjs");
var Barcli = require("barcli");

var palmX = new Barcli({label: "Palm X", range: [-500, 500]});
var palmY = new Barcli({label: "Palm Y", range: [50, 400]});
var palmZ = new Barcli({label: "Palm Z", range: [-500, 500]});

Leap.loop({enableGestures: true}, function(frame) {

  if (frame.hands.length === 1) {
    palmX.update(frame.hands[0].palmPosition[0]);
    palmY.update(frame.hands[0].palmPosition[1]);
    palmZ.update(frame.hands[0].palmPosition[2]);
  }

});
Screenshot of Leap Motion Controller example

screen shot 2015-04-05 at 10 46 51 pm

A Barcli Clock

var Barcli = require("barcli");

var hours = new Barcli({ label: "Hour", range: [0, 23]});
var minutes = new Barcli({ label: "Minute", range: [0, 59]});
var seconds = new Barcli({ label: "Second", range: [0, 59]});
var milliseconds = new Barcli({ label: "Millisecond", range: [0, 999]});
var state = new Barcli({label: "Clock State", type: "string"});

var intervalID = GLOBAL.setInterval(function() {

  var now = new Date();

  hours.update(now.getHours());
  minutes.update(now.getMinutes());
  seconds.update(now.getSeconds());
  milliseconds.update(now.getMilliseconds());
  state.update(now.getSeconds() % 2 ? "Tick" : "Tock");

}, 12);

barcli's People

Contributors

dtex avatar resseguie avatar

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.