one simple pills PillChart

A simple rubygem for create little svg pill charts.

Like this :

state_pills

Or without progression state :

simple_pills

It can be used alone, or in Rails (tested in 4.0.4) as a view helper.

Use it in Rails in 3 steps

  1. Add pill_chart to your Gemfile (by adding this line: gem 'pill_chart', '~> 1.0.2')
  2. Run bundle install into your terminal, on your rails project directory
  3. Use the following methods directly into your views ! (Don't forget to mark it as html_safe)

Helpers overview

# It will draw a simple pill, filled to `value`.
draw_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {})
# It will draw a stated pill (the color changes with the value), filled to `value`.
draw_state_pill_chart(height: 10, width: 60, value: 33, max: 100, colors: {})

Some examples

Draw a simple pill at 33% (simple pills ) in a Rails view:

<%= draw_pill_chart(width: 60, value: 33).html_safe %>

Draw a state pill at 70% (state pills ) in a Rails view:

<%= draw_state_pill_chart(width: 60, value: 70).html_safe %>

Available parameters

The max parameter represents the maximum value. For example, a value of 60 and a max of 120 will fill the half of the pill.

You can pass custom colors in a hash to the colors parameter. The color's default values are :

colors = {
    "background" => "#eee", # the background colour
    "foreground" => "#999", # the pill color when it's a simple pill (not a state pill)
    "low" => "#AD6D6D", # the pill color under 20% when it's a state pill
    "medium" => "#C59663", # the pill color between 20 and 40% when it's a state pill
    "high" => "#ADC563", # the pill color between 40 and 70% when it's a state pill
    "full" => "#92C447" # the pill color between 70 and 100% when it's a state pill
}

Use it without Rails

# Create a new SimplePillChart object, with theses parameters
elt = PillChart::SimplePillChart.new(height, width, value, max, :simple, colors)

# Run the pill method to generate the svg content
elt.pill