lazy_high_charts 1.5.4 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c28742599a93e17c58897651cec1e87dbb69f473
4
- data.tar.gz: 04d1a0564b935ba4b55f32cd921eda9cf61a09e7
3
+ metadata.gz: f5bbd30727f041d725287ddc99426ca728f86c1f
4
+ data.tar.gz: f352a46256674acb86897ea76e04033a5d2fa035
5
5
  SHA512:
6
- metadata.gz: 14023de4da68ab6b5ed3b770c648e9c95244922609b24b732bf4bfc9beaf0892c749436226c652a890e7e16dfd0c73acf7223daf3f80b8ce50965dc21f55ad92
7
- data.tar.gz: 65c5e078d571d344f15f9d69da69659dc9aee691382e97dd2943d821e202b67a85d4a1aeef46db35b20e67ebe4a82d83c91bb9c03ef65cd77c7cbbff4a147ec7
6
+ metadata.gz: b1b2c1ef228afe7aef43fff3839f1edf99d11b4a07f9f7876e67367270b4d4169ed79d543ba1923caa2842dabb53a498b4e5e47a40e104fec68c013226ac0ee1
7
+ data.tar.gz: d446f3a1b9dcb9414210ebb9dbbde9605bde6d46774051d850f23f4e5288b94894349a55786c00ce307ffa7fc4aed0d7eb357885ef76b2f3eeda53fd4fd6c040
@@ -1,3 +1,9 @@
1
+ # VERSION 1.5.5
2
+ * Mon Oct 19, 2015
3
+ 1. Support for HighChart global settings.
4
+ [#149](https://github.com/michelson/lazy_high_charts/issues/149)
5
+ 2. Minor code refactorings.
6
+
1
7
  # VERSION 1.5.4
2
8
  * Fri May 21
3
9
  1. Include ActionView::Helpers::TagHelper to the layout helper to avoid method conflict in object.
@@ -5,14 +11,14 @@
5
11
  # VERSION 1.5.3
6
12
  * Fri Apr 18
7
13
  1. update HighChart js lib to latest.
8
-
14
+
9
15
  # VERSION 1.5.2
10
16
  * Sun Mar 11, 2014
11
17
  1. Merge some requirement tweaks to use gem in NON-Rails contexts
12
18
 
13
19
  # VERSION 1.5.1
14
20
  * Sun Dec 22, 2013
15
- 1. Share highcharts:update rake task for gem and rails host app
21
+ 1. Share highcharts:update rake task for gem and rails host app
16
22
 
17
23
  # VERSION 1.5.0
18
24
  * Sun Jul 21, 2013
@@ -1 +1 @@
1
- 1.5.4
1
+ 1.5.5
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
 
6
6
  group :test, :development do # This causes the plugins to NOT load
7
7
  gem 'webrat', '~> 0.7'
8
- gem 'rspec', '~> 2.0'
8
+ gem 'rspec', '~> 3.4'
9
9
  gem 'rails', '>= 3.2'
10
10
  gem 'guard-rspec'
11
11
  gem 'rb-fsevent', '~> 0.9.1'
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # LazyHighCharts
2
2
 
3
+ [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/michelson/lazy_high_charts?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
3
5
  This gem provides a simple and extremely flexible way to use HighCharts from ruby code.
4
6
  Tested on Ruby on Rails, Sinatra and Nanoc, but it should work with others too.
5
7
 
@@ -40,6 +42,19 @@ then run
40
42
  bundle install
41
43
  ```
42
44
 
45
+ and add this in the application.js
46
+
47
+ ```js
48
+ //= require jquery
49
+ //= require jquery_ujs
50
+ //= require_tree .
51
+ //= require turbolinks
52
+
53
+ //= require highcharts/highcharts
54
+ //= require highcharts/highcharts-more
55
+ //= require highcharts/highstock
56
+ ```
57
+
43
58
  to install it.
44
59
 
45
60
  ## Usage:
@@ -47,26 +62,48 @@ to install it.
47
62
  ### Controller code:
48
63
  ```ruby
49
64
  @chart = LazyHighCharts::HighChart.new('graph') do |f|
50
- f.title(:text => "Population vs GDP For 5 Big Countries [2009]")
51
- f.xAxis(:categories => ["United States", "Japan", "China", "Germany", "France"])
52
- f.series(:name => "GDP in Billions", :yAxis => 0, :data => [14119, 5068, 4985, 3339, 2656])
53
- f.series(:name => "Population in Millions", :yAxis => 1, :data => [310, 127, 1340, 81, 65])
65
+ f.title(text: "Population vs GDP For 5 Big Countries [2009]")
66
+ f.xAxis(categories: ["United States", "Japan", "China", "Germany", "France"])
67
+ f.series(name: "GDP in Billions", yAxis: 0, data: [14119, 5068, 4985, 3339, 2656])
68
+ f.series(name: "Population in Millions", yAxis: 1, data: [310, 127, 1340, 81, 65])
54
69
 
55
70
  f.yAxis [
56
- {:title => {:text => "GDP in Billions", :margin => 70} },
57
- {:title => {:text => "Population in Millions"}, :opposite => true},
71
+ {title: {text: "GDP in Billions", margin: 70} },
72
+ {title: {text: "Population in Millions"}, opposite: true},
58
73
  ]
59
74
 
60
- f.legend(:align => 'right', :verticalAlign => 'top', :y => 75, :x => -50, :layout => 'vertical',)
61
- f.chart({:defaultSeriesType=>"column"})
75
+ f.legend(align: 'right', verticalAlign: 'top', y: 75, x: -50, layout: 'vertical')
76
+ f.chart({defaultSeriesType: "column"})
77
+ end
78
+
79
+ @chart_globals = LazyHighCharts::HighChartGlobals.new do |f|
80
+ f.global(useUTC: false)
81
+ f.chart(
82
+ backgroundColor: {
83
+ linearGradient: [0, 0, 500, 500],
84
+ stops: [
85
+ [0, "rgb(255, 255, 255)"],
86
+ [1, "rgb(240, 240, 255)"]
87
+ ]
88
+ },
89
+ borderWidth: 2,
90
+ plotBackgroundColor: "rgba(255, 255, 255, .9)",
91
+ plotShadow: true,
92
+ plotBorderWidth: 1
93
+ )
94
+ f.lang(thousandsSep: ",")
95
+ f.colors(["#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"])
62
96
  end
63
97
  ```
64
98
 
65
99
  ### View Helpers:
66
100
  ```ruby
101
+ <%= high_chart_globals(@chart_globals) %>
67
102
  <%= high_chart("some_id", @chart) %>
68
103
  ```
69
104
 
105
+ `high_chart_globals` is optional. Use it to set the global options of all charts that are currently displayed on the page. More info [here](http://api.highcharts.com/highcharts#global).
106
+
70
107
  ###Demo projects:
71
108
 
72
109
  [Nanoc App](spec/dummy_nanoc/README.md)
@@ -76,7 +113,7 @@ end
76
113
  [Sinatra App](spec/dummy_sinatra/README.md)
77
114
 
78
115
 
79
- ### Update to latest js library. Aditional command line
116
+ ### Update to latest js library. Additional command line
80
117
 
81
118
  To update to the current highcharts.js directly from http://code.highcharts.com/", you can always run
82
119
 
@@ -97,7 +134,7 @@ We're open to any contribution. It has to be tested properly though.
97
134
  * Test your changes. We won't accept any untested contributions (except if they're not testable).
98
135
  * Create an [issue](https://github.com/michelson/lazy_high_charts/issues) with a link to your commits.
99
136
 
100
- Thanks for all [contributers](https://github.com/michelson/lazy_high_charts/contributors)
137
+ Thanks for all [contributors](https://github.com/michelson/lazy_high_charts/contributors)
101
138
 
102
139
  ## Maintainers
103
140
  * Deshi Xiao [github/xiaods](https://github.com/xiaods)
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.required_rubygems_version = ">= 1.3"
24
24
 
25
- s.add_dependency "bundler", ">= 1.0"
25
+ s.add_development_dependency "bundler", ">= 1.0"
26
26
  s.add_dependency "hash-deep-merge"
27
27
 
28
28
  s.description = <<-DESC
@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), *%w[lazy_high_charts core_ext string])
5
5
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts options_key_filter])
6
6
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts layout_helper])
7
7
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart])
8
+ require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart_globals])
8
9
  if defined?(::Rails::Railtie)
9
10
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts railtie])
10
11
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts engine]) if ::Rails.version.to_s >= '3.1'
@@ -34,7 +34,6 @@ module LazyHighCharts
34
34
  self.subtitle({})
35
35
  end
36
36
 
37
-
38
37
  # Pass other methods through to the javascript high_chart object.
39
38
  #
40
39
  # For instance: <tt>high_chart.grid(:color => "#699")</tt>
@@ -66,11 +65,13 @@ module LazyHighCharts
66
65
  #
67
66
  # @return [Hash] options JSON options hash
68
67
  def full_options
69
- options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(self.options))]
70
- options_collection << %|"series": [#{generate_json_from_array(self.data)}]|
71
- <<-EOJS
72
- { #{options_collection.join(', ')} }
73
- EOJS
68
+ options_collection_as_string self
69
+ end
70
+
71
+ def to_json
72
+ data = self.options.clone
73
+ data[:series] = self.series_data.clone
74
+ data
74
75
  end
75
76
 
76
77
  private
@@ -82,7 +83,7 @@ module LazyHighCharts
82
83
  end
83
84
 
84
85
  def series_options
85
- @options.reject { |k, v| SERIES_OPTIONS.include?(k.to_s) == false }
86
+ @options.reject { |k, _| SERIES_OPTIONS.include?(k.to_s) == false }
86
87
  end
87
88
 
88
89
  def merge_options(name, opts)
@@ -0,0 +1,29 @@
1
+ module LazyHighCharts
2
+ class HighChartGlobals
3
+ include LayoutHelper
4
+
5
+ attr_accessor :options
6
+
7
+ def initialize
8
+ self.tap do |chart_globals|
9
+ chart_globals.options ||= {}
10
+ yield chart_globals if block_given?
11
+ end
12
+ end
13
+
14
+ # Pass other methods through to the high_chart_globals object.
15
+ #
16
+ # For instance: <tt>high_chart_globals.global(:useUTC => false)</tt>
17
+ def method_missing(meth, opts = {})
18
+ if meth.to_s == 'to_ary'
19
+ super
20
+ end
21
+ merge_options meth, opts
22
+ end
23
+
24
+ def merge_options(name, opts)
25
+ @options.merge! name => opts
26
+ end
27
+
28
+ end
29
+ end
@@ -16,6 +16,10 @@ module LazyHighCharts
16
16
  high_graph_stock(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
17
17
  end
18
18
 
19
+ def high_chart_globals(object)
20
+ build_globals_html_output(object)
21
+ end
22
+
19
23
  def high_graph(placeholder, object, &block)
20
24
  build_html_output("Chart", placeholder, object, &block)
21
25
  end
@@ -24,59 +28,27 @@ module LazyHighCharts
24
28
  build_html_output("StockChart", placeholder, object, &block)
25
29
  end
26
30
 
27
- def build_html_output(type, placeholder, object, &block)
28
- options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
29
- options_collection << %|"series": [#{generate_json_from_array(object.series_data)}]|
31
+ private
30
32
 
33
+ def build_html_output(type, placeholder, object, &block)
31
34
  core_js =<<-EOJS
32
- var options = { #{options_collection.join(',')} };
35
+ var options = #{options_collection_as_string(object)};
33
36
  #{capture(&block) if block_given?}
34
37
  window.chart_#{placeholder.underscore} = new Highcharts.#{type}(options);
35
38
  EOJS
36
39
 
37
- if defined?(request) && request.respond_to?(:xhr?) && request.xhr?
38
- graph =<<-EOJS
39
- <script type="text/javascript">
40
- (function() {
41
- #{core_js}
42
- })()
43
- </script>
44
- EOJS
45
- elsif defined?(Turbolinks) && request.headers["X-XHR-Referer"]
46
- graph =<<-EOJS
47
- <script type="text/javascript">
48
- (function() {
49
- var f = function(){
50
- document.removeEventListener('page:load', f, true);
51
- #{core_js}
52
- };
53
- document.addEventListener('page:load', f, true);
54
- })()
55
- </script>
56
- EOJS
57
- else
58
- graph =<<-EOJS
59
- <script type="text/javascript">
60
- (function() {
61
- var onload = window.onload;
62
- window.onload = function(){
63
- if (typeof onload == "function") onload();
64
- #{core_js}
65
- };
66
- })()
67
- </script>
68
- EOJS
69
- end
40
+ encapsulate_js core_js
41
+ end
70
42
 
71
- if defined?(raw)
72
- return raw(graph)
73
- else
74
- return graph
75
- end
43
+ def build_globals_html_output(object)
44
+ options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
76
45
 
77
- end
46
+ core_js =<<-EOJS
47
+ Highcharts.setOptions({ #{options_collection.join(',')} });
48
+ EOJS
78
49
 
79
- private
50
+ encapsulate_js core_js
51
+ end
80
52
 
81
53
  def generate_json_from_hash hash
82
54
  hash.each_pair.map do |key, value|
@@ -101,6 +73,65 @@ module LazyHighCharts
101
73
  array.map { |value| generate_json_from_value(value) }.join(",")
102
74
  end
103
75
 
76
+ def request_is_xhr?
77
+ defined?(request) && request.respond_to?(:xhr?) && request.xhr?
78
+ end
79
+
80
+ def request_is_referrer?
81
+ defined?(request) && request.respond_to?(:headers) && request.headers["X-XHR-Referer"]
82
+ end
83
+
84
+ def options_collection_as_string object
85
+ options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
86
+ options_collection << %|"series": [#{generate_json_from_array(object.series_data)}]|
87
+ "{ #{options_collection.join(',')} }"
88
+ end
89
+
90
+ def encapsulate_js(core_js)
91
+ if request_is_xhr?
92
+ js_output = "#{js_start} #{core_js} #{js_end}"
93
+ elsif defined?(Turbolinks) && request_is_referrer?
94
+ js_output =<<-EOJS
95
+ #{js_start}
96
+ var f = function(){
97
+ document.removeEventListener('page:load', f, true);
98
+ #{core_js}
99
+ };
100
+ document.addEventListener('page:load', f, true);
101
+ #{js_end}
102
+ EOJS
103
+ else
104
+ js_output =<<-EOJS
105
+ #{js_start}
106
+ var onload = window.onload;
107
+ window.onload = function(){
108
+ if (typeof onload == "function") onload();
109
+ #{core_js}
110
+ };
111
+ #{js_end}
112
+ EOJS
113
+ end
114
+
115
+ if defined?(raw)
116
+ return raw(js_output)
117
+ else
118
+ return js_output
119
+ end
120
+ end
121
+
122
+ def js_start
123
+ <<-EOJS
124
+ <script type="text/javascript">
125
+ (function() {
126
+ EOJS
127
+ end
128
+
129
+ def js_end
130
+ <<-EOJS
131
+ })()
132
+ </script>
133
+ EOJS
134
+ end
104
135
  end
105
136
  end
106
137
 
@@ -1,39 +1,42 @@
1
- #
2
1
  # A way to filter certain keys of data provided to the LazyHighCharts#series method and the LazyHighCharts#options
3
2
  #
4
- # Add methods or keys to the FILTER_MAP hash to have them applied to the options in a series
5
- # In the FILTER_MAP, the hash keys are methods, and the values are arrays of the hash keys the filter should be
6
- # applied to
3
+ # Add keys and methods to the FILTER_MAP hash to have them applied to the options in a series
7
4
  #
8
5
  # Be careful that it is OK to filter the hash keys you specify for every key of the options or series hash
9
6
  #
10
7
  module LazyHighCharts
11
8
  module OptionsKeyFilter
12
- def self.milliseconds value
13
- value * 1000
14
- end
15
-
16
- def self.date_to_js_code date
17
- "Date.UTC(#{date.year}, #{date.month - 1}, #{date.day})".js_code
18
- end
9
+ FILTER_MAP = {
10
+ :pointInterval => [:milliseconds],
11
+ :pointStart => [:date_to_js_code]
12
+ }
19
13
 
20
- def self.filter options
21
- new_options = options.map do |k, v|
22
- if v.is_a? ::Hash
23
- v = filter v
24
- else
25
- FILTER_MAP.each_pair do |method, matchers|
26
- v = method.call(v) if matchers.include?(k)
14
+ class << self
15
+ def filter options
16
+ {}.tap do |hash|
17
+ options.each do |key, value|
18
+ if value.is_a?(::Hash)
19
+ hash[key] = filter(value)
20
+ else
21
+ hash[key] = value
22
+ methods = Array(FILTER_MAP[key])
23
+ methods.each do |method_name|
24
+ hash[key] = send(method_name, hash[key])
25
+ end
26
+ end
27
27
  end
28
28
  end
29
- [k, v]
30
29
  end
31
- Hash[new_options]
32
- end
33
30
 
34
- FILTER_MAP = {
35
- method(:milliseconds) => [:pointInterval],
36
- method(:date_to_js_code) => [:pointStart]
37
- }
31
+ private
32
+
33
+ def milliseconds value
34
+ value * 1_000
35
+ end
36
+
37
+ def date_to_js_code date
38
+ "Date.UTC(#{date.year}, #{date.month - 1}, #{date.day})".js_code
39
+ end
40
+ end
38
41
  end
39
- end
42
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "HighChartGlobals" do
4
+ before(:each) do
5
+ @chart_globals = LazyHighCharts::HighChartGlobals.new do |chart|
6
+ chart.global( useUTC: false )
7
+ chart.chart(
8
+ backgroundColor: {
9
+ linearGradient: [0, 0, 500, 500],
10
+ stops: [
11
+ [0, "rgb(255, 255, 255)"],
12
+ [1, "rgb(240, 240, 255)"]
13
+ ]
14
+ },
15
+ borderWidth: 2,
16
+ plotBackgroundColor: "rgba(255, 255, 255, .9)",
17
+ plotShadow: true,
18
+ plotBorderWidth: 1
19
+ )
20
+ chart.lang(
21
+ thousandsSep: ","
22
+ )
23
+ chart.colors([
24
+ "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"
25
+ ])
26
+ end
27
+ end
28
+
29
+ # this is almost all flotomatic stuff
30
+ describe "initialization" do
31
+
32
+ it "should set options hash by default" do
33
+ @chart_globals.options.is_a?(Hash).should == true
34
+ end
35
+
36
+ it "should take a block and set attributes" do
37
+ @chart_globals.options[:lang][:thousandsSep].should == ","
38
+ @chart_globals.options[:global][:useUTC].should == false
39
+ @chart_globals.options[:chart][:backgroundColor][:linearGradient].should == [0, 0, 500, 500]
40
+ end
41
+
42
+ it "should override options" do
43
+ chart = LazyHighCharts::HighChartGlobals.new
44
+ chart.global({ useUTC: true })
45
+ chart.options[:global][:useUTC].should == true
46
+ chart.global({ useUTC: false })
47
+ chart.options[:global][:useUTC].should == false
48
+ end
49
+
50
+ end
51
+ end
@@ -17,25 +17,25 @@ describe "HighChart" do
17
17
  # this is almost all flotomatic stuff
18
18
  describe "initialization" do
19
19
  it "should take an optional 'placeholder' argument" do
20
- LazyHighCharts::HighChart.new(@placeholder).placeholder.should == @placeholder
21
- LazyHighCharts::HighChart.new.placeholder.should_not == @placeholder
20
+ expect(LazyHighCharts::HighChart.new(@placeholder).placeholder).to eq(@placeholder)
21
+ expect(LazyHighCharts::HighChart.new.placeholder).not_to eq(@placeholder)
22
22
  end
23
23
 
24
24
  it "shouldn't generate a nil placeholder" do
25
- LazyHighCharts::HighChart.new.placeholder.should_not be_nil
25
+ expect(LazyHighCharts::HighChart.new.placeholder).not_to be_nil
26
26
  end
27
27
 
28
28
  it "should generate different placeholders for different charts" do
29
29
  a_different_placeholder = LazyHighCharts::HighChart.new.placeholder
30
- LazyHighCharts::HighChart.new.placeholder.should_not == a_different_placeholder
30
+ expect(LazyHighCharts::HighChart.new.placeholder).not_to eq(a_different_placeholder)
31
31
  end
32
32
 
33
33
  it "should take an optional html_options argument (defaulting to 300px height)" do
34
- LazyHighCharts::HighChart.new(@placeholder, @html_options).html_options.should == @html_options
34
+ expect(LazyHighCharts::HighChart.new(@placeholder, @html_options).html_options).to eq(@html_options)
35
35
  end
36
36
 
37
37
  it "should set options by default" do
38
- LazyHighCharts::HighChart.new.options.should == {
38
+ expect(LazyHighCharts::HighChart.new.options).to eq({
39
39
  :title => {:text => nil},
40
40
  :legend => {:layout => "vertical", :style => {}},
41
41
  :xAxis => {},
@@ -44,27 +44,27 @@ describe "HighChart" do
44
44
  :credits => {:enabled => false},
45
45
  :plotOptions => {:areaspline => {}},
46
46
  :chart => {:defaultSeriesType => "line", :renderTo => nil},
47
- :subtitle => {}}
47
+ :subtitle => {}})
48
48
  end
49
49
 
50
50
  it "should set data empty by default" do
51
- LazyHighCharts::HighChart.new.series_data.should == []
51
+ expect(LazyHighCharts::HighChart.new.series_data).to eq([])
52
52
  end
53
53
 
54
54
  it "should take a block setting attributes" do
55
55
  chart = LazyHighCharts::HighChart.new { |f| f.series_data = @data; f.options = @options }
56
- chart.series_data.should == @data
57
- chart.options.should == @options
56
+ expect(chart.series_data).to eq(@data)
57
+ expect(chart.options).to eq(@options)
58
58
  end
59
59
 
60
60
  it "should take a block setting attributes" do
61
61
  chart = LazyHighCharts::HighChart.new { |f| f.options[:legend][:layout] = "horizontal" }
62
- chart.options[:legend][:layout].should == "horizontal"
62
+ expect(chart.options[:legend][:layout]).to eq("horizontal")
63
63
  end
64
64
 
65
65
  it "should take a block setting attributes" do
66
66
  chart = LazyHighCharts::HighChart.new { |f| f.options[:range_selector] = {}; f.options[:range_selector][:selected] = 1 }
67
- chart.options[:range_selector][:selected].should == 1
67
+ expect(chart.options[:range_selector][:selected]).to eq(1)
68
68
  end
69
69
 
70
70
  it "should change a block data without overriding options" do
@@ -77,11 +77,11 @@ describe "HighChart" do
77
77
  f.options[:legend][:layout] = "horizontal"
78
78
  f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
79
79
  end
80
- chart.series_data.should == [{:name => "John", :data => [3, 20]}, {:name => "Jane", :data => [1, 3]}]
81
- chart.options[:legend][:layout].should == "horizontal"
82
- chart.options[:xAxis][:categories].should == ["uno", "dos", "tres", "cuatro"]
83
- chart.options[:chart][:defaultSeriesType].should == "area"
84
- chart.options[:chart][:inverted].should == true
80
+ expect(chart.series_data).to eq([{:name => "John", :data => [3, 20]}, {:name => "Jane", :data => [1, 3]}])
81
+ expect(chart.options[:legend][:layout]).to eq("horizontal")
82
+ expect(chart.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
83
+ expect(chart.options[:chart][:defaultSeriesType]).to eq("area")
84
+ expect(chart.options[:chart][:inverted]).to eq(true)
85
85
  end
86
86
 
87
87
  it "should change a block data with overriding entire options" do
@@ -93,12 +93,12 @@ describe "HighChart" do
93
93
  f.xAxis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
94
94
  f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
95
95
  end
96
- chart.options[:xAxis][:categories].should == ["uno", "dos", "tres", "cuatro"]
97
- chart.options[:xAxis][:labels][:rotation].should == -45
98
- chart.options[:xAxis][:labels][:align].should == "right"
99
- chart.options[:chart][:defaultSeriesType].should == "spline"
100
- chart.options[:chart][:renderTo].should == "myRenderArea"
101
- chart.options[:chart][:inverted].should == true
96
+ expect(chart.options[:xAxis][:categories]).to eq(["uno", "dos", "tres", "cuatro"])
97
+ expect(chart.options[:xAxis][:labels][:rotation]).to eq(-45)
98
+ expect(chart.options[:xAxis][:labels][:align]).to eq("right")
99
+ expect(chart.options[:chart][:defaultSeriesType]).to eq("spline")
100
+ expect(chart.options[:chart][:renderTo]).to eq("myRenderArea")
101
+ expect(chart.options[:chart][:inverted]).to eq(true)
102
102
  end
103
103
 
104
104
  it "should have subtitles" do
@@ -111,7 +111,7 @@ describe "HighChart" do
111
111
  f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
112
112
  f.subtitle({:text => "Bar"})
113
113
  end
114
- chart.options[:subtitle][:text].should == "Bar"
114
+ expect(chart.options[:subtitle][:text]).to eq("Bar")
115
115
  end
116
116
 
117
117
  it 'should override entire option by default when resetting it again' do
@@ -119,8 +119,8 @@ describe "HighChart" do
119
119
  f.xAxis(categories: [3, 5, 7])
120
120
  f.xAxis(title: {text: 'x title'})
121
121
  end
122
- chart.options[:xAxis][:categories].should == nil
123
- chart.options[:xAxis][:title][:text].should == 'x title'
122
+ expect(chart.options[:xAxis][:categories]).to eq(nil)
123
+ expect(chart.options[:xAxis][:title][:text]).to eq('x title')
124
124
  end
125
125
 
126
126
  it 'should allow to build options step by step without overriding previously set values' do
@@ -128,8 +128,8 @@ describe "HighChart" do
128
128
  f.xAxis!(categories: [3, 5, 7])
129
129
  f.xAxis!(title: {text: 'x title'})
130
130
  end
131
- chart.options[:xAxis][:categories].should == [3, 5, 7]
132
- chart.options[:xAxis][:title][:text].should == 'x title'
131
+ expect(chart.options[:xAxis][:categories]).to eq([3, 5, 7])
132
+ expect(chart.options[:xAxis][:title][:text]).to eq('x title')
133
133
  end
134
134
 
135
135
  it 'should merge options and data into a full options hash' do
@@ -142,9 +142,10 @@ describe "HighChart" do
142
142
  end
143
143
 
144
144
  json = chart.full_options
145
- json.should match /\"series\"/
146
- json.should match /\"title\"/
147
- json.should match /\"tooltip\": { \"enabled\": true,\"formatter\"/
145
+ expect(json).to match /\"series\"/
146
+ expect(json).to match /\"title\"/
147
+ expect(json).to match /\"tooltip\": { \"enabled\": true,\"formatter\"/
148
+ expect(json).to match /\"data\": \[ 29.9,71.5,106.4,129.2,144.0,176.0,135.6,148.5,216.4,194.1,95.6,54.4 \]/
148
149
  end
149
150
 
150
151
  end
@@ -10,56 +10,90 @@ describe HighChartsHelper do
10
10
  @chart = LazyHighCharts::HighChart.new(@placeholder)
11
11
  @data = "data"
12
12
  @options = "options"
13
+ @chart_globals = LazyHighCharts::HighChartGlobals.new do |chart|
14
+ chart.global({ useUTC: false })
15
+ chart.chart({
16
+ backgroundColor: {
17
+ linearGradient: [0, 0, 500, 500],
18
+ stops: [
19
+ [0, "rgb(255, 255, 255)"],
20
+ [1, "rgb(240, 240, 255)"]
21
+ ]
22
+ },
23
+ borderWidth: 2,
24
+ plotBackgroundColor: "rgba(255, 255, 255, .9)",
25
+ plotShadow: true,
26
+ plotBorderWidth: 1
27
+ })
28
+ chart.lang({
29
+ thousandsSep: ","
30
+ })
31
+ chart.colors([
32
+ "#90ed7d", "#f7a35c", "#8085e9", "#f15c80", "#e4d354"
33
+ ])
34
+ end
13
35
  end
14
36
 
15
37
  context "layout_helper" do
16
38
  it "should return a div with an id of high_chart object" do
17
- high_chart(@placeholder, @chart).should have_selector('div', :id => @placeholder)
39
+ expect(high_chart(@placeholder, @chart)).to have_selector('div', :id => @placeholder)
18
40
  end
19
41
 
20
42
  it "should return a script" do
21
43
  hc = LazyHighCharts::HighChart.new("placeholder")
22
- high_chart(hc.placeholder, hc).should have_selector('script')
44
+ expect(high_chart(hc.placeholder, hc)).to have_selector('script')
45
+ end
46
+ end
47
+
48
+ context "high_chart_globals" do
49
+ it "should return a script" do
50
+ high_chart_globals(@chart_globals).should have_selector('script')
51
+ end
52
+
53
+ it "should take a block and set attributes" do
54
+ high_chart_globals(@chart_globals).should match(/useUTC/)
55
+ high_chart_globals(@chart_globals).should match(/backgroundColor/)
56
+ high_chart_globals(@chart_globals).should match(/thousandsSep/)
23
57
  end
24
58
  end
25
59
 
26
60
  context "high_chart_graph" do
27
61
  describe "ready function" do
28
62
  it "should be a javascript script" do
29
- high_chart(@placeholder, @chart).should have_selector('script', :type => 'text/javascript')
30
- high_chart(@placeholder, @chart).should match(/}\)\(\)/)
63
+ expect(high_chart(@placeholder, @chart)).to have_selector('script', :type => 'text/javascript')
64
+ expect(high_chart(@placeholder, @chart)).to match(/}\)\(\)/)
31
65
  end
32
66
 
33
67
  it "should assign to the onload event" do
34
- high_chart(@placeholder, @chart).should include('window.onload = function(){')
68
+ expect(high_chart(@placeholder, @chart)).to include('window.onload = function(){')
35
69
  end
36
70
  it "should call any existing onload function" do
37
- high_chart(@placeholder, @chart).should match(/onload = window.onload;/)
38
- high_chart(@placeholder, @chart).should match(/if \(typeof onload == "function"\)\s*onload\(\)/)
71
+ expect(high_chart(@placeholder, @chart)).to match(/onload = window.onload;/)
72
+ expect(high_chart(@placeholder, @chart)).to match(/if \(typeof onload == "function"\)\s*onload\(\)/)
39
73
  end
40
74
  end
41
75
  describe "initialize HighChart" do
42
76
  it "should set variables `chart` `options`" do
43
- high_chart(@placeholder, @chart).should match(/var\s+options\s+=/)
44
- high_chart(@placeholder, @chart).should match(/window.chart_placeholder\s=/)
77
+ expect(high_chart(@placeholder, @chart)).to match(/var\s+options\s+=/)
78
+ expect(high_chart(@placeholder, @chart)).to match(/window.chart_placeholder\s=/)
45
79
  end
46
80
  it "should set Chart data" do
47
- high_chart(@placeholder, @chart).should match(/window\.chart_placeholder\s=\snew\sHighcharts.Chart/)
81
+ expect(high_chart(@placeholder, @chart)).to match(/window\.chart_placeholder\s=\snew\sHighcharts.Chart/)
48
82
  end
49
83
 
50
84
  it "should set chart renderTo" do
51
- high_chart(@placeholder, @chart).should match(/"renderTo": "placeholder"/)
85
+ expect(high_chart(@placeholder, @chart)).to match(/"renderTo": "placeholder"/)
52
86
  end
53
87
 
54
88
  it "should set Chart Stock" do
55
- high_stock(@placeholder, @chart).should match(/window\.chart_placeholder\s+=\s+new\s+Highcharts.StockChart/)
89
+ expect(high_stock(@placeholder, @chart)).to match(/window\.chart_placeholder\s+=\s+new\s+Highcharts.StockChart/)
56
90
  end
57
91
  end
58
92
 
59
93
  describe "HighChart Variable" do
60
94
  it "should underscore chart_ variable" do
61
- high_chart("place-holder", @chart).should match(/window.chart_place_holder\s=/)
62
- high_chart("PlaceHolder", @chart).should match(/window.chart_place_holder\s=/)
95
+ expect(high_chart("place-holder", @chart)).to match(/window.chart_place_holder\s=/)
96
+ expect(high_chart("PlaceHolder", @chart)).to match(/window.chart_place_holder\s=/)
63
97
  end
64
98
  end
65
99
  end
@@ -75,11 +109,11 @@ describe HighChartsHelper do
75
109
  :data => [0, 1, 2, 3, 5, 6, 0, 7]
76
110
  )
77
111
  }
78
- chart.options[:rangeSelector][:selected].should == 1
79
- high_chart(@placeholder, chart).should match(/rangeSelector/)
80
- high_chart(@placeholder, chart).should match(/xAxis/)
81
- high_chart(@placeholder, chart).should match(/yAxis/)
82
- high_chart(@placeholder, chart).should match(/series/)
112
+ expect(chart.options[:rangeSelector][:selected]).to eq(1)
113
+ expect(high_chart(@placeholder, chart)).to match(/rangeSelector/)
114
+ expect(high_chart(@placeholder, chart)).to match(/xAxis/)
115
+ expect(high_chart(@placeholder, chart)).to match(/yAxis/)
116
+ expect(high_chart(@placeholder, chart)).to match(/series/)
83
117
 
84
118
  end
85
119
 
@@ -88,7 +122,7 @@ describe HighChartsHelper do
88
122
  chart = LazyHighCharts::HighChart.new { |f|
89
123
  f.others(:foo => "bar")
90
124
  }
91
- high_chart(@placeholder, chart).should match(/foo/)
125
+ expect(high_chart(@placeholder, chart)).to match(/foo/)
92
126
  end
93
127
 
94
128
  it "should allow js code as attribute" do
@@ -96,7 +130,7 @@ describe HighChartsHelper do
96
130
  f.options[:foo] = "function () { alert('hello') }".js_code
97
131
  }
98
132
 
99
- high_chart(@placeholder, chart).should match(/"foo": function \(\) { alert\('hello'\) }/)
133
+ expect(high_chart(@placeholder, chart)).to match(/"foo": function \(\) { alert\('hello'\) }/)
100
134
  end
101
135
 
102
136
  it "should convert keys to proper format" do
@@ -104,8 +138,8 @@ describe HighChartsHelper do
104
138
  f.options[:foo_bar] = {:bar_foo => "someattrib"}
105
139
  }
106
140
 
107
- high_chart(@placeholder, chart).should match(/fooBar/)
108
- high_chart(@placeholder, chart).should match(/barFoo/)
141
+ expect(high_chart(@placeholder, chart)).to match(/fooBar/)
142
+ expect(high_chart(@placeholder, chart)).to match(/barFoo/)
109
143
  end
110
144
 
111
145
  # issue #62 .js_code setting ignored
@@ -118,7 +152,7 @@ describe HighChartsHelper do
118
152
  }
119
153
  }])
120
154
  }
121
- high_chart(@placeholder, chart).should match(/"formatter": function\(\) {return this.value \+ ' W';}/)
155
+ expect(high_chart(@placeholder, chart)).to match(/"formatter": function\(\) {return this.value \+ ' W';}/)
122
156
  end
123
157
 
124
158
  it "should support js_code in Individual data label for each point" do
@@ -135,7 +169,7 @@ describe HighChartsHelper do
135
169
  :y => 54.4}
136
170
  ])
137
171
  }
138
- high_chart(@placeholder, chart).should match(/"formatter": function\(\) {\ return this.x;\ }/)
172
+ expect(high_chart(@placeholder, chart)).to match(/"formatter": function\(\) {\ return this.x;\ }/)
139
173
  end
140
174
 
141
175
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/spec_helper'
3
3
  describe LazyHighCharts::OptionsKeyFilter do
4
4
  it "should filter :pointInterval from seconds to milliseconds" do
5
5
  hash = LazyHighCharts::OptionsKeyFilter.filter(pointInterval: 1)
6
- hash[:pointInterval].should == 1000
6
+ expect(hash[:pointInterval]).to eq(1000)
7
7
  end
8
8
 
9
9
  describe "filters :pointStart from a Date to a JavaScript compatible string" do
@@ -13,16 +13,16 @@ describe LazyHighCharts::OptionsKeyFilter do
13
13
  end
14
14
 
15
15
  it "should be the correct string" do
16
- @value.should == "Date.UTC(2012, 8, 13)"
16
+ expect(@value).to eq("Date.UTC(2012, 8, 13)")
17
17
  end
18
18
 
19
19
  it "should be js_code" do
20
- @value.js_code.should be_true
20
+ expect(@value.js_code).to be_truthy
21
21
  end
22
22
  end
23
23
 
24
24
  it "should filter keys recursively" do
25
25
  hash = LazyHighCharts::OptionsKeyFilter.filter({something: {another_thing: {pointInterval: 2}}})
26
- hash[:something][:another_thing][:pointInterval].should == 2000
26
+ expect(hash[:something][:another_thing][:pointInterval]).to eq(2000)
27
27
  end
28
- end
28
+ end
@@ -6,7 +6,7 @@ require 'active_support'
6
6
  require 'action_pack'
7
7
  require 'action_view'
8
8
  require 'action_controller'
9
- require "active_support/core_ext"
9
+ require 'active_support/core_ext'
10
10
 
11
11
 
12
12
  require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts'))
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.5.4
4
+ version: 1.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Michelson
@@ -9,34 +9,34 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-05-22 00:00:00.000000000 Z
12
+ date: 2016-03-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.0'
21
- type: :runtime
21
+ type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: hash-deep-merge
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
42
  description: |2
@@ -50,9 +50,9 @@ extra_rdoc_files:
50
50
  - README.md
51
51
  - CHANGELOG.md
52
52
  files:
53
- - .gitignore
54
- - .rspec
55
- - .travis.yml
53
+ - ".gitignore"
54
+ - ".rspec"
55
+ - ".travis.yml"
56
56
  - CHANGELOG.md
57
57
  - GEM_VERSION
58
58
  - Gemfile
@@ -66,6 +66,7 @@ files:
66
66
  - lib/lazy_high_charts/core_ext/string.rb
67
67
  - lib/lazy_high_charts/engine.rb
68
68
  - lib/lazy_high_charts/high_chart.rb
69
+ - lib/lazy_high_charts/high_chart_globals.rb
69
70
  - lib/lazy_high_charts/layout_helper.rb
70
71
  - lib/lazy_high_charts/options_key_filter.rb
71
72
  - lib/lazy_high_charts/railtie.rb
@@ -136,6 +137,7 @@ files:
136
137
  - spec/dummy_sinatra/config.ru
137
138
  - spec/dummy_sinatra/views/index.erb
138
139
  - spec/dummy_sinatra/views/layout.erb
140
+ - spec/high_chart_globals_spec.rb
139
141
  - spec/high_chart_spec.rb
140
142
  - spec/lazy_high_charts_spec.rb
141
143
  - spec/options_key_filter_spec.rb
@@ -155,22 +157,22 @@ licenses: []
155
157
  metadata: {}
156
158
  post_install_message:
157
159
  rdoc_options:
158
- - --charset=UTF-8
160
+ - "--charset=UTF-8"
159
161
  require_paths:
160
162
  - lib
161
163
  required_ruby_version: !ruby/object:Gem::Requirement
162
164
  requirements:
163
- - - '>='
165
+ - - ">="
164
166
  - !ruby/object:Gem::Version
165
167
  version: '0'
166
168
  required_rubygems_version: !ruby/object:Gem::Requirement
167
169
  requirements:
168
- - - '>='
170
+ - - ">="
169
171
  - !ruby/object:Gem::Version
170
172
  version: '1.3'
171
173
  requirements: []
172
174
  rubyforge_project:
173
- rubygems_version: 2.0.6
175
+ rubygems_version: 2.4.8
174
176
  signing_key:
175
177
  specification_version: 4
176
178
  summary: rubyist way to render variant chart by highcharts without write javascript