lazy_high_charts 1.0.9 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
+ Mar 20,2011
2
+ * be compatible to rails 2.3
3
+ * dump to 1.1.1
4
+ * Rename options[:x_axis] and options[:y_axis] to options[:xAxis] and options[:yAxis], and options[:plot_options] to options[:plotOptions] to make it consistent with highcharts.
5
+
1
6
  Mar 19,2011
2
7
  * refactor my gem code,dumped to 1.0.9
8
+ * fix activeview load expansion tag
3
9
 
4
10
  Nov 30,2010
5
11
  * dumped to gem 0.0.1
@@ -10,7 +16,6 @@
10
16
  Sep 14,2010
11
17
  * update codebase to support rails3.0 and rspec2
12
18
 
13
-
14
19
  Oct 8,2010
15
20
  * update rake.it works now!
16
21
 
data/README.md CHANGED
@@ -1,13 +1,24 @@
1
1
  LazyHighCharts
2
2
  =======
3
- LazyHighCharts is Rails 3.x Gem for displaying Highcharts graphs.
3
+ LazyHighCharts is Rails 2.x/3.x Gem for displaying Highcharts graphs.
4
4
 
5
5
  Compatibility:
6
- lazy_high_charts 1.x is only compatible with Rails 3.x
6
+ lazy_high_charts 1.x is compatible with Rails 2.x/3.x
7
7
 
8
- Current Version: 1.0.9
9
8
  Usage
10
9
  =======
10
+ About javascript Assets notes:
11
+ for Rails 2.x
12
+ 1.you need manually put jquery/highcharts js to public/javascript
13
+ 2.modify your layout html
14
+ Sample Code:
15
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
16
+ <%= javascript_include_tag :high_charts %>
17
+ 3. add gem name in your config/environment.rb
18
+ config.gem "lazy_high_charts"
19
+ 4.done!
20
+
21
+ For Rails 3.x
11
22
  In your Gemfile, add this line:
12
23
  gem 'lazy_high_charts'
13
24
 
@@ -40,10 +51,7 @@ Usage
40
51
 
41
52
  Usage in layout:
42
53
 
43
- <%= javascript_include_tag 'highcharts' %>
44
- <!--[if IE]>
45
- <%= javascript_include_tag 'excanvas.compiled' %>
46
- <![endif]-->
54
+ <%= javascript_include_tag :high_charts %>
47
55
 
48
56
  Usage in view:
49
57
 
@@ -51,7 +59,7 @@ Usage
51
59
 
52
60
  Passing formatting options in the view to the helper block , because all the helper options declared in the controller are converted in strict/valid json (quoted key); so we need to extend the json object with some js.
53
61
 
54
- <% high_chart("my_id", @h) do |c| %>
62
+ <%= high_chart("my_id", @h) do |c| %>
55
63
  <%= "options.tooltip.formatter = function() { return '<b>HEY!!!'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +' units';}" %>
56
64
  <%= "options.xAxis.labels.formatter = function() { return 'ho';}" %>
57
65
  <%= "options.yAxis.labels.formatter = function() { return 'hey';}" %>
data/init.rb CHANGED
@@ -1,6 +1,6 @@
1
- # coding: utf-8
2
- require 'LazyHighCharts'
3
- require 'LazyHighCharts/high_charts_helper'
4
- ActionView::Helpers::AssetTagHelper.register_javascript_expansion :high_charts => ["highcharts"]
5
- ActionView::Base.send :include, LazyHighCharts::LayoutHelper
1
+ # encoding: utf-8
2
+ require 'lazy_high_charts'
3
+ require 'lazy_high_charts/layout_helper'
6
4
 
5
+ ActionView::Helpers::AssetTagHelper.register_javascript_expansion :high_charts => ["highcharts"]
6
+ ActionView::Base.send :include, LazyHighCharts::LayoutHelper
@@ -1,8 +1,7 @@
1
- require 'lazy_high_charts/high_chart'
2
- require 'lazy_high_charts/layout_helper.rb'
3
-
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])
4
3
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts railtie]) if defined?(::Rails::Railtie)
5
4
 
6
5
  module LazyHighCharts
7
- # Your code goes here...
6
+
8
7
  end
@@ -9,7 +9,6 @@ module LazyHighCharts
9
9
 
