ascii_bar_charter

ASCII character-based bar chart generator
HEAD Yanked release released

ascii_bar_charter

Travis status: Travis

GitHub release

This is a ASCII character-based bar char generator, with optional value prefix (of given precision) and optional colorization (red/green gradations).

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      ascii_bar_charter:
        github: drhuffman12/ascii_bar_charter
        branch: master
    
  2. Run shards install

Usage

require "ascii_bar_charter"

Generate a B/W barchart of values with associated value as a prefix:

  min = 0.0
  max = 1.0
  precision = 2.to_i8
  in_bw = true
  data = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9]
  prefixed = true
  reversed = false

  charter = AsciiBarCharter.new(min, max, precision, in_bw, reversed)
  plot = charter.plot(data, prefixed)

  puts plot

This will (when in bw only) look like:

0.0_0.1▁0.2▂0.3▃0.4▄0.5▅0.6▆0.7▇0.8█0.9▉
_▁▂▃▄▅▆▇█▉

And, using custom colors/bars could look like:

.0.0'0.1'0.2░0.3░0.4▒0.5▒0.6▒0.7▓0.8▓0.9█
.''░░▒▒▒▓▓█

For other examples, see the tests.

Testing

(Optionally,) open a docker-compose terminal:

docker-compose run app bash

Then run tests:

crystal spec

It should look like:

examples.png

Contributing

  1. Fork it (https://github.com/your-github-user/ascii_bar_charter/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

ascii_bar_charter:
  github: drhuffman12/ascii_bar_charter
  
License MIT
Crystal >= 0.36.0

Authors

Dependencies 0

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently