lazy_high_charts 1.4.2 → 1.4.3

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.
Files changed (48) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +8 -3
  4. data/GEM_VERSION +1 -1
  5. data/Gemfile +1 -1
  6. data/Guardfile +2 -2
  7. data/README.md +4 -4
  8. data/Rakefile +36 -1
  9. data/lazy_high_charts.gemspec +11 -11
  10. data/lib/lazy_high_charts.rb +4 -2
  11. data/lib/lazy_high_charts/core_ext/string.rb +4 -4
  12. data/lib/lazy_high_charts/high_chart.rb +32 -17
  13. data/lib/lazy_high_charts/layout_helper.rb +9 -9
  14. data/lib/lazy_high_charts/railtie.rb +6 -6
  15. data/spec/high_chart_spec.rb +56 -41
  16. data/spec/lazy_high_charts_spec.rb +49 -43
  17. data/spec/spec_helper.rb +1 -1
  18. data/vendor/assets/javascripts/highcharts/adapters/mootools-adapter.js +13 -0
  19. data/vendor/assets/javascripts/highcharts/adapters/prototype-adapter.js +15 -0
  20. data/vendor/assets/javascripts/highcharts/highcharts-more.js +51 -0
  21. data/vendor/assets/javascripts/highcharts/highcharts.js +272 -0
  22. data/vendor/assets/javascripts/highcharts/highstock.js +334 -0
  23. data/vendor/assets/javascripts/highcharts/modules/exporting.js +10 -10
  24. data/vendor/assets/javascripts/highcharts/stock/adapters/mootools-adapter.js +13 -0
  25. data/vendor/assets/javascripts/highcharts/stock/adapters/prototype-adapter.js +15 -0
  26. data/vendor/assets/javascripts/highcharts/stock/highcharts-more.js +51 -0
  27. data/vendor/assets/javascripts/highcharts/stock/modules/exporting.js +22 -0
  28. metadata +59 -52
  29. metadata.gz.sig +3 -2
  30. checksums.yaml +0 -7
  31. checksums.yaml.gz.sig +0 -2
  32. data/lib/generators/lazy_high_charts/install/install_generator.rb +0 -31
  33. data/vendor/assets/javascripts/exporting.js +0 -22
  34. data/vendor/assets/javascripts/highcharts-more.js +0 -50
  35. data/vendor/assets/javascripts/highcharts.js +0 -270
  36. data/vendor/assets/javascripts/highcharts/modules/canvas-tools.js +0 -133
  37. data/vendor/assets/javascripts/highcharts/modules/canvas-tools.src.js +0 -3113
  38. data/vendor/assets/javascripts/highcharts/modules/data.js +0 -16
  39. data/vendor/assets/javascripts/highcharts/modules/data.src.js +0 -537
  40. data/vendor/assets/javascripts/highcharts/modules/exporting.src.js +0 -703
  41. data/vendor/assets/javascripts/highcharts/modules/funnel.js +0 -12
  42. data/vendor/assets/javascripts/highcharts/modules/funnel.src.js +0 -284
  43. data/vendor/assets/javascripts/highcharts/themes/dark-blue.js +0 -254
  44. data/vendor/assets/javascripts/highcharts/themes/dark-green.js +0 -255
  45. data/vendor/assets/javascripts/highcharts/themes/gray.js +0 -257
  46. data/vendor/assets/javascripts/highcharts/themes/grid.js +0 -103
  47. data/vendor/assets/javascripts/highcharts/themes/skies.js +0 -89
  48. data/vendor/assets/javascripts/highstock.js +0 -332
data.tar.gz.sig CHANGED
Binary file
data/.travis.yml CHANGED
@@ -6,4 +6,4 @@ script: bundle exec rake
6
6
 
7
7
  rvm:
8
8
  - 1.9.3
9
- - ruby-head
9
+ - 2.0.0
data/CHANGELOG.md CHANGED
@@ -1,7 +1,12 @@
1
+ # VERSION 1.4.3
2
+ * Sat Jul 20, 2013
3
+ 1. Formatting all files
4
+ 2. change js update methods to rake, use rake highcharts:update to fetch upstream js files.
5
+ 3. update highcharts to 3.0.2
6
+
1
7
  # VERSION 1.4.2
2
- * Wed Apr 17 2013
3
- 1. upgraded js lib to 3.0.1.
4
- [#121](https://github.com/michelson/lazy_high_charts/issues/121)
8
+ * April 17, 2013
9
+ 1. bump new version to release
5
10
  # VERSION 1.4.1
6
11
  * Sat Apr 6, 2013
7
12
  1. support HighCharts 3.0
data/GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.2
1
+ 1.4.3
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  group :test, :development do # This causes the plugins to NOT load
7
- gem 'webrat','~> 0.7'
7
+ gem 'webrat', '~> 0.7'
8
8
  gem 'rspec', '~> 2.0'
9
9
  gem 'rails', '>= 3.2'
10
10
  gem 'guard-rspec'
data/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard 'rspec' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
8
  end
9
9
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # LazyHighCharts - Official gem repository
2
2
 
3
- Easily displaying Highcharts graphs with gem style.
3
+ Easily include HighCharts in your project with this gem
4
4
  [![Build Status](https://secure.travis-ci.org/michelson/lazy_high_charts.png)](http://travis-ci.org/michelson/lazy_high_charts)
5
5
 
6
6
  ## Notice
@@ -10,7 +10,7 @@ Current
10
10
 
11
11
  ## Installation
12
12
 
13
- ### Installing it by rubygems
13
+ ### Installation with rubygems
14
14
 
15
15
  To install it, you just need to add it to your Gemfile:
16
16
 
@@ -26,11 +26,11 @@ bundle install
26
26
 
27
27
  to install it.
28
28
 
29
- ### legacy notice: if you use rails 2.3.x or 3.0.x or 3.1.x, please keep version should be less than 1.3.3.
29
+ ### Deprecation notice: if you use rails 2.3.x or 3.0.x or 3.1.x, please use versions less than 1.3.3.
30
30
 
31
31
  ## Lazy_high_charts User Guide
32
32
 
33
- Todo...Hold on
33
+ See [project WIKI page](https://github.com/michelson/lazy_high_charts/wiki)
34
34
 
35
35
  ## Contributing
36
36
 
data/Rakefile CHANGED
@@ -9,5 +9,40 @@ task :default => :spec
9
9
 
10
10
  desc 'Test the lazy_high_charts plugin.'
11
11
  RSpec::Core::RakeTask.new('spec') do |t|
12
- t.pattern = FileList['spec/**/*_spec.rb']
12
+ t.pattern = FileList['spec/**/*_spec.rb']
13
+ end
14
+
15
+ # Below implement highcharts js files bootstrap logic
16
+ def say(msg, &block)
17
+ print "#{msg}..."
18
+
19
+ if block_given?
20
+ yield
21
+ puts " Done."
22
+ end
23
+ end
24
+
25
+ namespace :highcharts do
26
+ desc "Update highcharts.js from latest Builds on Highcharts codebase: http://code.highcharts.com/"
27
+ task :update => [:core, :stock]
28
+ task :core do
29
+ say "Grabbing Core from Highcharts codebase..." do
30
+ sh "curl -# http://code.highcharts.com/highcharts.js -L --compressed -o vendor/assets/javascripts/highcharts/highcharts.js"
31
+ sh "curl -# http://code.highcharts.com/highcharts-more.js -L --compressed -o vendor/assets/javascripts/highcharts/highcharts-more.js"
32
+ sh "curl -# http://code.highcharts.com/modules/exporting.js -L --compressed -o vendor/assets/javascripts/highcharts/modules/exporting.js"
33
+ sh "curl -# http://code.highcharts.com/adapters/mootools-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/adapters/mootools-adapter.js"
34
+ sh "curl -# http://code.highcharts.com/adapters/prototype-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/adapters/prototype-adapter.js"
35
+ end
36
+ end
37
+
38
+ task :stock do
39
+ say "Grabbing Highcharts Stock JS from Upstream..." do
40
+ sh "curl -# http://code.highcharts.com/stock/highstock.js -L --compressed -o vendor/assets/javascripts/highcharts/highstock.js"
41
+ sh "curl -# http://code.highcharts.com/stock/highcharts-more.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/highcharts-more.js"
42
+ sh "curl -# http://code.highcharts.com/stock/modules/exporting.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/modules/exporting.js"
43
+ sh "curl -# http://code.highcharts.com/stock/adapters/mootools-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/adapters/mootools-adapter.js"
44
+ sh "curl -# http://code.highcharts.com/stock/adapters/prototype-adapter.js -L --compressed -o vendor/assets/javascripts/highcharts/stock/adapters/prototype-adapter.js"
45
+ end
46
+ end
47
+
13
48
  end
@@ -1,19 +1,19 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
3
- version = File.read(File.expand_path("../GEM_VERSION",__FILE__)).strip
3
+ version = File.read(File.expand_path("../GEM_VERSION", __FILE__)).strip
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "lazy_high_charts"
7
- s.version = version
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ['Miguel Michelson', 'Deshi Xiao']
10
- s.email = ['miguelmichelson@gmail.com', 'xiaods@gmail.com']
11
- s.homepage = "https://github.com/michelson/lazy_high_charts"
12
- s.summary = "rubyist way to render variant chart by highcharts without write javascript right now, rails gem library."
6
+ s.name = "lazy_high_charts"
7
+ s.version = version
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Miguel Michelson', 'Deshi Xiao']
10
+ s.email = ['miguelmichelson@gmail.com', 'xiaods@gmail.com']
11
+ s.homepage = "https://github.com/michelson/lazy_high_charts"
12
+ s.summary = "rubyist way to render variant chart by highcharts without write javascript right now, rails gem library."
13
13
  s.description = "lazy_high_charts is leading edge rubyist render charts gem for displaying Highcharts graphs."
14
14
 
15
- s.extra_rdoc_files = [ "README.md", "CHANGELOG.md" ]
16
- s.rdoc_options = [ "--charset=UTF-8" ]
15
+ s.extra_rdoc_files = ["README.md", "CHANGELOG.md"]
16
+ s.rdoc_options = ["--charset=UTF-8"]
17
17
  key = File.expand_path("~/.ssh/gem-private_key.pem")
18
18
  if File.exist?(key)
19
19
  s.signing_key = key
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  DESC
31
31
 
32
32
  s.files = `git ls-files`.split("\n")
33
- s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
33
+ s.executables = `git ls-files`.split("\n").select { |f| f =~ /^bin/ }
34
34
  s.require_path = 'lib'
35
35
 
36
36
  end
@@ -1,12 +1,14 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts core_ext string])
2
2
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts options_key_filter])
3
- require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart])
4
3
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts layout_helper])
4
+ require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart])
5
5
  if defined?(::Rails::Railtie)
