lazy_high_charts 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,8 +1,16 @@
1
+ * Aug 26, 2012
2
+ 1. Troy Anderson (laptop) <troy@tlainvestments.com>
3
+ Added ability to supply an array of axes or other objects and still use .js_code within the array of hashes.
4
+ 2. David Biehl <lazylodr@gmail.com>
5
+ removing the window.onload function for AJAX requests
6
+
1
7
  * Jun 27, 2012
2
- update assets path for rails 3.x
8
+ update assets path for rails 3.x
9
+
3
10
  * Jun 25, 2012
4
- support inline javascript in click event on ruby runtime.
5
- https://github.com/michelson/lazy_high_charts/issues/57
11
+ support inline javascript in click event on ruby runtime.
12
+ https://github.com/michelson/lazy_high_charts/issues/57
13
+
6
14
  * Jul 14, 2011
7
15
  add support rails 3.1 rc4 now
8
16
 
data/README.md CHANGED
@@ -5,7 +5,8 @@ Easily displaying Highcharts graphs with gem style.
5
5
 
6
6
  ## Notice
7
7
 
8
- lasted version: 1.1.7
8
+ lasted version: 1.2.0
9
+ Thanks for Troy & David
9
10
 
10
11
  ### Installation instructions for Rails 3
11
12
 
@@ -36,7 +37,7 @@ About javascript Assets notes:
36
37
  Sample Code:
37
38
  ````
38
39
  <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
39
- <%= javascript_include_tag :high_charts %>
40
+ <%= javascript_include_tag :highcharts %>
40
41
  ````
41
42
 
42
43
  3. add gem name in your config/environment.rb
@@ -45,17 +46,7 @@ config.gem "lazy_high_charts"
45
46
  ````
46
47
  4. Done!
47
48
 
48
- ### For Rails 3.1
49
- In your Gemfile, add this line:
50
- ````
51
- gem 'lazy_high_charts', '~> 1.1.5'
52
- ````
53
- then execuate command:
54
- ````
55
- Rails g lazy_high_charts:install
56
- ````
57
-
58
- ### Usage in Controller:
49
+ ### Demo Usage in Controller:
59
50
  ````
60
51
  @h = LazyHighCharts::HighChart.new('graph') do |f|
61
52
  f.options[:chart][:defaultSeriesType] = "area"
@@ -89,7 +80,7 @@ Overriding entire option:
89
80
 
90
81
  Usage in layout:
91
82
  ````
92
- <%= javascript_include_tag :high_charts %>
83
+ <%= javascript_include_tag :highcharts %>
93
84
  ````
94
85
 
95
86
  Usage in view:
@@ -1,6 +1,6 @@
1
1
  module LazyHighCharts
2
2
  class HighChart
3
- CANVAS_DEFAULT_HTML_OPTIONS = { :style => "height: 300px, width:615px" }
3
+ CANVAS_DEFAULT_HTML_OPTIONS = { :style => "height: 300px; width:615px" }
4
4
  SERIES_OPTIONS = %w(lines points bars shadowSize colors)
5
5
 
6
6
  attr_accessor :data, :options, :placeholder, :html_options
@@ -27,22 +27,37 @@ module LazyHighCharts
27
27
  options_collection = [ generate_json_from_hash(object.options) ]
28
28
 
29
29
  options_collection << %|"series": #{object.data.to_json}|
30
-
31
- graph =<<-EOJS
32
- <script type="text/javascript">
33
- (function() {
34
- var onload = window.onload;
35
- window.onload = function(){
36
- if (typeof onload == "function") onload();
37
- var options, chart;
38
- options = { #{options_collection.join(',')} };
39
- #{capture(&block) if block_given?}
40
- chart = new Highcharts.#{type}(options);
41
- };
42
- })()
43
- </script>
30
+
31
+ core_js =<<-EOJS
32
+ var options, chart;
33
+ options = { #{options_collection.join(',')} };
34
+ #{capture(&block) if block_given?}
35
+ chart = new Highcharts.#{type}(options);
44
36
  EOJS
45
37
 
38
+ if defined?(request) && request.respond_to?(:xhr?) && request.xhr?
39
+ graph =<<-EOJS
40
+ <script type="text/javascript">
41
+ (function() {
42
+ #{core_js}
43
+ })()
44
+ </script>
45
+ EOJS
46
+ else
47
+ graph =<<-EOJS
48
+ <script type="text/javascript">
49
+ (function() {
50
+ var onload = window.onload;
51
+ window.onload = function(){
52
+ if (typeof onload == "function") onload();
53
+ #{core_js}
54
+ };
55
+ })()
56
+ </script>
57
+ EOJS
58
+ end
59
+
60
+
46
61
  if defined?(raw)
47
62
  return raw(graph)
48
63
  else
@@ -52,21 +67,29 @@ module LazyHighCharts
52
67
  end
53
68
 
54
69
  private
55
-
56
- def generate_json_from_hash hash
70
+
71
+ def generate_json_from_hash hash
57
72
  hash.each_pair.map do |key, value|
58
73
  k = key.to_s.camelize.gsub!(/\b\w/) { $&.downcase }
59
- if value.is_a? Hash
60
- %|"#{k}": { #{generate_json_from_hash(value)} }|
61
- else
62
- if value.respond_to?(:js_code) && value.js_code?
63
- %|"#{k}": #{value}|
64
- else
65
- %|"#{k}": #{value.to_json}|
66
- end
67
- end
74
+ %|"#{k}": #{generate_json_from_value value}|
68
75
  end.flatten.join(',')
69
76
  end
77
+
78
+ def generate_json_from_value value
79
+ if value.is_a? Hash
80
+ %|{ #{generate_json_from_hash value} }|
81
+ elsif value.is_a? Array
82
+ %|[ #{generate_json_from_array value} ]|
83
+ elsif value.respond_to?(:js_code) && value.js_code?
84
+ value
85
+ else
86
+ value.to_json
87
+ end
88
+ end
89
+
90
+ def generate_json_from_array array
91
+ array.map{|value| generate_json_from_value(value)}.join(",")
92
+ end
70
93
 
71
94
  end
72
95
  end
@@ -1,3 +1,3 @@
1
1
  module LazyHighCharts
2
- VERSION = "1.1.7"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -102,4 +102,17 @@ describe HighChartsHelper do
102
102
  high_chart(@placeholder, chart).should match(/barFoo/)
103
103
  end
104
104
 
105
+ # issue #62 .js_code setting ignored
106
+ # https://github.com/michelson/lazy_high_charts/issues/62
107
+ it "should allow js code in array && nest attributs" do
108
+ chart = LazyHighCharts::HighChart.new {|f|
109
+ f.yAxis([{
110
+ :labels => {
111
+ :formatter => %|function() {return this.value + ' W';}|.js_code
112
+ }
113
+ }])
114
+ }
115
+ high_chart(@placeholder,chart).should match(/"formatter": function\(\) {return this.value \+ ' W';}/)
116
+ end
117
+
105
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lazy_high_charts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-27 00:00:00.000000000 Z
13
+ date: 2012-08-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -89,4 +89,3 @@ signing_key:
89
89
  specification_version: 3
90
90
  summary: lazy higcharts gem for rails
91
91
  test_files: []
92
- has_rdoc: