lazy_high_charts 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +8 -3
- data/GEM_VERSION +1 -1
- data/Gemfile +1 -1
- data/Guardfile +2 -2
- data/README.md +4 -4
- data/Rakefile +36 -1
- data/lazy_high_charts.gemspec +11 -11
- data/lib/lazy_high_charts.rb +4 -2
- data/lib/lazy_high_charts/core_ext/string.rb +4 -4
- data/lib/lazy_high_charts/high_chart.rb +32 -17
- data/lib/lazy_high_charts/layout_helper.rb +9 -9
- data/lib/lazy_high_charts/railtie.rb +6 -6
- data/spec/high_chart_spec.rb +56 -41
- data/spec/lazy_high_charts_spec.rb +49 -43
- data/spec/spec_helper.rb +1 -1
- data/vendor/assets/javascripts/highcharts/adapters/mootools-adapter.js +13 -0
- data/vendor/assets/javascripts/highcharts/adapters/prototype-adapter.js +15 -0
- data/vendor/assets/javascripts/highcharts/highcharts-more.js +51 -0
- data/vendor/assets/javascripts/highcharts/highcharts.js +272 -0
- data/vendor/assets/javascripts/highcharts/highstock.js +334 -0
- data/vendor/assets/javascripts/highcharts/modules/exporting.js +10 -10
- data/vendor/assets/javascripts/highcharts/stock/adapters/mootools-adapter.js +13 -0
- data/vendor/assets/javascripts/highcharts/stock/adapters/prototype-adapter.js +15 -0
- data/vendor/assets/javascripts/highcharts/stock/highcharts-more.js +51 -0
- data/vendor/assets/javascripts/highcharts/stock/modules/exporting.js +22 -0
- metadata +59 -52
- metadata.gz.sig +3 -2
- checksums.yaml +0 -7
- checksums.yaml.gz.sig +0 -2
- data/lib/generators/lazy_high_charts/install/install_generator.rb +0 -31
- data/vendor/assets/javascripts/exporting.js +0 -22
- data/vendor/assets/javascripts/highcharts-more.js +0 -50
- data/vendor/assets/javascripts/highcharts.js +0 -270
- data/vendor/assets/javascripts/highcharts/modules/canvas-tools.js +0 -133
- data/vendor/assets/javascripts/highcharts/modules/canvas-tools.src.js +0 -3113
- data/vendor/assets/javascripts/highcharts/modules/data.js +0 -16
- data/vendor/assets/javascripts/highcharts/modules/data.src.js +0 -537
- data/vendor/assets/javascripts/highcharts/modules/exporting.src.js +0 -703
- data/vendor/assets/javascripts/highcharts/modules/funnel.js +0 -12
- data/vendor/assets/javascripts/highcharts/modules/funnel.src.js +0 -284
- data/vendor/assets/javascripts/highcharts/themes/dark-blue.js +0 -254
- data/vendor/assets/javascripts/highcharts/themes/dark-green.js +0 -255
- data/vendor/assets/javascripts/highcharts/themes/gray.js +0 -257
- data/vendor/assets/javascripts/highcharts/themes/grid.js +0 -103
- data/vendor/assets/javascripts/highcharts/themes/skies.js +0 -89
- data/vendor/assets/javascripts/highstock.js +0 -332
data.tar.gz.sig
CHANGED
Binary file
|
data/.travis.yml
CHANGED
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
|
-
*
|
3
|
-
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.
|
1
|
+
1.4.3
|
data/Gemfile
CHANGED
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$})
|
7
|
-
watch('spec/spec_helper.rb')
|
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
|
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
|
-
###
|
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
|
-
###
|
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
|
-
|
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
|
-
|
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
|
data/lazy_high_charts.gemspec
CHANGED
@@ -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
|
7
|
-
s.version
|
8
|
-
s.platform
|
9
|
-
s.authors
|
10
|
-
s.email
|
11
|
-
s.homepage
|
12
|
-
s.summary
|
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
|
16
|
-
s.rdoc_options
|
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
|
data/lib/lazy_high_charts.rb
CHANGED
@@ -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,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
|
7
|
-
alias
|
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({
|
25
|
-
self.legend({
|
27
|
+
self.title({:text => nil})
|
28
|
+
self.legend({:layout => "vertical", :style => {}})
|
26
29
|
self.xAxis({})
|
27
|
-
self.yAxis({
|
28
|
-
self.tooltip({
|
29
|
-
self.credits({
|
30
|
-
self.plotOptions({
|
31
|
-
self.chart({
|
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
|
-
|
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!
|
87
|
+
@options.merge! name => opts
|
73
88
|
end
|
74
89
|
|
75
90
|
def deep_merge_options(name, opts)
|
76
|
-
@options.deep_merge!
|
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
|
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
|
9
|
+
high_graph(placeholder, object, &block).concat(content_tag("div", "", object.html_options))
|
10
10
|
end
|
11
11
|
|
12
|
-
def high_stock(placeholder, object
|
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
|
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 =
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
data/spec/high_chart_spec.rb
CHANGED
@@ -4,14 +4,14 @@ Record = Struct.new(:frequency, :amplitude)
|
|
4
4
|
|
5
5
|
describe "HighChart" do
|
6
6
|
before(:each) do
|
7
|
-
@collection
|
8
|
-
@data
|
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
|
10
|
+
@placeholder = "placeholder"
|
11
11
|
@html_options = {:class => "stylin"}
|
12
|
-
@options
|
12
|
+
@options = {:bars => {:show => true}}
|
13
13
|
|
14
|
-
@flot
|
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
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
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|
|
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|
|
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'
|
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"
|
78
|
+
f.options[:xAxis][:categories] = ["uno", "dos", "tres", "cuatro"]
|
79
79
|
end
|
80
|
-
chart.data.should ==
|
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"
|
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({
|
92
|
-
# without overriding
|
93
|
-
f.xAxis(:categories => ["uno"
|
94
|
-
f.chart({:defaultSeriesType=>"spline"
|
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"
|
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'
|
107
|
-
f.series(:name=>'Jane', :data=>[1, 3]
|
108
|
-
f.title({
|
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"
|
111
|
-
f.chart({:defaultSeriesType=>"spline"
|
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
|