10
10
  def initialize(canvas = nil, html_opts = {})
11
11
 
12
- @collection_filter = nil
13
12
  self.tap do |high_chart|
14
13
  high_chart.data ||= []
15
14
  high_chart.options ||= {}
@@ -26,17 +25,17 @@ module LazyHighCharts
26
25
  self.title({ :text=>"example test title from highcharts gem"})
27
26
  self.legend({:layout=>"vertical", :style=>{:position=>'absolute', :bottom=>'auto', :left=>'150px', :top=>'150px'} , :borderWidth=> 1,
28
27
  :backgroundColor=>'#FFFFFF'})
29
- self.x_axis(
28
+ self.xAxis(
30
29
  {:categories=> ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
31
30
  :plotBands=> [{
32
31
  :from=> 6.0,:to=> 6.5,:color=> 'rgba(68, 170, 213, .2)'
33
32
  }],
34
33
  :labels=>{ :align=>'right',:rotation=>45 }
35
34
  })
36
- self.y_axis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} })
35
+ self.yAxis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} })
37
36
  self.tooltip({ :enabled=>true })
38
37
  self.credits({:enabled => false})
39
- self.plot_options({
38
+ self.plotOptions({
40
39
  :areaspline => {
41
40
  :fillOpacity => 0.5
42
41
  }
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ require 'rails' unless defined? ::Rails
2
3
 
3
4
  module LazyHighCharts
4
5
  module LayoutHelper
@@ -11,41 +12,40 @@ module LazyHighCharts
11
12
  end
12
13
  end
13
14
 
14
- def high_graph(placeholder, object, &block)
15
- @options = {
16
- "chart" => object.options[:chart],
17
- "title" => object.options[:title],
18
- "legend" => object.options[:legend],
19
- "xAxis" => object.options[:xAxis],
20
- "yAxis" => object.options[:yAxis],
21
- "credits" => object.options[:credits],
22
- "plotOptions" => object.options[:plotOptions],
23
- "series" => object.options[:series],
24
- "subtitle" => object.options[:subtitle]
25
- }.reject{|k,v| v.nil?}
26
-
27
- graph =<<-EOJS
28
- <script type="text/javascript">
29
- jQuery(function() {
30
- var options = { #{format_options} };
31
- #{capture(&block) if block_given?}
32
- var chart = new Highcharts.Chart(options);
33
- });
34
- </script>
35
- EOJS
36
15
 
16
+ def high_graph(placeholder, object, &block)
17
+ graph =<<-EOJS
18
+ <script type="text/javascript">
19
+ jQuery(function() {
20
+ // 1. Define JSON options
21
+ var options = {
22
+ chart: #{object.options[:chart].to_json},
23
+ title: #{object.options[:title].to_json},
24
+ legend: #{object.options[:legend].to_json},
25
+ xAxis: #{object.options[:xAxis].to_json},
26
+ yAxis: #{object.options[:yAxis].to_json},
27
+ tooltip: #{object.options[:tooltip].to_json},
28
+ credits: #{object.options[:credits].to_json},
29
+ plotOptions: #{object.options[:plotOptions].to_json},
30
+ series: #{object.data.to_json},
31
+ subtitle: #{object.options[:subtitle].to_json}
32
+ };
33
+
34
+ // 2. Add callbacks (non-JSON compliant)
35
+ #{capture(&block) if block_given?}
36
+ // 3. Build the chart
37
+ var chart = new Highcharts.Chart(options);
38
+ });
39
+ </script>
40
+ EOJS
41
+
42
+ if defined?(raw) && ::Rails.version >= '3.0'
37
43
  return raw(graph)
38
-
39
- end
40
-
41
- def format_options
42
- options = []
43
- @options.each do |k,v|
44
- options << "#{k}: #{v.to_json}"
45
- end
46
- options << "tooltip:{}"
47
- options.join(', ')
44
+ else
45
+ return graph unless block_given?
46
+ concat graph
48
47
  end
48
+ end
49
49
 
50
50
  end
51
51
  end
@@ -1,12 +1,19 @@
1
- # encoding: utf-8
1
+ require 'lazy_high_charts'
2
+ require 'lazy_high_charts/layout_helper'
3
+ require 'rails'
2
4
 
3
5
  module LazyHighCharts
4
- # @private
5
- class Railtie < Rails::Railtie
6
- initializer 'lazy_high_charts.initialize' do
7
- ActiveSupport.on_load(:action_view) do
8
- include LazyHighCharts::LayoutHelper
6
+
7
+ class Railtie < ::Rails::Railtie
8
+ config.before_configuration do
9
+ config.action_view.javascript_expansions[:high_charts] = %w(highcharts)
10
+ end
11
+
12
+ initializer 'lazy_high_charts.initialize' do
13
+ ActiveSupport.on_load(:action_view) do
14
+ include LazyHighCharts::LayoutHelper
15
+ end
9
16
  end
10
17
  end
11
- end
12
- end
18
+
19
+ end
@@ -1,3 +1,3 @@
1
1
  module LazyHighCharts
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.1"
3
3
  end
data/rails/init.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  # encoding: utf-8
2
- require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
2
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
@@ -32,7 +32,7 @@ describe "HighChart" do
32
32
  LazyHighCharts::HighChart.new.options.should == {
33
33
  :subtitle=>{},
34
34
  :chart=>{:renderTo=>nil, :defaultSeriesType=>"areaspline"},
35
- :plot_options=>{:areaspline=>{:fillOpacity=>0.5}},
35
+ :plotOptions=>{:areaspline=>{:fillOpacity=>0.5}},
36
36
  :legend=>{
37
37
  :borderWidth=>1,
38
38
  :backgroundColor=>"#FFFFFF",
@@ -41,11 +41,11 @@ describe "HighChart" do
41
41
  :left=>"150px", :position=>"absolute", :bottom=>"auto"}
42
42
  },
43
43
  :tooltip=>{:enabled=>true},
44
- :x_axis=>{
44
+ :xAxis=>{
45
45
  :categories=>["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
46
46
  :plotBands=>[{:to=>6.5, :from=>6.0, :color=>"rgba(68, 170, 213, .2)"}],
47
47
  :labels=>{:align=>"right", :rotation=>45}},
48
- :y_axis=>{:title=>{:text=>"Fruit units"},
48
+ :yAxis=>{:title=>{:text=>"Fruit units"},
49
49
  :labels=>{:align=>"right"}},
50
50
  :title=>{:text=>"example test title from highcharts gem"},
51
51
  :credits=>{:enabled=>false}
@@ -76,11 +76,11 @@ describe "HighChart" do
76
76
  f.options[:chart][:defaultSeriesType] = "area"
77
77
  f.options[:chart][:inverted] = true
78
78
  f.options[:legend][:layout] = "horizontal"
79
- f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
79
+ f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
80
80
  end
81
81
  chart.data.should == [{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
82
82
  chart.options[:legend][:layout].should == "horizontal"
83
- chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
83
+ chart.options[:xAxis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
84
84
  chart.options[:chart][:defaultSeriesType].should == "area"
85
85
  chart.options[:chart][:inverted].should == true
86
86
  end
@@ -91,12 +91,12 @@ describe "HighChart" do
91
91
  f.series(:name=>'Jane', :data=>[1, 3] )
92
92
  f.title({ :text=>"example test title from controller"})
93
93
  # without overriding
94
- f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
94
+ f.xAxis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
95
95
  f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
96
96
  end
97
- chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
98
- chart.options[:x_axis][:labels][:rotation].should == -45
99
- chart.options[:x_axis][:labels][:align].should == "right"
97
+ chart.options[:xAxis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
98
+ chart.options[:xAxis][:labels][:rotation].should == -45
99
+ chart.options[:xAxis][:labels][:align].should == "right"
100
100
  chart.options[:chart][:defaultSeriesType].should == "spline"
101
101
  chart.options[:chart][:renderTo].should == "myRenderArea"
102
102
  chart.options[:chart][:inverted].should == true
@@ -117,4 +117,4 @@ describe "HighChart" do
117
117
 
118
118
  end
119
119
 
120
- end
120
+ end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ require 'active_support'
7
7
  require 'action_pack'
8
8
  require 'action_view'
9
9
  require 'action_controller'
10
+ require 'rails'
10
11
  #require 'action_mailer'
11
12
 
12
13
  require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts'))
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.0.9
5
+ version: 1.1.1
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-03-19 00:00:00 +08:00
14
+ date: 2011-03-20 00:00:00 +08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency