pie-high 0.1.0 → 0.2.0
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/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/hash_extensions.rb +9 -0
- data/lib/high_chart.rb +10 -6
- data/lib/high_chart_series.rb +8 -7
- data/pie-high.gemspec +7 -2
- data/spec/assets/high_chart_defaults.yml +9 -0
- data/spec/high_chart_series_spec.rb +4 -2
- data/spec/high_chart_spec.rb +18 -18
- metadata +22 -4
data/Rakefile
CHANGED
@@ -13,6 +13,7 @@ begin
|
|
13
13
|
gem.authors = ["Jeff Sutherland"]
|
14
14
|
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
15
|
gem.add_development_dependency "ruport", ">=1.6.1"
|
16
|
+
gem.add_development_dependency "json_pure", ">=1.1.9"
|
16
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
18
|
end
|
18
19
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/high_chart.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
require "yaml"
|
2
|
+
require "hash_extensions"
|
3
|
+
require "json"
|
4
|
+
|
1
5
|
class HighChart
|
2
6
|
attr_accessor :chart, :credits, :colors, :global, :labels, :lang, :legend, :loading, :plot_options, :point, :series,
|
3
|
-
:subtitle, :symbols, :title, :toolbar, :tooltip, :x_axis, :y_axis, :x_axis_labels,
|
7
|
+
:subtitle, :symbols, :title, :toolbar, :tooltip, :x_axis, :y_axis, :x_axis_labels,
|
4
8
|
:chart_div, :chart_type, :width
|
5
9
|
|
6
10
|
def initialize(series, options={})
|
@@ -41,6 +45,7 @@ class HighChart
|
|
41
45
|
return default_value
|
42
46
|
end
|
43
47
|
|
48
|
+
# read a yaml file of defaults and write out the options
|
44
49
|
def read_defaults(config_file)
|
45
50
|
begin
|
46
51
|
defaults = YAML.load_file(config_file)
|
@@ -53,6 +58,8 @@ class HighChart
|
|
53
58
|
end
|
54
59
|
end
|
55
60
|
rescue Exception => e
|
61
|
+
puts e.message
|
62
|
+
puts e.backtrace
|
56
63
|
raise e
|
57
64
|
end
|
58
65
|
end
|
@@ -67,7 +74,7 @@ class HighChart
|
|
67
74
|
end
|
68
75
|
|
69
76
|
default_chart = {"renderTo" => @chart_div, "defaultSeriesType" => @chart_type}
|
70
|
-
default_chart.merge!({"width" => @width}) if width
|
77
|
+
default_chart.merge!({"width" => @width}) if @width != nil
|
71
78
|
default_chart.merge!(@chart) if @chart
|
72
79
|
|
73
80
|
return default_chart
|
@@ -91,10 +98,7 @@ class HighChart
|
|
91
98
|
end
|
92
99
|
|
93
100
|
def y_axis
|
94
|
-
|
95
|
-
y_axis_hash["title"] = @y_axis_title
|
96
|
-
y_axis_hash.merge!(@y_axis) if @y_axis
|
97
|
-
return y_axis_hash
|
101
|
+
return @y_axis
|
98
102
|
end
|
99
103
|
|
100
104
|
def to_json
|
data/lib/high_chart_series.rb
CHANGED
@@ -5,7 +5,7 @@ class HighChartSeries
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
|
8
|
-
# builds an array of series
|
8
|
+
# builds an array of series to make a chart more interesting
|
9
9
|
# series_name_attribute - string of method to call to get series name
|
10
10
|
# attribute_of_interest - method with the numeric data to build the chart
|
11
11
|
# chart_data - array of query results with which to build a series
|
@@ -23,7 +23,7 @@ class HighChartSeries
|
|
23
23
|
return series
|
24
24
|
end
|
25
25
|
|
26
|
-
# will generate a hash
|
26
|
+
# will generate a hash
|
27
27
|
# {:name => "My Wonderful Series", :data => [0, 1, 2, 3]
|
28
28
|
# series_options => used to define individual options for series
|
29
29
|
def single_series(series_name, attribute_of_interest, chart_series_data, series_options={})
|
@@ -31,10 +31,10 @@ class HighChartSeries
|
|
31
31
|
|
32
32
|
if chart_series_data.kind_of?(Array)
|
33
33
|
for datum in chart_series_data
|
34
|
-
series_data << datum.send(attribute_of_interest)
|
34
|
+
series_data << datum.send(attribute_of_interest).to_f
|
35
35
|
end
|
36
36
|
else
|
37
|
-
series_data << chart_series_data
|
37
|
+
series_data << chart_series_data.to_f
|
38
38
|
end
|
39
39
|
|
40
40
|
unless series_options == nil
|
@@ -62,7 +62,8 @@ class HighChartSeries
|
|
62
62
|
return final_series
|
63
63
|
end
|
64
64
|
|
65
|
-
# accommodates multi-dimensional pivot tables
|
65
|
+
# accommodates multi-dimensional pivot tables
|
66
|
+
# based on Ruport pivot tables
|
66
67
|
# also generates your x-axis labels
|
67
68
|
def pivot_series(series_name_attribute, attribute_of_interest, chart_data, options={})
|
68
69
|
series = []
|
@@ -102,12 +103,12 @@ class HighChartSeries
|
|
102
103
|
return x_labels, series
|
103
104
|
end
|
104
105
|
|
105
|
-
# for building multiple, non-identical series for combo line
|
106
|
+
# for building multiple, non-identical series for combo line, bar charts
|
106
107
|
# series_name_attributes - attributes to get "name" keys from
|
107
108
|
# attributes_of_interest - array of strings naming the attributes to examine
|
108
109
|
# chart_data - the data to build the chart from, an array of arrays, if you will
|
109
110
|
# series_options - array of hashes to be passed to single_series
|
110
|
-
def multi_axis_series(series_name_attributes, attributes_of_interest, chart_data_arr, series_options=[{}, {"type" => "
|
111
|
+
def multi_axis_series(series_name_attributes, attributes_of_interest, chart_data_arr, series_options=[{}, {"type" => "line", "yAxis"=>1}, {"type" => "line", "yAxis"=>2}])
|
111
112
|
series = []
|
112
113
|
|
113
114
|
chart_data_arr.each_with_index do |chart_data, index|
|
data/pie-high.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pie-high}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeff Sutherland"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-31}
|
13
13
|
s.description = %q{High Charts is one of the best JavaScript charting libraries there is. Here is a straight-forward
|
14
14
|
Ruby API to harness all the power High Charts has to offer. Includes support for Ruport pivot tables.}
|
15
15
|
s.email = %q{jefferey.sutherland@gmail.com}
|
@@ -24,9 +24,11 @@ Gem::Specification.new do |s|
|
|
24
24
|
"README.rdoc",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
|
+
"lib/hash_extensions.rb",
|
27
28
|
"lib/high_chart.rb",
|
28
29
|
"lib/high_chart_series.rb",
|
29
30
|
"pie-high.gemspec",
|
31
|
+
"spec/assets/high_chart_defaults.yml",
|
30
32
|
"spec/high_chart_series_spec.rb",
|
31
33
|
"spec/high_chart_spec.rb",
|
32
34
|
"spec/spec.opts",
|
@@ -50,13 +52,16 @@ Gem::Specification.new do |s|
|
|
50
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
53
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
54
|
s.add_development_dependency(%q<ruport>, [">= 1.6.1"])
|
55
|
+
s.add_development_dependency(%q<json_pure>, [">= 1.1.9"])
|
53
56
|
else
|
54
57
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
58
|
s.add_dependency(%q<ruport>, [">= 1.6.1"])
|
59
|
+
s.add_dependency(%q<json_pure>, [">= 1.1.9"])
|
56
60
|
end
|
57
61
|
else
|
58
62
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
63
|
s.add_dependency(%q<ruport>, [">= 1.6.1"])
|
64
|
+
s.add_dependency(%q<json_pure>, [">= 1.1.9"])
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
require "high_chart"
|
3
3
|
require "high_chart_series"
|
4
|
+
require "ruport"
|
5
|
+
|
4
6
|
include Ruport::Data
|
5
7
|
|
6
8
|
class ChartData
|
@@ -92,7 +94,7 @@ describe HighChartSeries do
|
|
92
94
|
it "should build a multi series from a ruport table" do
|
93
95
|
series = HighChartSeries.multi_series("event", "count", table.data.collect(& :data))
|
94
96
|
series.size.should == 2
|
95
|
-
series.first[:data].first.should eql(2)
|
97
|
+
series.first[:data].first.to_i.should eql(2)
|
96
98
|
series.first[:name].should eql("Event 1")
|
97
99
|
end
|
98
100
|
|
data/spec/high_chart_spec.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
require "high_chart"
|
3
|
+
require "hash_extensions"
|
3
4
|
|
4
5
|
describe HighChart do
|
5
6
|
before(:each) do
|
6
7
|
@series = [{:name => "series1", :data => [0]}, {:name => "series2", :data => [1]}]
|
7
8
|
@x_labels = ["label1", "label2"]
|
8
9
|
@y_title = "a title"
|
9
|
-
@chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
10
|
+
@chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title"})
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should read some defaults from a config file" do
|
13
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
14
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title", :config_file => File.dirname(__FILE__) + "/assets/high_chart_defaults.yml"})
|
14
15
|
chart.legend.should == {"enabled" => true, "layout" => "vertical"}
|
15
16
|
end
|
16
17
|
|
@@ -19,12 +20,12 @@ describe HighChart do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
it "should merge options from the hash passed in with the values in the config file" do
|
22
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :legend => {:enabled => false}, :config_file => File.dirname(__FILE__) + "
|
23
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :legend => {:enabled => false}, :config_file => File.dirname(__FILE__) + "/assets/high_chart_defaults.yml"})
|
23
24
|
chart.legend.should == {"enabled" => false, "layout" => "vertical"}
|
24
25
|
end
|
25
26
|
|
26
27
|
it "should set instance variables from the options hash" do
|
27
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
28
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title", :legend => {:enabled => false}, :config_file => File.dirname(__FILE__) + "/assets/high_chart_defaults.yml"})
|
28
29
|
chart.title.should == {"text" => "chart title"}
|
29
30
|
end
|
30
31
|
|
@@ -33,7 +34,7 @@ describe HighChart do
|
|
33
34
|
end
|
34
35
|
|
35
36
|
it "should return a colors hash" do
|
36
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
37
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title", :colors => ["red", "green", "blue"]})
|
37
38
|
chart.colors.should == ["red", "green", "blue"]
|
38
39
|
end
|
39
40
|
|
@@ -46,35 +47,34 @@ describe HighChart do
|
|
46
47
|
end
|
47
48
|
|
48
49
|
it "should return an xAxis hash" do
|
49
|
-
@chart.x_axis.should ==
|
50
|
+
@chart.x_axis["categories"].should == ["label1", "label2"]
|
50
51
|
end
|
51
52
|
|
52
|
-
it "should return a yAxis
|
53
|
-
|
53
|
+
it "should return a yAxis array" do
|
54
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :y_axis => [{:opposite => true}, {:opposite => false}], :title => "chart title"})
|
55
|
+
chart.y_axis.should.kind_of?(Array)
|
56
|
+
chart.y_axis.size.should == 2
|
57
|
+
chart.y_axis[0][:opposite].should == true
|
58
|
+
chart.y_axis[1][:opposite].should == false
|
54
59
|
end
|
55
60
|
|
56
61
|
it "should fail if no x_axis_labels are provided" do
|
57
62
|
lambda {HighChart.new(@series)}.should raise_error(HighChartError)
|
58
63
|
end
|
59
64
|
|
60
|
-
it "should output JSON without null entries" do
|
61
|
-
@chart.to_json.should_not match(/null/)
|
62
|
-
end
|
63
|
-
|
64
65
|
it "should read colors from a config file" do
|
65
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
66
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title", :config_file => File.dirname(__FILE__) + "/assets/high_chart_defaults.yml"})
|
66
67
|
chart.colors.should == ['#FFFFFF', '#000000']
|
67
68
|
end
|
68
69
|
|
69
70
|
it "should merge default chart options from a config file" do
|
70
|
-
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :
|
71
|
+
chart = HighChart.new(@series, {:x_axis_labels => @x_labels, :title => "chart title", :config_file => File.dirname(__FILE__) + "/assets/high_chart_defaults.yml"})
|
71
72
|
chart.chart.should == {"defaultSeriesType"=>"bar", "renderTo"=>"high-chart-container", "plotBackgroundColor" => "#000000"}
|
72
73
|
end
|
73
74
|
|
74
75
|
it "should raise an error if series is not an array" do
|
75
76
|
series = {:name => "series1", :data => [0]}
|
76
77
|
x_labels = ["label1", "label2"]
|
77
|
-
|
78
|
-
lambda {HighChart.new(series, {:x_axis_labels => x_labels, :y_axis_title => y_title, :title => "chart title"})}.should raise_error(HighChartError)
|
78
|
+
lambda {HighChart.new(series, {:x_axis_labels => x_labels, :title => "chart title"})}.should raise_error(HighChartError)
|
79
79
|
end
|
80
|
-
end
|
80
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pie-high
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeff Sutherland
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-31 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,22 @@ dependencies:
|
|
50
50
|
version: 1.6.1
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: json_pure
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 1
|
62
|
+
segments:
|
63
|
+
- 1
|
64
|
+
- 1
|
65
|
+
- 9
|
66
|
+
version: 1.1.9
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
53
69
|
description: |-
|
54
70
|
High Charts is one of the best JavaScript charting libraries there is. Here is a straight-forward
|
55
71
|
Ruby API to harness all the power High Charts has to offer. Includes support for Ruport pivot tables.
|
@@ -68,9 +84,11 @@ files:
|
|
68
84
|
- README.rdoc
|
69
85
|
- Rakefile
|
70
86
|
- VERSION
|
87
|
+
- lib/hash_extensions.rb
|
71
88
|
- lib/high_chart.rb
|
72
89
|
- lib/high_chart_series.rb
|
73
90
|
- pie-high.gemspec
|
91
|
+
- spec/assets/high_chart_defaults.yml
|
74
92
|
- spec/high_chart_series_spec.rb
|
75
93
|
- spec/high_chart_spec.rb
|
76
94
|
- spec/spec.opts
|