googlecharts 1.3.4 → 1.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.sig +2 -4
- data/History.txt +8 -0
- data/Manifest.txt +2 -0
- data/lib/gchart.rb +23 -11
- data/lib/gchart/theme.rb +46 -0
- data/lib/gchart/version.rb +1 -1
- data/spec/gchart_spec.rb +16 -0
- data/spec/theme_spec.rb +34 -0
- metadata +15 -4
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
@@ -1,4 +1,2 @@
|
|
1
|
-
{�(
|
2
|
-
|
3
|
-
�H��с7���j����J� �1)F��XC��ږ����c̘<9a�9�p�t5K�p�5��`�сbII�3��F鐫ﶫ_��bl&`=�;����I#�3Zd�@�sx�ޭa��^#'�z�2O������1��̀�>�s��|�
|
4
|
-
�bw���\"Lڇ�j<���K��ynv�9d`~��G��Y�
|
1
|
+
Е{.���Z��M4G�����ZZ$6<���V!B�t�Ye�=)�!xV�_-0��������N3�D�^L0�S�~����@�^ ���@/������G;�_8��_PN��H�%q��asR���:���7��/гn�^����'�"����B>y��(G�������S��n.>��{9�����V`%^��Fh/�m~Z,�`
|
2
|
+
�O�D��>stt̥t+
|
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.3.6
|
2
|
+
* support nil values. The Google Charts API specifies that a single underscore (_) can be used to omit a value from a line chart with 'simple' data encoding, and a double underscore (__) can do the same for a chart with 'extended' data encoding. (Matt Moyer)
|
3
|
+
* allow a label to appear on a google-o-meter via the :legend option. (hallettj)
|
4
|
+
|
5
|
+
== 1.3.5
|
6
|
+
* added code to properly escape image tag URLs (mokolabs)
|
7
|
+
* added themes support + 4 default themes (keynote, thirty7signals, pastel, greyscale) chart.line(:theme=>:keynote) (jakehow)
|
8
|
+
|
1
9
|
== 1.3.4
|
2
10
|
* updated documentation and cleaned it up (mokolabs)
|
3
11
|
* added support for custom class, id and alt tags when using the image_tag format (i.e Gchart.line(:data => [0, 26], :format => 'image_tag')) (mokolabs)
|
data/Manifest.txt
CHANGED
data/lib/gchart.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
2
|
require 'gchart/version'
|
3
|
+
require 'gchart/theme'
|
3
4
|
require "open-uri"
|
4
5
|
require "uri"
|
5
6
|
|
@@ -19,6 +20,9 @@ class Gchart
|
|
19
20
|
|
20
21
|
# Support for Gchart.line(:title => 'my title', :size => '400x600')
|
21
22
|
def self.method_missing(m, options={})
|
23
|
+
# Start with theme defaults if a theme is set
|
24
|
+
theme = options[:theme]
|
25
|
+
options = theme ? Chart::Theme.load(theme).to_options.merge(options) : options
|
22
26
|
# Extract the format and optional filename, then clean the hash
|
23
27
|
format = options[:format] || 'url'
|
24
28
|
@@file_name = options[:filename] unless options[:filename].nil?
|
@@ -130,7 +134,7 @@ class Gchart
|
|
130
134
|
image = "<img"
|
131
135
|
image += " id=\"#{@id}\"" if @id
|
132
136
|
image += " class=\"#{@class}\"" if @class
|
133
|
-
image += " src=\"#{query_builder}\""
|
137
|
+
image += " src=\"#{query_builder(:html)}\""
|
134
138
|
image += " width=\"#{@width}\""
|
135
139
|
image += " height=\"#{@height}\""
|
136
140
|
image += " alt=\"#{@alt}\""
|
@@ -231,7 +235,7 @@ class Gchart
|
|
231
235
|
# or
|
232
236
|
# Gchart.line(:legend => ['first label', 'last label'])
|
233
237
|
def set_legend
|
234
|
-
return set_labels if @type == :pie || @type == :pie_3d
|
238
|
+
return set_labels if @type == :pie || @type == :pie_3d || @type == :meter
|
235
239
|
|
236
240
|
if @legend.is_a?(Array)
|
237
241
|
"chdl=#{@legend.map{|label| "#{label}"}.join('|')}"
|
@@ -321,12 +325,12 @@ class Gchart
|
|
321
325
|
# to about 300 pixels. Simple encoding is suitable for all other types of chart regardless of size.
|
322
326
|
def simple_encoding(dataset=[])
|
323
327
|
dataset = prepare_dataset(dataset)
|
324
|
-
@max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
|
328
|
+
@max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
|
325
329
|
|
326
330
|
if @max_value == false || @max_value == 'false' || @max_value == :false || @max_value == 0
|
327
|
-
"s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value(number) }.join }.join(',')
|
331
|
+
"s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value(number) }.join }.join(',')
|
328
332
|
else
|
329
|
-
"s:" + dataset.map { |ds| ds.map { |number| convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
|
333
|
+
"s:" + dataset.map { |ds| ds.map { |number| number.nil? ? '_' : convert_to_simple_value( (@@simple_chars.size - 1) * number / @max_value) }.join }.join(',')
|
330
334
|
end
|
331
335
|
|
332
336
|
end
|
@@ -357,18 +361,18 @@ class Gchart
|
|
357
361
|
def extended_encoding(dataset=[])
|
358
362
|
|
359
363
|
dataset = prepare_dataset(dataset)
|
360
|
-
@max_value = dataset.map{|ds| ds.max}.max if @max_value == 'auto'
|
364
|
+
@max_value = dataset.compact.map{|ds| ds.compact.max}.max if @max_value == 'auto'
|
361
365
|
|
362
366
|
if @max_value == false || @max_value == 'false' || @max_value == :false
|
363
|
-
"e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value(number)}.join }.join(',')
|
367
|
+
"e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value(number)}.join }.join(',')
|
364
368
|
else
|
365
|
-
"e:" + dataset.map { |ds| ds.map { |number| convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
|
369
|
+
"e:" + dataset.map { |ds| ds.map { |number| number.nil? ? '__' : convert_to_extended_value( (@@ext_pairs.size - 1) * number / @max_value) }.join }.join(',')
|
366
370
|
end
|
367
371
|
|
368
372
|
end
|
369
373
|
|
370
374
|
|
371
|
-
def query_builder
|
375
|
+
def query_builder(options="")
|
372
376
|
query_params = instance_variables.map do |var|
|
373
377
|
case var
|
374
378
|
# Set the graph size
|
@@ -399,7 +403,15 @@ class Gchart
|
|
399
403
|
end
|
400
404
|
end.compact
|
401
405
|
|
402
|
-
|
406
|
+
# Use ampersand as default delimiter
|
407
|
+
unless options == :html
|
408
|
+
delimiter = '&'
|
409
|
+
# Escape ampersand for html image tags
|
410
|
+
else
|
411
|
+
delimiter = '&'
|
412
|
+
end
|
413
|
+
|
414
|
+
jstize(@@url + query_params.join(delimiter))
|
403
415
|
end
|
404
416
|
|
405
|
-
end
|
417
|
+
end
|
data/lib/gchart/theme.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Chart
|
4
|
+
class Theme
|
5
|
+
class ThemeNotFound < RuntimeError; end
|
6
|
+
|
7
|
+
@@theme_files = ["#{File.dirname(__FILE__)}/../themes.yml"]
|
8
|
+
|
9
|
+
attr_accessor :colors
|
10
|
+
attr_accessor :bar_colors
|
11
|
+
attr_accessor :background
|
12
|
+
attr_accessor :chart_background
|
13
|
+
|
14
|
+
def self.load(theme_name)
|
15
|
+
theme = new(theme_name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.theme_files
|
19
|
+
@@theme_files
|
20
|
+
end
|
21
|
+
|
22
|
+
# Allows you to specify paths for custom theme files in YAML format
|
23
|
+
def self.add_theme_file(file)
|
24
|
+
@@theme_files << file
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(theme_name)
|
28
|
+
themes = {}
|
29
|
+
@@theme_files.each {|f| themes.update YAML::load(File.open(f))}
|
30
|
+
theme = themes[theme_name]
|
31
|
+
if theme
|
32
|
+
self.colors = theme[:colors]
|
33
|
+
self.bar_colors = theme[:bar_colors]
|
34
|
+
self.background = theme[:background]
|
35
|
+
self.chart_background = theme[:chart_background]
|
36
|
+
self
|
37
|
+
else
|
38
|
+
raise(ThemeNotFound, "Could not locate the #{theme_name} theme ...")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_options
|
43
|
+
{:background => background, :chart_background => chart_background, :bar_colors => bar_colors.join(',')}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/gchart/version.rb
CHANGED
data/spec/gchart_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
require File.dirname(__FILE__) + '/../lib/gchart'
|
3
3
|
|
4
|
+
Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/test_theme.yml")
|
5
|
+
|
4
6
|
# Time to add your specs!
|
5
7
|
# http://rspec.rubyforge.org/
|
6
8
|
describe "generating a default Gchart" do
|
@@ -26,6 +28,11 @@ describe "generating a default Gchart" do
|
|
26
28
|
@chart.include?('cht=lc').should be_true
|
27
29
|
end
|
28
30
|
|
31
|
+
it 'should use theme defaults if theme is set' do
|
32
|
+
Gchart.line(:theme=>:test).include?('chco=6886B4,FDD84E').should be_true
|
33
|
+
Gchart.line(:theme=>:test).include?(Gchart.jstize('chf=c,s,FFFFFF|bg,s,FFFFFF')).should be_true
|
34
|
+
end
|
35
|
+
|
29
36
|
it "should use the simple encoding by default with auto max value" do
|
30
37
|
# 9 is the max value in simple encoding, 26 being our max value the 2nd encoded value should be 9
|
31
38
|
Gchart.line(:data => [0, 26]).include?('chd=s:A9').should be_true
|
@@ -404,6 +411,15 @@ describe 'exporting a chart' do
|
|
404
411
|
it "should be available as an image tag using custom css class selector" do
|
405
412
|
Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should match(/<img class="chart" src=(.*) width="300" height="200" alt="Google Chart" \/>/)
|
406
413
|
end
|
414
|
+
|
415
|
+
it "should use ampersands to separate key/value pairs in URLs by default" do
|
416
|
+
Gchart.line(:data => [0, 26]).should satisfy {|chart| chart.include? "&" }
|
417
|
+
Gchart.line(:data => [0, 26]).should_not satisfy {|chart| chart.include? "&" }
|
418
|
+
end
|
419
|
+
|
420
|
+
it "should escape ampersands in URLs when used as an image tag" do
|
421
|
+
Gchart.line(:data => [0, 26], :format => 'image_tag', :class => 'chart').should satisfy {|chart| chart.include? "&" }
|
422
|
+
end
|
407
423
|
|
408
424
|
it "should be available as a file" do
|
409
425
|
File.delete('chart.png') if File.exist?('chart.png')
|
data/spec/theme_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/gchart'
|
3
|
+
|
4
|
+
describe "generating a default Gchart" do
|
5
|
+
it 'should be able to add additional theme files' do
|
6
|
+
Chart::Theme.theme_files.should_not include("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml")
|
7
|
+
Chart::Theme.add_theme_file("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml")
|
8
|
+
Chart::Theme.theme_files.should include("#{File.dirname(__FILE__)}/fixtures/another_test_theme.yml")
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should be able to load themes from the additional theme files' do
|
12
|
+
lambda { Chart::Theme.load(:test_two) }.should_not raise_error
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should raise ThemeNotFound if theme does not exist' do
|
16
|
+
lambda { Chart::Theme.load(:nonexistent) }.should raise_error(Chart::Theme::ThemeNotFound, "Could not locate the nonexistent theme ...")
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set colors array' do
|
20
|
+
Chart::Theme.load(:keynote).colors.should eql(["6886B4", "FDD84E", "72AE6E", "D1695E", "8A6EAF", "EFAA43", "FFFFFF", "000000"])
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should set bar colors array' do
|
24
|
+
Chart::Theme.load(:keynote).bar_colors.should eql(["6886B4", "FDD84E", "72AE6E", "D1695E", "8A6EAF", "EFAA43"])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should set background' do
|
28
|
+
Chart::Theme.load(:keynote).background.should eql("000000")
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should set chart background' do
|
32
|
+
Chart::Theme.load(:keynote).chart_background.should eql("FFFFFF")
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: googlecharts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Aimonetti
|
@@ -30,10 +30,19 @@ cert_chain:
|
|
30
30
|
ZR7qHIpykzr3ezcNiWtBWw==
|
31
31
|
-----END CERTIFICATE-----
|
32
32
|
|
33
|
-
date: 2008-
|
33
|
+
date: 2008-10-04 00:00:00 -07:00
|
34
34
|
default_executable:
|
35
|
-
dependencies:
|
36
|
-
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hoe
|
38
|
+
type: :development
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.7.0
|
45
|
+
version:
|
37
46
|
description: description of gem
|
38
47
|
email: mattaimonetti@gmail.com
|
39
48
|
executables: []
|
@@ -55,9 +64,11 @@ files:
|
|
55
64
|
- config/requirements.rb
|
56
65
|
- lib/gchart.rb
|
57
66
|
- lib/gchart/aliases.rb
|
67
|
+
- lib/gchart/theme.rb
|
58
68
|
- lib/gchart/version.rb
|
59
69
|
- setup.rb
|
60
70
|
- spec/gchart_spec.rb
|
71
|
+
- spec/theme_spec.rb
|
61
72
|
- spec/spec.opts
|
62
73
|
- spec/spec_helper.rb
|
63
74
|
- tasks/environment.rake
|
metadata.gz.sig
CHANGED
Binary file
|