6
6
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts railtie])
7
7
  require File.join(File.dirname(__FILE__), *%w[lazy_high_charts engine]) if ::Rails.version.to_s >= '3.1'
8
8
  end
9
9
 
10
10
  module LazyHighCharts
11
-
11
+ def self.root
12
+ File.expand_path '../..', __FILE__
13
+ end
12
14
  end
@@ -1,12 +1,12 @@
1
1
  class String
2
-
2
+
3
3
  def js_code true_or_false = true
4
4
  @_lazy_high_charts_js_code = true_or_false
5
5
  self
6
6
  end
7
-
7
+
8
8
  def js_code?
9
- @_lazy_high_charts_js_code || false
9
+ @_lazy_high_charts_js_code || false
10
10
  end
11
-
11
+
12
12
  end
@@ -1,17 +1,20 @@
1
+
1
2
  module LazyHighCharts
2
3
  class HighChart
4
+ include LayoutHelper
5
+
3
6
  SERIES_OPTIONS = %w(data dataParser dataURL index legendIndex name stack type xAxis yAxis)
4
7
 
5
8
  attr_accessor :data, :options, :placeholder, :html_options
6
- alias :canvas :placeholder
7
- alias :canvas= :placeholder=
9
+ alias :canvas :placeholder
10
+ alias :canvas= :placeholder=
8
11
 
9
12
  def initialize(canvas = nil, html_opts = {})
10
13
 
11
14
  @collection_filter = nil
12
15
  self.tap do |high_chart|
13
- high_chart.data ||= []
14
- high_chart.options ||= {}
16
+ high_chart.data ||= []
17
+ high_chart.options ||= {}
15
18
  high_chart.defaults_options
16
19
  high_chart.html_options ||= html_opts
17
20
  high_chart.canvas = (canvas ? canvas : random_canvas_id)
@@ -21,14 +24,14 @@ module LazyHighCharts
21
24
 
22
25
  # title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
23
26
  def defaults_options
24
- self.title({ :text=> nil })
25
- self.legend({ :layout=>"vertical", :style=>{} })
27
+ self.title({:text => nil})
28
+ self.legend({:layout => "vertical", :style => {}})
26
29
  self.xAxis({})
