lazy_high_charts 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +7 -9
- data/README.md +22 -2
- data/init.rb +2 -3
- data/lazy_high_charts.gemspec +0 -1
- data/lib/generators/lazy_high_charts/install/install_generator.rb +3 -3
- data/lib/lazy_high_charts.rb +1 -1
- data/lib/lazy_high_charts/high_chart.rb +18 -28
- data/lib/lazy_high_charts/layout_helper.rb +74 -39
- data/lib/lazy_high_charts/railtie.rb +3 -2
- data/lib/lazy_high_charts/version.rb +1 -1
- data/spec/high_chart_spec.rb +13 -24
- data/spec/lazy_high_charts_spec.rb +6 -2
- metadata +3 -3
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
* refactor my gem code,dumped to 1.0.9
|
8
|
-
* fix activeview load expansion tag
|
1
|
+
* Jul 13, 2011
|
2
|
+
HighStock support
|
3
|
+
remove some defaults
|
4
|
+
|
5
|
+
Jan 31, 2011
|
6
|
+
* backwards compatibility for rails 2.3.x in rendering callbacks options
|
9
7
|
|
10
8
|
Nov 30,2010
|
11
9
|
* dumped to gem 0.0.1
|
12
|
-
|
10
|
+
|
13
11
|
Sep 13,2010
|
14
12
|
* truely support rails 3.0(returning is deprecate function,use tap) deshi(xiaods@gmail.com)
|
15
13
|
|
data/README.md
CHANGED
@@ -5,6 +5,16 @@ LazyHighCharts is Rails 2.x/3.x Gem for displaying Highcharts graphs.
|
|
5
5
|
Compatibility:
|
6
6
|
lazy_high_charts 1.x is compatible with Rails 2.x/3.x
|
7
7
|
|
8
|
+
=======
|
9
|
+
### plugin support for rails 2.3.5 and rails 3
|
10
|
+
|
11
|
+
script/plugin install git://github.com/michelson/lazy_high_charts.git ##(for rails 2)
|
12
|
+
|
13
|
+
rails plugin install git://github.com/michelson/lazy_high_charts.git ##(for rails 3)
|
14
|
+
|
15
|
+
#HighStocks
|
16
|
+
LazyHighCharts now compatible with beta HighStock, http://www.highcharts.com/stock/demo/
|
17
|
+
|
8
18
|
Usage
|
9
19
|
=======
|
10
20
|
About javascript Assets notes:
|
@@ -37,7 +47,7 @@ Usage
|
|
37
47
|
f.options[:chart][:defaultSeriesType] = "area"
|
38
48
|
f.options[:chart][:inverted] = true
|
39
49
|
f.options[:legend][:layout] = "horizontal"
|
40
|
-
f.options[:
|
50
|
+
f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
|
41
51
|
......
|
42
52
|
|
43
53
|
Overriding entire option:
|
@@ -67,11 +77,21 @@ Usage
|
|
67
77
|
|
68
78
|
|
69
79
|
|
80
|
+
|
81
|
+
HighStock Support:
|
82
|
+
|
83
|
+
##just call HighChart Helper this way:
|
84
|
+
|
85
|
+
<%= high_stock("my_id", @h) %>
|
86
|
+
|
87
|
+
|
70
88
|
Option reference:
|
71
89
|
|
72
90
|
http://www.highcharts.com/ref/
|
73
91
|
|
74
|
-
|
92
|
+
HighCharts License:
|
93
|
+
|
94
|
+
http://www.highcharts.com/license
|
75
95
|
|
76
96
|
|
77
97
|
Contributors
|
data/init.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
require 'lazy_high_charts'
|
3
3
|
require 'lazy_high_charts/layout_helper'
|
4
|
-
|
5
4
|
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :high_charts => ["highcharts"]
|
6
|
-
ActionView::Base.send :include, LazyHighCharts::LayoutHelper
|
5
|
+
ActionView::Base.send :include, LazyHighCharts::LayoutHelper
|
data/lazy_high_charts.gemspec
CHANGED
@@ -2,9 +2,9 @@ module LazyHighCharts
|
|
2
2
|
class InstallGenerator < Rails::Generators::Base
|
3
3
|
desc "This generator install highcharts javascripts"
|
4
4
|
|
5
|
-
def install_highcharts
|
6
|
-
say_status("installing", "Highcharts javascript (github
|
7
|
-
get "https://github.com/highslide-software/highcharts.com/
|
5
|
+
def install_highcharts(opts = nil)
|
6
|
+
say_status("installing", "Highcharts javascript (github STOCK branch)", :green)
|
7
|
+
get "https://raw.github.com/highslide-software/highcharts.com/stock/js/highcharts.src.js","public/javascripts/highcharts.js"
|
8
8
|
rescue OpenURI::HTTPError
|
9
9
|
say_status("warning", "could not find Highcharts javascript file", :yellow)
|
10
10
|
end
|
data/lib/lazy_high_charts.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart])
|
2
|
-
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts layout_helper])
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts layout_helper])
|
3
3
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts railtie]) if defined?(::Rails::Railtie)
|
4
4
|
|
5
5
|
module LazyHighCharts
|
@@ -6,41 +6,30 @@ module LazyHighCharts
|
|
6
6
|
alias :canvas :placeholder
|
7
7
|
alias :canvas= :placeholder=
|
8
8
|
|
9
|
+
def initialize(canvas = nil, html_opts = {})
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
yield high_chart if block_given?
|
19
|
-
end
|
11
|
+
@collection_filter = nil
|
12
|
+
self.tap do |high_chart|
|
13
|
+
high_chart.data ||= []
|
14
|
+
high_chart.options ||= {}
|
15
|
+
high_chart.defaults_options
|
16
|
+
high_chart.html_options = html_opts.reverse_merge(CANVAS_DEFAULT_HTML_OPTIONS)
|
17
|
+
high_chart.canvas = canvas if canvas
|
18
|
+
yield high_chart if block_given?
|
20
19
|
end
|
20
|
+
end
|
21
21
|
|
22
22
|
# title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
|
23
23
|
|
24
24
|
def defaults_options
|
25
25
|
self.title({ :text=>"example test title from highcharts gem"})
|
26
|
-
self.legend({:layout=>"vertical", :style=>{
|
27
|
-
|
28
|
-
self.
|
29
|
-
{:categories=> ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
30
|
-
:plotBands=> [{
|
31
|
-
:from=> 6.0,:to=> 6.5,:color=> 'rgba(68, 170, 213, .2)'
|
32
|
-
}],
|
33
|
-
:labels=>{ :align=>'right',:rotation=>45 }
|
34
|
-
})
|
35
|
-
self.yAxis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} })
|
26
|
+
self.legend({ :layout=>"vertical", :style=>{} })
|
27
|
+
self.x_axis({})
|
28
|
+
self.y_axis({ :title=> {:text=> nil}, :labels=>{} })
|
36
29
|
self.tooltip({ :enabled=>true })
|
37
|
-
self.credits({:enabled => false})
|
38
|
-
self.
|
39
|
-
|
40
|
-
:fillOpacity => 0.5
|
41
|
-
}
|
42
|
-
})
|
43
|
-
self.chart({:defaultSeriesType=>"areaspline" , :renderTo => nil})
|
30
|
+
self.credits({ :enabled => false})
|
31
|
+
self.plot_options({ :areaspline => { } })
|
32
|
+
self.chart({ :defaultSeriesType=>nil , :renderTo => nil})
|
44
33
|
self.subtitle({})
|
45
34
|
end
|
46
35
|
|
@@ -68,7 +57,8 @@ module LazyHighCharts
|
|
68
57
|
end
|
69
58
|
end
|
70
59
|
|
71
|
-
|
60
|
+
private
|
61
|
+
|
72
62
|
def series_options
|
73
63
|
@options.reject {|k,v| SERIES_OPTIONS.include?(k.to_s) == false}
|
74
64
|
end
|
@@ -1,51 +1,86 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
require 'rails' unless defined? ::Rails
|
3
|
-
|
4
2
|
module LazyHighCharts
|
5
3
|
module LayoutHelper
|
6
|
-
|
7
|
-
def high_chart(placeholder, object, &block)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
4
|
+
|
5
|
+
def high_chart(placeholder, object , &block)
|
6
|
+
object.html_options.merge!({:id=>placeholder})
|
7
|
+
object.options[:chart][:renderTo] = placeholder
|
8
|
+
high_graph(placeholder,object , &block).concat(content_tag("div","", object.html_options))
|
9
|
+
end
|
10
|
+
|
11
|
+
def high_stock(placeholder, object , &block)
|
12
|
+
object.html_options.merge!({:id=>placeholder})
|
13
|
+
object.options[:chart][:renderTo] = placeholder
|
14
|
+
high_graph_stock(placeholder,object , &block).concat(content_tag("div","", object.html_options))
|
13
15
|
end
|
14
16
|
|
17
|
+
def high_graph(placeholder, object, &block)
|
18
|
+
graph =<<-EOJS
|
19
|
+
<script type="text/javascript">
|
20
|
+
jQuery(function() {
|
21
|
+
// 1. Define JSON options
|
22
|
+
var options = {
|
23
|
+
chart: #{object.options[:chart].to_json},
|
24
|
+
title: #{object.options[:title].to_json},
|
25
|
+
legend: #{object.options[:legend].to_json},
|
26
|
+
xAxis: #{object.options[:x_axis].to_json},
|
27
|
+
yAxis: #{object.options[:y_axis].to_json},
|
28
|
+
tooltip: #{object.options[:tooltip].to_json},
|
29
|
+
credits: #{object.options[:credits].to_json},
|
30
|
+
plotOptions: #{object.options[:plot_options].to_json},
|
31
|
+
series: #{object.data.to_json},
|
32
|
+
subtitle: #{object.options[:subtitle].to_json}
|
33
|
+
};
|
15
34
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
subtitle: #{object.options[:subtitle].to_json}
|
32
|
-
};
|
35
|
+
// 2. Add callbacks (non-JSON compliant)
|
36
|
+
#{capture(&block) if block_given?}
|
37
|
+
// 3. Build the chart
|
38
|
+
var chart = new Highcharts.Chart(options);
|
39
|
+
});
|
40
|
+
</script>
|
41
|
+
EOJS
|
42
|
+
|
43
|
+
if defined?(raw)
|
44
|
+
return raw(graph)
|
45
|
+
else
|
46
|
+
return graph
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
33
50
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
51
|
+
def high_graph_stock(placeholder, object, &block)
|
52
|
+
graph =<<-EOJS
|
53
|
+
<script type="text/javascript">
|
54
|
+
jQuery(function() {
|
55
|
+
// 1. Define JSON options
|
56
|
+
var options = {
|
57
|
+
chart: #{object.options[:chart].to_json},
|
58
|
+
title: #{object.options[:title].to_json},
|
59
|
+
legend: #{object.options[:legend].to_json},
|
60
|
+
xAxis: #{object.options[:x_axis].to_json},
|
61
|
+
yAxis: #{object.options[:y_axis].to_json},
|
62
|
+
tooltip: #{object.options[:tooltip].to_json},
|
63
|
+
credits: #{object.options[:credits].to_json},
|
64
|
+
plotOptions: #{object.options[:plot_options].to_json},
|
65
|
+
series: #{object.data.to_json},
|
66
|
+
subtitle: #{object.options[:subtitle].to_json}
|
67
|
+
};
|
41
68
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
69
|
+
// 2. Add callbacks (non-JSON compliant)
|
70
|
+
#{capture(&block) if block_given?}
|
71
|
+
// 3. Build the chart
|
72
|
+
var chart = new Highcharts.StockChart(options);
|
73
|
+
});
|
74
|
+
</script>
|
75
|
+
EOJS
|
76
|
+
|
77
|
+
if defined?(raw)
|
78
|
+
return raw(graph)
|
79
|
+
else
|
80
|
+
return graph
|
81
|
+
end
|
82
|
+
|
47
83
|
end
|
48
|
-
end
|
49
84
|
|
50
85
|
end
|
51
86
|
end
|
data/spec/high_chart_spec.rb
CHANGED
@@ -22,36 +22,25 @@ describe "HighChart" do
|
|
22
22
|
it "should take an optional 'placeholder' argument" do
|
23
23
|
LazyHighCharts::HighChart.new(@placeholder).placeholder.should == @placeholder
|
24
24
|
LazyHighCharts::HighChart.new.placeholder.should == nil
|
25
|
-
|
25
|
+
end
|
26
26
|
|
27
27
|
it "should take an optional html_options argument (defaulting to 300px height)" do
|
28
28
|
LazyHighCharts::HighChart.new(@html_options).placeholder.should == @html_options
|
29
|
-
|
29
|
+
end
|
30
30
|
|
31
31
|
it "should set options by default" do
|
32
32
|
LazyHighCharts::HighChart.new.options.should == {
|
33
|
-
:
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
:xAxis=>{
|
45
|
-
:categories=>["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
46
|
-
:plotBands=>[{:to=>6.5, :from=>6.0, :color=>"rgba(68, 170, 213, .2)"}],
|
47
|
-
:labels=>{:align=>"right", :rotation=>45}},
|
48
|
-
:yAxis=>{:title=>{:text=>"Fruit units"},
|
49
|
-
:labels=>{:align=>"right"}},
|
50
|
-
:title=>{:text=>"example test title from highcharts gem"},
|
51
|
-
:credits=>{:enabled=>false}
|
52
|
-
}
|
53
|
-
|
54
|
-
end
|
33
|
+
:plot_options=>{:areaspline=>{}},
|
34
|
+
:x_axis=>{},
|
35
|
+
:chart=>{:defaultSeriesType=>nil, :renderTo=>nil},
|
36
|
+
:y_axis=>{:title=>{:text=>nil},
|
37
|
+
:labels=>{}},
|
38
|
+
:title=>{:text=>"example test title from highcharts gem"},
|
39
|
+
:subtitle=>{},
|
40
|
+
:credits=>{:enabled=>false},
|
41
|
+
:legend=>{:layout=>"vertical", :style=>{}},
|
42
|
+
:tooltip=>{:enabled=>true}}
|
43
|
+
end
|
55
44
|
|
56
45
|
it "should set data empty by default" do
|
57
46
|
LazyHighCharts::HighChart.new.data.should == []
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
3
|
|
4
|
-
describe
|
4
|
+
describe HighChartsHelper do
|
5
5
|
include LazyHighCharts::LayoutHelper
|
6
6
|
|
7
7
|
before(:each) do
|
@@ -43,8 +43,12 @@ describe LazyHighCharts::LayoutHelper do
|
|
43
43
|
it "should set chart renderTo" do
|
44
44
|
high_chart(@placeholder, @chart).should match(/\"renderTo\":\"placeholder\"/)
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
it "should set Chart Stock" do
|
48
|
+
high_stock(@placeholder, @chart).should match(/var\s+chart\s+=\s+new\s+Highcharts.StockChart/)
|
49
|
+
end
|
47
50
|
end
|
51
|
+
|
48
52
|
end
|
49
53
|
|
50
54
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: lazy_high_charts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Miguel Michelson Martinez
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-07-14 00:00:00 +08:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
requirements: []
|
115
115
|
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 1.
|
117
|
+
rubygems_version: 1.6.2
|
118
118
|
signing_key:
|
119
119
|
specification_version: 3
|
120
120
|
summary: lazy higcharts plugin for rails
|