lazy_high_charts 1.0.6
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/.gitignore +12 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +13 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +83 -0
- data/Rakefile +15 -0
- data/autotest/discover.rb +1 -0
- data/init.rb +9 -0
- data/lazy_high_charts.gemspec +36 -0
- data/lib/generators/lazy_high_charts/install/install_generator.rb +14 -0
- data/lib/lazy_high_charts.rb +6 -0
- data/lib/lazy_high_charts/high_chart.rb +93 -0
- data/lib/lazy_high_charts/high_charts_helper.rb +46 -0
- data/lib/lazy_high_charts/version.rb +3 -0
- data/rails/init.rb +1 -0
- data/spec/high_chart_spec.rb +120 -0
- data/spec/lazy_high_charts_spec.rb +52 -0
- data/spec/spec_helper.rb +24 -0
- metadata +143 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Nov 30,2010
|
2
|
+
* dumped to gem 0.0.1
|
3
|
+
|
4
|
+
Sep 13,2010
|
5
|
+
* truely support rails 3.0(returning is deprecate function,use tap) deshi(xiaods@gmail.com)
|
6
|
+
|
7
|
+
Sep 14,2010
|
8
|
+
* update codebase to support rails3.0 and rspec2
|
9
|
+
|
10
|
+
|
11
|
+
Oct 8,2010
|
12
|
+
* update rake.it works now!
|
13
|
+
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2010 Miguel Michelson Martinez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
LazyHighCharts
|
2
|
+
=======
|
3
|
+
= update(Dec 4,2010)
|
4
|
+
bumping version to gem 0.0.3
|
5
|
+
|
6
|
+
- Test Environment
|
7
|
+
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
|
8
|
+
rspec 2.0
|
9
|
+
rails 3.0.1
|
10
|
+
- Result(autotest)
|
11
|
+
Finished in 0.01502 seconds
|
12
|
+
9 examples, 0 failures
|
13
|
+
|
14
|
+
Attention:
|
15
|
+
this gem Only support Rails 3.x
|
16
|
+
|
17
|
+
Usage
|
18
|
+
=======
|
19
|
+
In your Gemfile, add this line:
|
20
|
+
gem 'lazy_high_charts'
|
21
|
+
|
22
|
+
Usage in Controller:
|
23
|
+
|
24
|
+
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
25
|
+
f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
|
26
|
+
f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
Without overriding entire option , (only change a specific option index):
|
31
|
+
|
32
|
+
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
33
|
+
.....
|
34
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
35
|
+
f.options[:chart][:inverted] = true
|
36
|
+
f.options[:legend][:layout] = "horizontal"
|
37
|
+
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
|
38
|
+
......
|
39
|
+
|
40
|
+
Overriding entire option:
|
41
|
+
|
42
|
+
@h = LazyHighCharts::HighChart.new('graph') do |f|
|
43
|
+
.....
|
44
|
+
f.x_axis(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
|
45
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
46
|
+
.....
|
47
|
+
|
48
|
+
|
49
|
+
Usage in layout:
|
50
|
+
|
51
|
+
<%= javascript_include_tag 'highcharts' %>
|
52
|
+
<!--[if IE]>
|
53
|
+
<%= javascript_include_tag 'excanvas.compiled' %>
|
54
|
+
<![endif]-->
|
55
|
+
|
56
|
+
Usage in view:
|
57
|
+
|
58
|
+
<%= high_chart("my_id", @h) %>
|
59
|
+
|
60
|
+
Passing formatting options in the view to the helper block , because all the helper options declared in the controller are converted in strict/valid json (quoted key); so we need to extend the json object with some js.
|
61
|
+
|
62
|
+
<% high_chart("my_id", @h) do |c| %>
|
63
|
+
<%= "options.tooltip.formatter = function() { return '<b>HEY!!!'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +' units';}" %>
|
64
|
+
<%= "options.xAxis.labels.formatter = function() { return 'ho';}" %>
|
65
|
+
<%= "options.yAxis.labels.formatter = function() { return 'hey';}" %>
|
66
|
+
<%end %>
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
Option reference:
|
71
|
+
|
72
|
+
http://www.highcharts.com/ref/
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
h2.Contributors
|
78
|
+
LayHighCharts gem is maintained by "Deshi Xiao":https://github.com/xiaods
|
79
|
+
|
80
|
+
@git shortlog -n -s --no-merges@
|
81
|
+
|
82
|
+
|
83
|
+
Copyright (c) 2010 Miguel Michelson Martinez, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
desc 'Default: run specs.'
|
7
|
+
task :default => :spec
|
8
|
+
|
9
|
+
desc 'Run the specs'
|
10
|
+
if defined?(RSpec)
|
11
|
+
desc 'Test the Lazy_high_charts gem.'
|
12
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
13
|
+
t.pattern = FileList['spec/**/*_spec.rb']
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/init.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'LazyHighCharts'
|
3
|
+
require 'LazyHighCharts/high_charts_helper'
|
4
|
+
|
5
|
+
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :high_charts => ["highcharts"]
|
6
|
+
# ActionView::Helpers::AssetTagHelper.register_javascript_expansion :ie_high_charts => ["excanvas.compiled"]
|
7
|
+
|
8
|
+
ActionView::Base.send :include, LazyHighCharts::HighChartsHelper
|
9
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
#require File.expand_path("../lib/lazy_high_charts/version", __FILE__)
|
3
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
4
|
+
require 'lazy_high_charts/version'
|
5
|
+
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "lazy_high_charts"
|
9
|
+
s.version = LazyHighCharts::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ['Miguel Michelson Martinez','Deshi Xiao']
|
12
|
+
s.email = ['miguelmichelson@gmail.com','xiaods@gmail.com']
|
13
|
+
s.homepage = "https://github.com/xiaods/lazy_high_charts"
|
14
|
+
s.summary = "lazy higcharts plugin for rails"
|
15
|
+
s.description = "use highcharts js libary to visualization your data plugin for rails"
|
16
|
+
|
17
|
+
s.extra_rdoc_files = [ "README.md", "CHANGELOG.md" ]
|
18
|
+
s.rdoc_options = [ "--charset=UTF-8" ]
|
19
|
+
|
20
|
+
s.required_rubygems_version = ">= 1.3.6"
|
21
|
+
|
22
|
+
s.add_dependency "bundler", "~> 1.0"
|
23
|
+
|
24
|
+
s.add_development_dependency "webrat", "~> 0.7"
|
25
|
+
s.add_development_dependency "rspec", "~> 2.0"
|
26
|
+
s.add_development_dependency "rails", "~> 3.0"
|
27
|
+
|
28
|
+
s.description = <<-DESC
|
29
|
+
Lazy_high_charts provides a Rails interface for utilize highcharts to displaying graphs.
|
30
|
+
DESC
|
31
|
+
|
32
|
+
s.files = `git ls-files`.split("\n")
|
33
|
+
s.executables = `git ls-files`.split("\n").select{|f| f =~ /^bin/}
|
34
|
+
s.require_path = 'lib'
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LazyHighCharts
|
2
|
+
class InstallGenerator < Rails::Generators::Base
|
3
|
+
desc "This generator install highcharts javascripts"
|
4
|
+
@@version = "2.1.1"
|
5
|
+
|
6
|
+
def install_highcharts
|
7
|
+
say_status("installing", "Highcharts javascript (github HEAD)", :green)
|
8
|
+
get "https://github.com/highslide-software/highcharts.com/raw/master/js/highcharts.src.js","public/javascripts/highcharts.js"
|
9
|
+
rescue OpenURI::HTTPError
|
10
|
+
say_status("warning", "could not find Highcharts javascript file", :yellow)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module LazyHighCharts
|
2
|
+
class HighChart
|
3
|
+
CANVAS_DEFAULT_HTML_OPTIONS = {:style => "height: 300px, width:615px" }
|
4
|
+
SERIES_OPTIONS = %w(lines points bars shadowSize colors)
|
5
|
+
|
6
|
+
attr_accessor :data, :options, :placeholder, :html_options
|
7
|
+
alias :canvas :placeholder
|
8
|
+
alias :canvas= :placeholder=
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(canvas = nil, html_opts = {})
|
12
|
+
|
13
|
+
@collection_filter = nil
|
14
|
+
self.tap do |high_chart|
|
15
|
+
high_chart.data ||= []
|
16
|
+
high_chart.options ||= {}
|
17
|
+
high_chart.defaults_options
|
18
|
+
high_chart.html_options = html_opts.reverse_merge(CANVAS_DEFAULT_HTML_OPTIONS)
|
19
|
+
high_chart.canvas = canvas if canvas
|
20
|
+
yield high_chart if block_given?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# title: legend: xAxis: yAxis: tooltip: credits: :plotOptions
|
25
|
+
|
26
|
+
def defaults_options
|
27
|
+
self.title({ :text=>"example test title from highcharts gem"})
|
28
|
+
self.legend({:layout=>"vertical", :style=>{:position=>'absolute', :bottom=>'auto', :left=>'150px', :top=>'150px'} , :borderWidth=> 1,
|
29
|
+
:backgroundColor=>'#FFFFFF'})
|
30
|
+
self.x_axis(
|
31
|
+
{:categories=> ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
|
32
|
+
:plotBands=> [{
|
33
|
+
:from=> 6.0,:to=> 6.5,:color=> 'rgba(68, 170, 213, .2)'
|
34
|
+
}],
|
35
|
+
:labels=>{ :align=>'right',:rotation=>45 }
|
36
|
+
})
|
37
|
+
self.y_axis({:title=> {:text=> 'Fruit units'}, :labels=>{:align=>'right'} })
|
38
|
+
self.tooltip({ :enabled=>true })
|
39
|
+
self.credits({:enabled => false})
|
40
|
+
self.plot_options({
|
41
|
+
:areaspline => {
|
42
|
+
:fillOpacity => 0.5
|
43
|
+
}
|
44
|
+
})
|
45
|
+
self.chart({:defaultSeriesType=>"areaspline" , :renderTo => nil})
|
46
|
+
self.subtitle({})
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Pass other methods through to the javascript high_chart object.
|
51
|
+
#
|
52
|
+
# For instance: <tt>high_chart.grid(:color => "#699")</tt>
|
53
|
+
#
|
54
|
+
def method_missing(meth, opts = {})
|
55
|
+
merge_options meth, opts
|
56
|
+
end
|
57
|
+
|
58
|
+
# Add a simple series to the graph:
|
59
|
+
#
|
60
|
+
# data = [[0,5], [1,5], [2,5]]
|
61
|
+
# @high_chart.series :name=>'Updated', :data=>data
|
62
|
+
# @high_chart.series :name=>'Updated', :data=>[5, 1, 6, 1, 5, 4, 9]
|
63
|
+
#
|
64
|
+
def series(opts = {})
|
65
|
+
@data ||= []
|
66
|
+
if opts.blank?
|
67
|
+
@data << series_options.merge(:name => label, :data => d)
|
68
|
+
else
|
69
|
+
@data << opts.merge(:name => opts[:name], :data => opts[:data])
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
def series_options
|
75
|
+
@options.reject {|k,v| SERIES_OPTIONS.include?(k.to_s) == false}
|
76
|
+
end
|
77
|
+
|
78
|
+
def merge_options(name, opts)
|
79
|
+
@options.merge! name => opts
|
80
|
+
end
|
81
|
+
|
82
|
+
def arguments_to_options(args)
|
83
|
+
if args.blank?
|
84
|
+
{:show => true}
|
85
|
+
elsif args.is_a? Array
|
86
|
+
args.first
|
87
|
+
else
|
88
|
+
args
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module LazyHighCharts
|
4
|
+
module HighChartsHelper
|
5
|
+
# ActiveSupport::JSON.unquote_hash_key_identifiers = false
|
6
|
+
def high_chart(placeholder, object , &block)
|
7
|
+
object.html_options.merge!({:id=>placeholder})
|
8
|
+
object.options[:chart][:renderTo] = placeholder
|
9
|
+
high_graph(placeholder,object , &block).concat(content_tag("div","", object.html_options))
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def high_graph(placeholder, object, &block)
|
14
|
+
graph =<<-EOJS
|
15
|
+
<script type="text/javascript">
|
16
|
+
jQuery(function() {
|
17
|
+
// 1. Define JSON options
|
18
|
+
var options = {
|
19
|
+
chart: #{object.options[:chart].to_json},
|
20
|
+
title: #{object.options[:title].to_json},
|
21
|
+
legend: #{object.options[:legend].to_json},
|
22
|
+
xAxis: #{object.options[:x_axis].to_json},
|
23
|
+
yAxis: #{object.options[:y_axis].to_json},
|
24
|
+
tooltip: #{object.options[:tooltip].to_json},
|
25
|
+
credits: #{object.options[:credits].to_json},
|
26
|
+
plotOptions: #{object.options[:plot_options].to_json},
|
27
|
+
series: #{object.data.to_json},
|
28
|
+
subtitle: #{object.options[:subtitle].to_json}
|
29
|
+
};
|
30
|
+
|
31
|
+
// 2. Add callbacks (non-JSON compliant)
|
32
|
+
#{capture(&block) if block_given?}
|
33
|
+
// 3. Build the chart
|
34
|
+
var chart = new Highcharts.Chart(options);
|
35
|
+
});
|
36
|
+
</script>
|
37
|
+
EOJS
|
38
|
+
if defined?(raw)
|
39
|
+
return raw(graph)
|
40
|
+
else
|
41
|
+
return graph
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require '../init'
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
Record = Struct.new(:frequency, :amplitude)
|
4
|
+
|
5
|
+
|
6
|
+
describe "HighChart" do
|
7
|
+
before(:each) do
|
8
|
+
@collection = [Record.new(1,15), Record.new(2,30), Record.new(4,40)]
|
9
|
+
@data = [ [1,15], [2,30], [4,40]]
|
10
|
+
|
11
|
+
@placeholder = "placeholder"
|
12
|
+
@html_options = {:class => "stylin"}
|
13
|
+
@options = {:bars => {:show => true}}
|
14
|
+
|
15
|
+
@flot = LazyHighCharts::HighChart.new(@placeholder, @html_options) {|chart| chart.options = @options }
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
# this is almost all flotomatic stuff
|
21
|
+
describe "initialization" do
|
22
|
+
it "should take an optional 'placeholder' argument" do
|
23
|
+
LazyHighCharts::HighChart.new(@placeholder).placeholder.should == @placeholder
|
24
|
+
LazyHighCharts::HighChart.new.placeholder.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should take an optional html_options argument (defaulting to 300px height)" do
|
28
|
+
LazyHighCharts::HighChart.new(@html_options).placeholder.should == @html_options
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should set options by default" do
|
32
|
+
LazyHighCharts::HighChart.new.options.should == {
|
33
|
+
:subtitle=>{},
|
34
|
+
:chart=>{:renderTo=>nil, :defaultSeriesType=>"areaspline"},
|
35
|
+
:plot_options=>{:areaspline=>{:fillOpacity=>0.5}},
|
36
|
+
:legend=>{
|
37
|
+
:borderWidth=>1,
|
38
|
+
:backgroundColor=>"#FFFFFF",
|
39
|
+
:layout=>"vertical",
|
40
|
+
:style=>{:top=>"150px",
|
41
|
+
:left=>"150px", :position=>"absolute", :bottom=>"auto"}
|
42
|
+
},
|
43
|
+
:tooltip=>{:enabled=>true},
|
44
|
+
:x_axis=>{
|
45
|
+
:categories=>["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
|
46
|
+
:plotBands=>[{:to=>6.5, :from=>6.0, :color=>"rgba(68, 170, 213, .2)"}],
|
47
|
+
:labels=>{:align=>"right", :rotation=>45}},
|
48
|
+
:y_axis=>{:title=>{:text=>"Fruit units"},
|
49
|
+
:labels=>{:align=>"right"}},
|
50
|
+
:title=>{:text=>"example test title from highcharts gem"},
|
51
|
+
:credits=>{:enabled=>false}
|
52
|
+
}
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should set data empty by default" do
|
57
|
+
LazyHighCharts::HighChart.new.data.should == []
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should take a block setting attributes" do
|
61
|
+
chart = LazyHighCharts::HighChart.new {|f| f.data = @data ; f.options = @options }
|
62
|
+
chart.data.should == @data
|
63
|
+
chart.options.should == @options
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should take a block setting attributes" do
|
67
|
+
chart = LazyHighCharts::HighChart.new {|f| f.options[:legend][:layout] = "horizontal" }
|
68
|
+
chart.options[:legend][:layout].should == "horizontal"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should change a block data without overriding options" do
|
72
|
+
chart = LazyHighCharts::HighChart.new('graph') do |f|
|
73
|
+
f.series(:name=>'John', :data=>[3, 20])
|
74
|
+
f.series(:name=>'Jane',:data=> [1, 3] )
|
75
|
+
# without overriding
|
76
|
+
f.options[:chart][:defaultSeriesType] = "area"
|
77
|
+
f.options[:chart][:inverted] = true
|
78
|
+
f.options[:legend][:layout] = "horizontal"
|
79
|
+
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
|
80
|
+
end
|
81
|
+
chart.data.should == [{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
|
82
|
+
chart.options[:legend][:layout].should == "horizontal"
|
83
|
+
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
|
84
|
+
chart.options[:chart][:defaultSeriesType].should == "area"
|
85
|
+
chart.options[:chart][:inverted].should == true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should change a block data with overriding entire options" do
|
89
|
+
chart = LazyHighCharts::HighChart.new('graph') do |f|
|
90
|
+
f.series(:name=>'John', :data=>[3, 20])
|
91
|
+
f.series(:name=>'Jane', :data=>[1, 3] )
|
92
|
+
f.title({ :text=>"example test title from controller"})
|
93
|
+
# without overriding
|
94
|
+
f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
|
95
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
96
|
+
end
|
97
|
+
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
|
98
|
+
chart.options[:x_axis][:labels][:rotation].should == -45
|
99
|
+
chart.options[:x_axis][:labels][:align].should == "right"
|
100
|
+
chart.options[:chart][:defaultSeriesType].should == "spline"
|
101
|
+
chart.options[:chart][:renderTo].should == "myRenderArea"
|
102
|
+
chart.options[:chart][:inverted].should == true
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should have subtitles" do
|
106
|
+
chart = LazyHighCharts::HighChart.new('graph') do |f|
|
107
|
+
f.series(:name=>'John',:data=> [3, 20])
|
108
|
+
f.series(:name=>'Jane', :data=>[1, 3] )
|
109
|
+
f.title({ :text=>"example test title from controller"})
|
110
|
+
# without overriding
|
111
|
+
f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
|
112
|
+
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
|
113
|
+
f.subtitle({:text=>"Bar"})
|
114
|
+
end
|
115
|
+
chart.options[:subtitle][:text].should == "Bar"
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
3
|
+
require 'pp'
|
4
|
+
|
5
|
+
describe HighChartsHelper do
|
6
|
+
include HighChartsHelper
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
@class = "stylin"
|
10
|
+
@placeholder = "placeholder"
|
11
|
+
@chart = LazyHighCharts::HighChart.new(@placeholder)
|
12
|
+
@data = "data"
|
13
|
+
@options = "options"
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "high_chart_helper" do
|
17
|
+
it "should return a div with an id of high_chart object" do
|
18
|
+
hc = LazyHighCharts::HighChart.new("placeholder", :class => 'stylin')
|
19
|
+
high_chart(hc.placeholder, hc).should have_selector('div', :id => hc.placeholder, :class => 'stylin')
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a script" do
|
23
|
+
hc = LazyHighCharts::HighChart.new("placeholder")
|
24
|
+
high_chart(hc.placeholder, hc).should have_selector('script')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "high_chart_graph" do
|
29
|
+
describe "ready function" do
|
30
|
+
it "should be a javascript script" do
|
31
|
+
high_chart(@placeholder, @chart).should have_selector('script', :type => 'text/javascript')
|
32
|
+
high_chart(@placeholder, @chart).should match(/\}\s*\)\s*;/)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should generate generate ready function (no conflict with prototype)" do
|
36
|
+
high_chart(@placeholder, @chart).should match(/jQuery\(function\(\)\s*\{/)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
describe "initialize HighChart" do
|
40
|
+
it "should set Chart data" do
|
41
|
+
high_chart(@placeholder, @chart).should match(/var\s+chart\s+=\s+new\s+Highcharts.Chart/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should set chart renderTo" do
|
45
|
+
high_chart(@placeholder, @chart).should match(/\"renderTo\":\"placeholder\"/)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
|
6
|
+
require 'active_support'
|
7
|
+
require 'action_pack'
|
8
|
+
require 'action_view'
|
9
|
+
require 'action_controller'
|
10
|
+
#require 'action_mailer'
|
11
|
+
|
12
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts'))
|
13
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/lazy_high_charts/high_charts_helper'))
|
14
|
+
|
15
|
+
require 'webrat'
|
16
|
+
require 'rspec'
|
17
|
+
Rspec.configure do |config|
|
18
|
+
config.include ActionView::Helpers
|
19
|
+
config.include Webrat::Matchers
|
20
|
+
end
|
21
|
+
|
22
|
+
module HighChartsHelper
|
23
|
+
include ActionView::Helpers::TagHelper
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lazy_high_charts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 6
|
9
|
+
version: 1.0.6
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Miguel Michelson Martinez
|
13
|
+
- Deshi Xiao
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-05 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: "1.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: webrat
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 7
|
46
|
+
version: "0.7"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 2
|
59
|
+
- 0
|
60
|
+
version: "2.0"
|
61
|
+
type: :development
|
62
|
+
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rails
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
segments:
|
72
|
+
- 3
|
73
|
+
- 0
|
74
|
+
version: "3.0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: " Lazy_high_charts provides a Rails interface for utilize highcharts to displaying graphs.\n"
|
78
|
+
email:
|
79
|
+
- miguelmichelson@gmail.com
|
80
|
+
- xiaods@gmail.com
|
81
|
+
executables: []
|
82
|
+
|
83
|
+
extensions: []
|
84
|
+
|
85
|
+
extra_rdoc_files:
|
86
|
+
- README.md
|
87
|
+
- CHANGELOG.md
|
88
|
+
files:
|
89
|
+
- .gitignore
|
90
|
+
- .rspec
|
91
|
+
- CHANGELOG.md
|
92
|
+
- Gemfile
|
93
|
+
- MIT-LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- autotest/discover.rb
|
97
|
+
- init.rb
|
98
|
+
- lazy_high_charts.gemspec
|
99
|
+
- lib/generators/lazy_high_charts/install/install_generator.rb
|
100
|
+
- lib/lazy_high_charts.rb
|
101
|
+
- lib/lazy_high_charts/high_chart.rb
|
102
|
+
- lib/lazy_high_charts/high_charts_helper.rb
|
103
|
+
- lib/lazy_high_charts/version.rb
|
104
|
+
- rails/init.rb
|
105
|
+
- spec/high_chart_spec.rb
|
106
|
+
- spec/lazy_high_charts_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
has_rdoc: true
|
109
|
+
homepage: https://github.com/xiaods/lazy_high_charts
|
110
|
+
licenses: []
|
111
|
+
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- --charset=UTF-8
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
segments:
|
131
|
+
- 1
|
132
|
+
- 3
|
133
|
+
- 6
|
134
|
+
version: 1.3.6
|
135
|
+
requirements: []
|
136
|
+
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 1.3.7
|
139
|
+
signing_key:
|
140
|
+
specification_version: 3
|
141
|
+
summary: lazy higcharts plugin for rails
|
142
|
+
test_files: []
|
143
|
+
|