lazy_high_charts 1.2.2 → 1.3.0.beta
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.
- data/CHANGELOG.md +8 -0
- data/GEM_VERSION +1 -0
- data/README.md +27 -4
- data/lazy_high_charts.gemspec +6 -5
- data/lib/lazy_high_charts.rb +1 -0
- data/lib/lazy_high_charts/high_chart.rb +11 -3
- data/lib/lazy_high_charts/layout_helper.rb +1 -1
- data/lib/lazy_high_charts/options_key_filter.rb +39 -0
- data/spec/high_chart_spec.rb +18 -0
- data/spec/options_key_filter_spec.rb +28 -0
- data/spec/spec_helper.rb +1 -0
- metadata +26 -8
- data/lib/lazy_high_charts/version.rb +0 -3
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
# VERSION 1.3.0.beta
|
2
|
+
* Oct 27,2012
|
3
|
+
1.merged hash deep merge patch
|
4
|
+
[#77](https://github.com/michelson/lazy_high_charts/issues/77)
|
5
|
+
2.enhance example case in README.md
|
6
|
+
[#78](https://github.com/michelson/lazy_high_charts/issues/78)
|
7
|
+
|
8
|
+
# VERSION 1.2.2
|
1
9
|
* Aug 31, 2012
|
2
10
|
1. Correct highchart js location
|
3
11
|
[issue#74](https://github.com/michelson/lazy_high_charts/issues/74)
|
data/GEM_VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.3.0.beta
|
data/README.md
CHANGED
@@ -36,7 +36,7 @@ About javascript Assets notes:
|
|
36
36
|
````
|
37
37
|
|
38
38
|
### For Rails 2.x/3.0.x
|
39
|
-
|
39
|
+
|
40
40
|
1. you need manually put jquery/highcharts js to public/javascript
|
41
41
|
2. modify your layout html
|
42
42
|
Sample Code:
|
@@ -82,6 +82,29 @@ Overriding entire option:
|
|
82
82
|
#.....
|
83
83
|
````
|
84
84
|
|
85
|
+
If you want to use this syntax and still be able to build option step-by-step without overriding:
|
86
|
+
|
87
|
+
````
|
88
|
+
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
89
|
+
#.....
|
90
|
+
f.xAxis!(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
|
91
|
+
f.chart!({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
92
|
+
#.....
|
93
|
+
````
|
94
|
+
|
95
|
+
Using the datetime axis type:
|
96
|
+
|
97
|
+
````
|
98
|
+
@h = LazyHighCharts::HighChart.new('graph', style: '') do |f|
|
99
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
100
|
+
f.options[:plotOptions] = {areaspline: {pointInterval: 1.day, pointStart: 10.days.ago}}
|
101
|
+
f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
|
102
|
+
f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9])
|
103
|
+
f.xAxis(type: :datetime)
|
104
|
+
end
|
105
|
+
````
|
106
|
+
A datetime axis [example](http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/xaxis/type-datetime/)
|
107
|
+
|
85
108
|
|
86
109
|
Usage in layout:
|
87
110
|
````
|
@@ -103,11 +126,11 @@ You can pass in additional javascript into to the view with a block, this will b
|
|
103
126
|
To include javascript function calls or callbacks you can use the js_code method on your string`"function".js_code`:
|
104
127
|
|
105
128
|
````
|
106
|
-
f.options[:plotOptions] = {
|
129
|
+
f.options[:plotOptions] = {
|
107
130
|
:column => { :events => { :click => %|function() { window.location = "http://www.highcharts.com" }|.js_code } }
|
108
131
|
}
|
109
132
|
````
|
110
|
-
|
133
|
+
|
111
134
|
|
112
135
|
## HighStock Support:
|
113
136
|
|
@@ -123,7 +146,7 @@ http://www.highcharts.com/ref/
|
|
123
146
|
## HighCharts License:
|
124
147
|
|
125
148
|
http://www.highcharts.com/license
|
126
|
-
|
149
|
+
|
127
150
|
|
128
151
|
## Contributing
|
129
152
|
|
data/lazy_high_charts.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
3
|
-
|
3
|
+
version = File.read(File.expand_path("../GEM_VERSION",__FILE__)).strip
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "lazy_high_charts"
|
7
|
-
s.version =
|
7
|
+
s.version = version
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ['Miguel Michelson Martinez','Deshi Xiao']
|
10
10
|
s.email = ['miguelmichelson@gmail.com','xiaods@gmail.com']
|
11
11
|
s.homepage = "https://github.com/xiaods/lazy_high_charts"
|
12
|
-
s.summary = "
|
13
|
-
s.description = "
|
12
|
+
s.summary = "rubyist way to render variant chart by highcharts without write javascript right now, rails gem library."
|
13
|
+
s.description = "lazy_high_charts is leading edge rubyist render charts gem for displaying Highcharts graphs."
|
14
14
|
|
15
15
|
s.extra_rdoc_files = [ "README.md", "CHANGELOG.md" ]
|
16
16
|
s.rdoc_options = [ "--charset=UTF-8" ]
|
@@ -18,9 +18,10 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.required_rubygems_version = "~> 1.3"
|
19
19
|
|
20
20
|
s.add_dependency "bundler", "~> 1.0"
|
21
|
+
s.add_dependency "hash-deep-merge"
|
21
22
|
|
22
23
|
s.description = <<-DESC
|
23
|
-
lazy_high_charts is
|
24
|
+
lazy_high_charts is leading edge rubyist render charts gem for displaying Highcharts graphs.
|
24
25
|
DESC
|
25
26
|
|
26
27
|
s.files = `git ls-files`.split("\n")
|
data/lib/lazy_high_charts.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts core_ext string])
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts options_key_filter])
|
2
3
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts high_chart])
|
3
4
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts layout_helper])
|
4
5
|
require File.join(File.dirname(__FILE__), *%w[lazy_high_charts railtie]) if defined?(::Rails::Railtie)
|
@@ -22,7 +22,7 @@ module LazyHighCharts
|
|
22
22
|
# title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
|
23
23
|
def defaults_options
|
24
24
|
self.title({ :text=>"example test title from highcharts gem"})
|
25
|
-
self.legend({ :layout=>"vertical", :style=>{} })
|
25
|
+
self.legend({ :layout=>"vertical", :style=>{} })
|
26
26
|
self.xAxis({})
|
27
27
|
self.yAxis({ :title=> {:text=> nil}, :labels=>{} })
|
28
28
|
self.tooltip({ :enabled=>true })
|
@@ -37,7 +37,11 @@ module LazyHighCharts
|
|
37
37
|
#
|
38
38
|
# For instance: <tt>high_chart.grid(:color => "#699")</tt>
|
39
39
|
def method_missing(meth, opts = {})
|
40
|
-
|
40
|
+
if meth.to_s.end_with? '!'
|
41
|
+
deep_merge_options meth[0..-2].to_sym, opts
|
42
|
+
else
|
43
|
+
merge_options meth, opts
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
# Add a simple series to the graph:
|
@@ -48,7 +52,7 @@ module LazyHighCharts
|
|
48
52
|
def series(opts = {})
|
49
53
|
@data ||= []
|
50
54
|
if not opts.empty?
|
51
|
-
@data << opts.merge(:name => opts[:name], :data => opts[:data])
|
55
|
+
@data << OptionsKeyFilter.filter(opts.merge(:name => opts[:name], :data => opts[:data]))
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
@@ -62,6 +66,10 @@ private
|
|
62
66
|
@options.merge! name => opts
|
63
67
|
end
|
64
68
|
|
69
|
+
def deep_merge_options(name, opts)
|
70
|
+
@options.deep_merge! name => opts
|
71
|
+
end
|
72
|
+
|
65
73
|
def arguments_to_options(args)
|
66
74
|
if args.blank?
|
67
75
|
{:show => true}
|
@@ -24,7 +24,7 @@ module LazyHighCharts
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def build_html_output(type, placeholder, object, &block)
|
27
|
-
options_collection = [ generate_json_from_hash(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
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# A way to filter certain keys of data provided to the LazyHighCharts#series method and the LazyHighCharts#options
|
3
|
+
#
|
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
|
7
|
+
#
|
8
|
+
# Be careful that it is OK to filter the hash keys you specify for every key of the options or series hash
|
9
|
+
#
|
10
|
+
module LazyHighCharts
|
11
|
+
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
|
19
|
+
|
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)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
[k, v]
|
30
|
+
end
|
31
|
+
Hash[new_options]
|
32
|
+
end
|
33
|
+
|
34
|
+
FILTER_MAP = {
|
35
|
+
method(:milliseconds) => [:pointInterval],
|
36
|
+
method(:date_to_js_code) => [:pointStart]
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
data/spec/high_chart_spec.rb
CHANGED
@@ -104,6 +104,24 @@ describe "HighChart" do
|
|
104
104
|
end
|
105
105
|
chart.options[:subtitle][:text].should == "Bar"
|
106
106
|
end
|
107
|
+
|
108
|
+
it 'should override entire option by default when resetting it again' do
|
109
|
+
chart = LazyHighCharts::HighChart.new('graph') do |f|
|
110
|
+
f.xAxis(categories: [3, 5, 7])
|
111
|
+
f.xAxis(title: {text: 'x title'})
|
112
|
+
end
|
113
|
+
chart.options[:xAxis][:categories].should == nil
|
114
|
+
chart.options[:xAxis][:title][:text].should == 'x title'
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should allow to build options step by step without overriding previously set values' do
|
118
|
+
chart = LazyHighCharts::HighChart.new('graph') do |f|
|
119
|
+
f.xAxis!(categories: [3, 5, 7])
|
120
|
+
f.xAxis!(title: {text: 'x title'})
|
121
|
+
end
|
122
|
+
chart.options[:xAxis][:categories].should == [3, 5, 7]
|
123
|
+
chart.options[:xAxis][:title][:text].should == 'x title'
|
124
|
+
end
|
107
125
|
|
108
126
|
end
|
109
127
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe LazyHighCharts::OptionsKeyFilter do
|
4
|
+
it "should filter :pointInterval from seconds to milliseconds" do
|
5
|
+
hash = LazyHighCharts::OptionsKeyFilter.filter(pointInterval: 1)
|
6
|
+
hash[:pointInterval].should == 1000
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "filters :pointStart from a Date to a JavaScript compatible string" do
|
10
|
+
before(:each) do
|
11
|
+
hash = LazyHighCharts::OptionsKeyFilter.filter(pointStart: Date.new(2012, 9, 13))
|
12
|
+
@value = hash[:pointStart]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be the correct string" do
|
16
|
+
@value.should == "Date.UTC(2012, 8, 13)"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be js_code" do
|
20
|
+
@value.js_code.should be_true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should filter keys recursively" do
|
25
|
+
hash = LazyHighCharts::OptionsKeyFilter.filter({something: {another_thing: {pointInterval: 2}}})
|
26
|
+
hash[:something][:another_thing][:pointInterval].should == 2000
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,6 +14,7 @@ require "active_support/core_ext"
|
|
14
14
|
|
15
15
|
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts'))
|
16
16
|
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts/layout_helper'))
|
17
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts/options_key_filter'))
|
17
18
|
|
18
19
|
require 'webrat'
|
19
20
|
require 'rspec'
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazy_high_charts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0.beta
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Miguel Michelson Martinez
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -28,8 +28,24 @@ dependencies:
|
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '1.0'
|
31
|
-
|
32
|
-
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: hash-deep-merge
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: ! ' lazy_high_charts is leading edge rubyist render charts gem for
|
48
|
+
displaying Highcharts graphs.
|
33
49
|
|
34
50
|
'
|
35
51
|
email:
|
@@ -44,6 +60,7 @@ files:
|
|
44
60
|
- .gitignore
|
45
61
|
- .rspec
|
46
62
|
- CHANGELOG.md
|
63
|
+
- GEM_VERSION
|
47
64
|
- Gemfile
|
48
65
|
- MIT-LICENSE
|
49
66
|
- README.md
|
@@ -56,11 +73,12 @@ files:
|
|
56
73
|
- lib/lazy_high_charts/core_ext/string.rb
|
57
74
|
- lib/lazy_high_charts/high_chart.rb
|
58
75
|
- lib/lazy_high_charts/layout_helper.rb
|
76
|
+
- lib/lazy_high_charts/options_key_filter.rb
|
59
77
|
- lib/lazy_high_charts/railtie.rb
|
60
|
-
- lib/lazy_high_charts/version.rb
|
61
78
|
- rails/init.rb
|
62
79
|
- spec/high_chart_spec.rb
|
63
80
|
- spec/lazy_high_charts_spec.rb
|
81
|
+
- spec/options_key_filter_spec.rb
|
64
82
|
- spec/spec_helper.rb
|
65
83
|
homepage: https://github.com/xiaods/lazy_high_charts
|
66
84
|
licenses: []
|
@@ -86,6 +104,6 @@ rubyforge_project:
|
|
86
104
|
rubygems_version: 1.8.24
|
87
105
|
signing_key:
|
88
106
|
specification_version: 3
|
89
|
-
summary:
|
107
|
+
summary: rubyist way to render variant chart by highcharts without write javascript
|
108
|
+
right now, rails gem library.
|
90
109
|
test_files: []
|
91
|
-
has_rdoc:
|