27
- self.yAxis({ :title=> {:text=> nil}, :labels=>{} })
28
- self.tooltip({ :enabled=>true })
29
- self.credits({ :enabled => false})
30
- self.plotOptions({ :areaspline => { } })
31
- self.chart({ :defaultSeriesType=>"line" , :renderTo => nil})
30
+ self.yAxis({:title => {:text => nil}, :labels => {}})
31
+ self.tooltip({:enabled => true})
32
+ self.credits({:enabled => false})
33
+ self.plotOptions({:areaspline => {}})
34
+ self.chart({:defaultSeriesType => "line", :renderTo => nil})
32
35
  self.subtitle({})
33
36
  end
34
37
 
@@ -56,28 +59,40 @@ module LazyHighCharts
56
59
  end
57
60
  end
58
61
 
59
- private
62
+ # Pre-processes and returns full set of options relevant to the chart. Identical to what happens in the high_charts
63
+ # view helper.
64
+ #
65
+ # @return [Hash] options JSON options hash
66
+ def full_options
67
+ options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(self.options))]
68
+ options_collection << %|"series": [#{generate_json_from_array(self.data)}]|
69
+ <<-EOJS
70
+ { #{options_collection.join(', ')} }
71
+ EOJS
72
+ end
73
+
74
+ private
60
75
 
61
76
  def random_canvas_id
62
77
  canvas_id_length = 11
63
- # Don't use SecureRandom.urlsafe_base64; it gives invalid characters.
78
+ # Don't use SecureRandom.urlsafe_base64; it gives invalid characters.
64
79
  ('a'..'z').to_a.shuffle.take(canvas_id_length).join
65
80
  end
66
81
 
67
82
  def series_options
68
- @options.reject {|k,v| SERIES_OPTIONS.include?(k.to_s) == false}
83
+ @options.reject { |k, v| SERIES_OPTIONS.include?(k.to_s) == false }
69
84
  end
70
85
 
71
86
  def merge_options(name, opts)
72
- @options.merge! name => opts
87
+ @options.merge! name => opts
73
88
  end
74
89
 
75
90
  def deep_merge_options(name, opts)
76
- @options.deep_merge! name => opts
91
+ @options.deep_merge! name => opts
77
92
  end
78
93
 
79
94
  def arguments_to_options(args)
80
- if args.blank?
95
+ if args.blank?
81
96
  {:show => true}
82
97
  elsif args.is_a? Array
83
98
  args.first
@@ -3,16 +3,16 @@
3
3
  module LazyHighCharts
4
4
  module LayoutHelper
5
5
 
6
- def high_chart(placeholder, object , &block)
7
- object.html_options.merge!({:id=>placeholder})
6
+ def high_chart(placeholder, object, &block)
7
+ object.html_options.merge!({:id => placeholder})
8
8
  object.options[:chart][:renderTo] = placeholder
9
- high_graph(placeholder,object , &block).concat(content_tag("div","", object.html_options))
9
+ high_graph(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
10
10
  end
11
11
 
12
- def high_stock(placeholder, object , &block)
13
- object.html_options.merge!({:id=>placeholder})
12
+ def high_stock(placeholder, object, &block)
13
+ object.html_options.merge!({:id => placeholder})
14
14
  object.options[:chart][:renderTo] = placeholder
15
- high_graph_stock(placeholder,object , &block).concat(content_tag("div","", object.html_options))
15
+ high_graph_stock(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
16
16
  end
17
17
 
18
18
  def high_graph(placeholder, object, &block)
@@ -24,13 +24,13 @@ module LazyHighCharts
24
24
  end
25
25
 
26
26
  def build_html_output(type, placeholder, object, &block)
27
- options_collection = [ generate_json_from_hash(OptionsKeyFilter.filter(object.options)) ]
27
+ options_collection = [generate_json_from_hash(OptionsKeyFilter.filter(object.options))]
28
28
  options_collection << %|"series": [#{generate_json_from_array(object.data)}]|
29
29
 
30
30
  core_js =<<-EOJS
31
31
  var options = { #{options_collection.join(',')} };
32
32
  #{capture(&block) if block_given?}
33
- window.chart_#{placeholder} = new Highcharts.#{type}(options);
33
+ window.chart_#{placeholder.underscore} = new Highcharts.#{type}(options);
34
34
  EOJS
35
35
 
36
36
  if defined?(request) && request.respond_to?(:xhr?) && request.xhr?
@@ -97,7 +97,7 @@ module LazyHighCharts
97
97
  end
98
98
 
99
99
  def generate_json_from_array array
100
- array.map{|value| generate_json_from_value(value)}.join(",")
100
+ array.map { |value| generate_json_from_value(value) }.join(",")
101
101
  end
102
102
 
103
103
  end
@@ -1,11 +1,11 @@
1
1
  # encoding: UTF-8
2
2
  module LazyHighCharts
3
- class Railtie < ::Rails::Railtie
4
- config.before_configuration do
5
- if config.action_view.javascript_expansions
6
- config.action_view.javascript_expansions[:high_charts] |= %w(highcharts exporting)
7
- end
3
+ class Railtie < ::Rails::Railtie
4
+ config.before_configuration do
5
+ if config.action_view.javascript_expansions
6
+ config.action_view.javascript_expansions[:high_charts] |= %w(highcharts exporting)
8
7
  end
9
8
  end
10
-
9
+ end
10
+
11
11
  end
@@ -4,14 +4,14 @@ Record = Struct.new(:frequency, :amplitude)
4
4
 
5
5
  describe "HighChart" do
6
6
  before(:each) do
7
- @collection = [Record.new(1,15), Record.new(2,30), Record.new(4,40)]
8
- @data = [ [1,15], [2,30], [4,40]]
7
+ @collection = [Record.new(1, 15), Record.new(2, 30), Record.new(4, 40)]
8
+ @data = [[1, 15], [2, 30], [4, 40]]
9
9
 
10
- @placeholder = "placeholder"
10
+ @placeholder = "placeholder"
11
11
  @html_options = {:class => "stylin"}
12
- @options = {:bars => {:show => true}}
12
+ @options = {:bars => {:show => true}}
13
13
 
14
- @flot = LazyHighCharts::HighChart.new(@placeholder, @html_options) {|chart| chart.options = @options }
14
+ @flot = LazyHighCharts::HighChart.new(@placeholder, @html_options) { |chart| chart.options = @options }
15
15
  end
16
16
 
17
17
  # this is almost all flotomatic stuff
@@ -31,20 +31,20 @@ describe "HighChart" do
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
+ LazyHighCharts::HighChart.new(@placeholder, @html_options).html_options.should == @html_options
35
35
  end
36
36
 
37
37
  it "should set options by default" do
38
38
  LazyHighCharts::HighChart.new.options.should == {
39
- :title=>{:text=>nil},
40
- :legend=>{:layout=>"vertical", :style=>{}},
41
- :xAxis=>{},
42
- :yAxis=>{:title=>{:text=>nil}, :labels=>{}},
43
- :tooltip=>{:enabled=>true},
44
- :credits=>{:enabled=>false},
45
- :plotOptions=>{:areaspline=>{}},
46
- :chart=>{:defaultSeriesType=>"line", :renderTo=>nil},
47
- :subtitle=>{}}
39
+ :title => {:text => nil},
40
+ :legend => {:layout => "vertical", :style => {}},
41
+ :xAxis => {},
42
+ :yAxis => {:title => {:text => nil}, :labels => {}},
43
+ :tooltip => {:enabled => true},
44
+ :credits => {:enabled => false},
45
+ :plotOptions => {:areaspline => {}},
46
+ :chart => {:defaultSeriesType => "line", :renderTo => nil},
47
+ :subtitle => {}}
48
48
  end
49
49
 
50
50
  it "should set data empty by default" do
@@ -52,64 +52,64 @@ describe "HighChart" do
52
52
  end
53
53
 
54
54
  it "should take a block setting attributes" do
55
- chart = LazyHighCharts::HighChart.new {|f| f.data = @data ; f.options = @options }
55
+ chart = LazyHighCharts::HighChart.new { |f| f.data = @data; f.options = @options }
56
56
  chart.data.should == @data
57
57
  chart.options.should == @options
58
58
  end
59
59
 
60
60
  it "should take a block setting attributes" do
61
- chart = LazyHighCharts::HighChart.new {|f| f.options[:legend][:layout] = "horizontal" }
61
+ chart = LazyHighCharts::HighChart.new { |f| f.options[:legend][:layout] = "horizontal" }
62
62
  chart.options[:legend][:layout].should == "horizontal"
63
63
  end
64
64
 
65
65
  it "should take a block setting attributes" do
66
- chart = LazyHighCharts::HighChart.new {|f| f.options[:range_selector] = {}; f.options[:range_selector][:selected] = 1}
66
+ chart = LazyHighCharts::HighChart.new { |f| f.options[:range_selector] = {}; f.options[:range_selector][:selected] = 1 }
67
67
  chart.options[:range_selector][:selected].should == 1
68
68
  end
69
69
 
70
70
  it "should change a block data without overriding options" do
71
71
  chart = LazyHighCharts::HighChart.new('graph') do |f|
72
- f.series(:name=>'John', :data=>[3, 20])
73
- f.series(:name=>'Jane',:data=> [1, 3] )
72
+ f.series(:name => 'John', :data => [3, 20])
73
+ f.series(:name => 'Jane', :data => [1, 3])
74
74
  # without overriding
75
75
  f.options[:chart][:defaultSeriesType] = "area"
76
76
  f.options[:chart][:inverted] = true
77
77
  f.options[:legend][:layout] = "horizontal"
78
- f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
78
+ f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
79
79
  end
80
- chart.data.should == [{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
80
+ chart.data.should == [{:name => "John", :data => [3, 20]}, {:name => "Jane", :data => [1, 3]}]
81
81
  chart.options[:legend][:layout].should == "horizontal"
82
- chart.options[:xAxis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
82
+ chart.options[:xAxis][:categories].should == ["uno", "dos", "tres", "cuatro"]
83
83
  chart.options[:chart][:defaultSeriesType].should == "area"
84
84
  chart.options[:chart][:inverted].should == true
85
85
  end
86
86
 
87
87
  it "should change a block data with overriding entire options" do
88
88
  chart = LazyHighCharts::HighChart.new('graph') do |f|
89
- f.series(:name=>'John', :data=>[3, 20])
90
- f.series(:name=>'Jane', :data=>[1, 3] )
91
- f.title({ :text=> nil })
92
- # without overriding
93
- f.xAxis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
94
- f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
89
+ f.series(:name => 'John', :data => [3, 20])
90
+ f.series(:name => 'Jane', :data => [1, 3])
91
+ f.title({:text => nil})
92
+ # without overriding
93
+ f.xAxis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
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
+ 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
102
102
  end
103
103
 
104
104
  it "should have subtitles" do
105
105
  chart = LazyHighCharts::HighChart.new('graph') do |f|
106
- f.series(:name=>'John',:data=> [3, 20])
107
- f.series(:name=>'Jane', :data=>[1, 3] )
108
- f.title({ :text=>nil})
106
+ f.series(:name => 'John', :data => [3, 20])
107
+ f.series(:name => 'Jane', :data => [1, 3])
108
+ f.title({:text => nil})
109
109
  # without overriding
110
- f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
111
- f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
112
- f.subtitle({:text=>"Bar"})
110
+ f.x_axis(:categories => ["uno", "dos", "tres", "cuatro"], :labels => {:rotation => -45, :align => 'right'})
111
+ f.chart({:defaultSeriesType => "spline", :renderTo => "myRenderArea", :inverted => true})
112
+ f.subtitle({:text => "Bar"})
113
113
  end
114
114
  chart.options[:subtitle][:text].should == "Bar"
115
115
  end
@@ -132,6 +132,21 @@ describe "HighChart" do
132
132
  chart.options[:xAxis][:title][:text].should == 'x title'
133
133
  end
134
134
 
135
+ it 'should merge options and data into a full options hash' do
136
+ chart = LazyHighCharts::HighChart.new('graph') do |f|
137
+ f.series(name: 'John', 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])
138
+ f.series(name: 'Jane', data: [140.02, 41.63, 66.72, 113.21, 107.98, 105.71, 28.59, 114.23, 5.56, 93.71, 137.35, 93.16])
139
+ f.title({text: 'Example Data'})
140
+ f.xAxis(categories: %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec), labels: {rotation: -45, align: 'right'})
141
+ f.options[:tooltip][:formatter] = "function(){ return '<b>'+ this.point.name +'</b>: '+ Highcharts.numberFormat(this.percentage, 2) +' %'; }"
142
+ end
143
+
144
+ json = chart.full_options
145
+ json.should match /\"series\"/
146
+ json.should match /\"title\"/
147
+ json.should match /\"tooltip\": { \"enabled\": true,\"formatter\"/
148
+ end
149
+
135
150
  end
136
151
 
137
152
  end