Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

histogram-rb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

histogram-rb

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Histogram

Ruby CI Publish new releases to rubygems

Easily create a histogram from an array of values and allow easy rendering to the terminal.

Installation

Add this line to your application's Gemfile:

gem 'histogram-rb'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install histogram-rb

Usage

Initialize a Histogram with a list of values:

histogram = Histogram.new(1000.times.map { Random.rand })

Then call render to get a print-friendly string, all parameters are optional.

histogram.render(
  title: "Uniform Distribution",
  precision: 2,
)
                              Uniform Distribution
═════════════════════════════════════════════════════════════════════════════════
    x                       x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
    x           x           x           x           x           x          x
─────────────────────────────────────────────────────────────────────────────────
 0.0-0.14   0.14-0.29   0.29-0.43   0.43-0.57   0.57-0.71   0.71-0.86   0.86-1.0
 (150)      (128)       (154)       (145)       (136)       (150)       (137)

You can use the border parameter to specify a terminal-table border class to change the output. e.g.

histogram.render(
  title: "Normal Distribution",
  precision: 2,
  border: Terminal::Table::AsciiBorder.new,
)
                               Normal Distribution
-----------+----------+----------+-----------+-----------+-----------+-----------
                                       x
                                       x
                           x           x
                           x           x
                           x           x           x
                           x           x           x           x
                           x           x           x           x
                x          x           x           x           x
                x          x           x           x           x
     x          x          x           x           x           x           x
     x          x          x           x           x           x           x
     x          x          x           x           x           x           x
-----------+----------+----------+-----------+-----------+-----------+-----------
 0.02-0.16   0.16-0.3   0.3-0.44   0.44-0.57   0.57-0.71   0.71-0.85   0.85-0.98
 (26)        (51)       (108)      (141)       (81)        (73)        (24)

Development

After checking out the repo, run bundle install to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

Testing

Running the unit tests with bundle exec rake test.

The rendering portion of the histogram is harder to test with unit tests. Instead there is a script that will allow you to render histograms easily to enable visual tests.

Examples:

bin/test bin/test -b ascii -p 2 bin/test -t "Example Title" -b thick -p 2 bin/test -t "Example Title" -b ascii -p 3 bin/test -t "Normal Distribution" -d normal -p 2 -c 10000

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 09 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc