= ProgressbarSnapshot
A simple widget that generates progress bars in png format. There are other ways to
generate a progress bar with css, html and javascript. However, if you have to
stick a progress bar in a pdf you probably need to stick it in as an image.
Rmagick gem required.
== Example usage:
In a stand alone script:
require 'rubygems'
require 'progress_bar_snapshot'
pb = ProgressBarSnapshot.new(200, 50, [15.0, 25, 4.1, 2.9])
pb.to_file("47percent.png")
This will generate a png file 200x50 called 47percent.png. Since the sum of
15.0, 25, 4.1, 2.9 is 47 the progress bar would be 47% full.
In your rails app:
In your controller:
require 'progress_bar_snapshot'
...
class MySomethingController < ApplicationController
helper :progress_bar_snapshot
...
# define an action to render and send the png
def progress_bar
percentages = params[:percentages].split(",").collect { |p| p.to_f }
bar = ProgressBarSnapshot.new(
params[:width].to_i, params[:height].to_i,
percentages)
send_data bar.to_blob, :type => 'image/png', :disposition => 'inline',
:filename => "progress.png"
end
In your view:
<%= progress_bar_png_tag(
[12.4, 24,1, 25.6],
['#0398B3', '#E9C74B' ],
{ :width => 178,
:height => 18,
:controller => 'my_something',
:action => 'progress_bar' }
) %>
Customizable colors:
These following parameters can be passed in to the progress bar snapshot constructor
:border_color # outer border color, defaults to "#666666",
:progress_colors # progress bar colors, defaults to alternating between 'skyblue', 'grey' ,'salmon',
:background # color of unfilled portion of the progress bar, defaults to "white",
:font_family # default font to "arial",
:font_color # default color of the font "black",
All the colors are passed straight to Rmagick, so they can be any color Rmagick supports.
For example:
pb = ProgressBarSnapshot.new(200, 50, [35.0, 25, 14.1, 12.9],
:progress_colors => ['blue', 'SteelBlue', 'skyblue', 'grey'],
:background => 'grey90')
Multiple Segments:
This release of progress bar can be instructed to generate "sausage links" segments of progress bars.
You can pass it any number of percentages and their corresponding colors. Each of these percentages
would be drawn and their sum would be displayed on the progress bar.
== Authors, credits, blame, contact!
xiaoke@microplace.com
julio@microplace.com