Project

spark_pr

0.0
No commit activity in last 3 years
No release in over 3 years
spark_pr is a Ruby class to generate sparkline graphs with PNG or ASCII output. It only depends on zlib and generates PNGs with pure Ruby code. The line-graph outputs antialised lines.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.10
~> 10.0
 Project Readme
spark_pr is a Ruby class to generate sparkline graphs with PNG or ASCII output.

It only depends on zlib and generates PNGs with pure Ruby code.
The line-graph outputs antialised lines.

Example for PNG output:

File.open( 'test.png', 'wb' ) do |png|
  png << Spark.plot( [47, 43, 24, 47, 16, 28, 38, 57, 50, 76,
                      42, 20, 98, 34, 53,  1, 55, 74, 63, 38,
                      31, 98, 89],
                     :has_min => true, :has_max => true, 'has_last' => 'true',
                     'height' => '40', :step => 10, :normalize => 'logarithmic' )
end

Example ASCII output:

spark = Spark.new({:has_min => true, :has_max => true, :height => 14, :step => 4})
puts spark.smooth( [47, 43, 24, 47, 16, 28, 38, 57, 50, 76,
                    42,  1, 98, 34, 53, 97, 55, 74, 63, 38,
                    31, 98, 89] ).to_ascii

The PNG output can also be obtained in data: URI format convenient for web
use. If the Spark.data_uri is used, there is also a dependency on Base64,
which is a standard library just like Zlib

You can paste the output from:

Spark.data_uri( [47, 43, 24, 47, 16, 28, 38, 57, 50, 76,
                 42, 20, 98, 34, 53,  1, 55, 74, 63, 38,
                 31, 98, 89],
                :has_min => true, :has_max => true, 'has_last' => 'true',
                'height' => '40', :step => 10, :normalize => 'logarithmic' )

into your browser's address and see the PNG directly.

Class based usage:

spark = Spark.new(:has_min => true, :has_max => true, 'has_last' => 'true',
                  'height' => '40', :step => 10, :normalize => 'logarithmic' )
spark.smooth(data)

File.open( 'test.png', 'wb' ) do |png|
  png << spark.png
end

img_src = spark.data_uri


The SparkCanvas class can also be used for other drawing operations,
it provides drawing canvas with alpha blending and some primitive graphics
operations and PNG output in just about 100 lines of Ruby code.

Pure Ruby sparklines are released under the terms of the MIT-LICENSE.
See the included MIT-LICENSE file for details.