Skip to content

Commit

Permalink
merging xiaods gem
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Sep 23, 2011
2 parents 8da9e69 + 90281c6 commit e477109
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 85 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
@@ -1,3 +1,6 @@
* Jul 14, 2011
add support rails 3.1 rc4 now

* Jul 13, 2011
HighStock support
remove some defaults
Expand All @@ -14,7 +17,6 @@
Sep 14,2010
* update codebase to support rails3.0 and rspec2


Oct 8,2010
* update rake.it works now!

60 changes: 32 additions & 28 deletions README.md
@@ -1,18 +1,9 @@
LazyHighCharts
=======
update(Dec 4,2010)

- Test Environment
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
rspec 2.0
rails 3.0.1
- Result(autotest)
Finished in 0.01502 seconds
9 examples, 0 failures
LazyHighCharts is Rails 2.x/3.x Gem for displaying Highcharts graphs.


Attention:
This gem only supports Rails 3.x
Now Support Rails 3.1 rc4 stable branch,Happy useful
=======
### Installation instructions for Rails 3
Add this line to your Gemfile:
Expand All @@ -27,15 +18,36 @@ And then run this to install the javascript files:

rails plugin install git://github.com/michelson/lazy_high_charts.git ##(for rails 3)

#HighStocks
LazyHighCharts now compatible with beta HighStock, http://www.highcharts.com/stock/demo/

### HighStocks
LazyHighCharts now compatible with beta HighStock, http://www.highcharts.com/stock/demo/

Usage
=======

About javascript Assets notes:
for Rails 2.x/3.x
1.you need manually put jquery/highcharts js to public/javascript
2.modify your layout html
Sample Code:
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag :high_charts %>
3. add gem name in your config/environment.rb
config.gem "lazy_high_charts"
4.done!

For Rails 3.x
In your Gemfile, add this line:
gem 'lazy_high_charts'

For Rails 3.1
In your Gemfile, add this line:
gem 'lazy_high_charts', '~> 1.1.5'
then execuate command:
Rails g lazy_high_charts:install

Usage in Controller:

@h = LazyHighCharts::HighChart.new('graph') do |f|
f.options[:chart][:defaultSeriesType] = "area"
f.series(:name=>'John', :data=>[3, 20, 3, 5, 4, 10, 12 ,3, 5,6,7,7,80,9,9])
f.series(:name=>'Jane', :data=> [1, 3, 4, 3, 3, 5, 4,-46,7,8,8,9,9,0,0,9] )
end
Expand All @@ -48,47 +60,40 @@ Usage
f.options[:chart][:defaultSeriesType] = "area"
f.options[:chart][:inverted] = true
f.options[:legend][:layout] = "horizontal"
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
......

Overriding entire option:

@h = LazyHighCharts::HighChart.new('graph') do |f|
.....
f.x_axis(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
f.xAxis(:categories => @days.reverse! , :labels=>{:rotation=>-45 , :align => 'right'})
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
.....


Usage in layout:

<%= javascript_include_tag 'highcharts' %>
<!--[if IE]>
<%= javascript_include_tag 'excanvas.compiled' %>
<![endif]-->
<%= javascript_include_tag :high_charts %>

Usage in view:

<%= high_chart("my_id", @h) %>

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.

<% high_chart("my_id", @h) do |c| %>
<%= high_chart("my_id", @h) do |c| %>
<%= "options.tooltip.formatter = function() { return '<b>HEY!!!'+ this.series.name +'</b><br/>'+ this.x +': '+ this.y +' units';}" %>
<%= "options.xAxis.labels.formatter = function() { return 'ho';}" %>
<%= "options.yAxis.labels.formatter = function() { return 'hey';}" %>
<%end %>



HighStock Support:

##just call HighChart Helper this way:

<%= high_stock("my_id", @h) %>


Option reference:

http://www.highcharts.com/ref/
Expand All @@ -101,7 +106,6 @@ Usage
Contributors
=======
LazyHighCharts gem is maintained by "Deshi Xiao":https://github.com/xiaods
git shortlog -n -s --no-merges

Run @git shortlog -n -s --no-merges@ to see the awesome.

Copyright (c) 2010 Miguel Michelson Martinez, released under the MIT license
15 changes: 7 additions & 8 deletions Rakefile
@@ -1,15 +1,14 @@
require 'bundler'
Bundler::GemHelper.install_tasks
# encoding: utf-8
require 'rubygems'
require 'rake/dsl_definition'
require 'rake'
require 'rspec/core/rake_task'
require 'bundler'

desc 'Default: run specs.'
task :default => :spec

desc 'Run the specs'
if defined?(RSpec)
desc 'Test the Lazy_high_charts gem.'
RSpec::Core::RakeTask.new('spec') do |t|
t.pattern = FileList['spec/**/*_spec.rb']
end
desc 'Test the Lazy_high_charts gem.'
RSpec::Core::RakeTask.new('spec') do |t|
t.pattern = FileList['spec/**/*_spec.rb']
end
1 change: 0 additions & 1 deletion init.rb
Expand Up @@ -3,4 +3,3 @@
require 'lazy_high_charts/layout_helper'
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :high_charts => ["highcharts"]
ActionView::Base.send :include, LazyHighCharts::LayoutHelper

10 changes: 5 additions & 5 deletions lazy_high_charts.gemspec
Expand Up @@ -10,22 +10,22 @@ Gem::Specification.new do |s|
s.authors = ['Miguel Michelson Martinez','Deshi Xiao']
s.email = ['miguelmichelson@gmail.com','xiaods@gmail.com']
s.homepage = "https://github.com/xiaods/lazy_high_charts"
s.summary = "lazy higcharts plugin for rails"
s.description = "use highcharts js libary to visualization your data plugin for rails"
s.summary = "lazy higcharts gem for rails"
s.description = "use highcharts js libary to visualization your data by rubygem/rails"

s.extra_rdoc_files = [ "README.md", "CHANGELOG.md" ]
s.rdoc_options = [ "--charset=UTF-8" ]

s.required_rubygems_version = ">= 1.3.6"
s.required_rubygems_version = "~> 1.3"

s.add_dependency "bundler", "~> 1.0"

s.add_development_dependency "webrat", "~> 0.7"
s.add_development_dependency "webrat","~> 0.7"
s.add_development_dependency "rspec", "~> 2.0"
s.add_development_dependency "rails", "~> 3.0"

s.description = <<-DESC
Lazy_high_charts provides a Rails interface for utilize highcharts to displaying graphs.
lazy_high_charts is a Rails 3.x gem for displaying Highcharts graphs.
DESC

s.files = `git ls-files`.split("\n")
Expand Down
11 changes: 7 additions & 4 deletions lib/generators/lazy_high_charts/install/install_generator.rb
@@ -1,14 +1,17 @@
module LazyHighCharts
class InstallGenerator < Rails::Generators::Base
desc "This generator install highcharts javascripts"
@@version = "2.1.1"

def install_highcharts(opts = nil)
say_status("installing", "Highcharts javascript (github STOCK branch)", :green)
get "https://raw.github.com/highslide-software/highcharts.com/stock/js/highcharts.src.js","public/javascripts/highcharts.js"
rescue OpenURI::HTTPError
if ::Rails::VERSION::MAJOR == 3 && ::Rails::VERSION::MINOR >= 1
get "http://highcharts.com/js/highstock.js","app/assets/javascripts/highcharts.js"
else
get "https://raw.github.com/highslide-software/highcharts.com/stock/js/highcharts.src.js","public/javascripts/highcharts.js"
end
rescue OpenURI::HTTPError
say_status("warning", "could not find Highcharts javascript file", :yellow)
end

end
end
end
10 changes: 5 additions & 5 deletions lib/lazy_high_charts/high_chart.rb
@@ -1,6 +1,6 @@
module LazyHighCharts
class HighChart
CANVAS_DEFAULT_HTML_OPTIONS = {:style => "height: 300px, width:615px" }
CANVAS_DEFAULT_HTML_OPTIONS = { :style => "height: 300px, width:615px" }
SERIES_OPTIONS = %w(lines points bars shadowSize colors)

attr_accessor :data, :options, :placeholder, :html_options
Expand All @@ -25,12 +25,12 @@ def initialize(canvas = nil, html_opts = {})
def defaults_options
self.title({ :text=>"example test title from highcharts gem"})
self.legend({ :layout=>"vertical", :style=>{} })
self.x_axis({})
self.y_axis({ :title=> {:text=> nil}, :labels=>{} })
self.xAxis({})
self.yAxis({ :title=> {:text=> nil}, :labels=>{} })
self.tooltip({ :enabled=>true })
self.credits({ :enabled => false})
self.plot_options({ :areaspline => { } })
self.chart({ :defaultSeriesType=>nil , :renderTo => nil})
self.plotOptions({ :areaspline => { } })
self.chart({ :defaultSeriesType=>"areaspline" , :renderTo => nil})
self.subtitle({})
end

Expand Down
2 changes: 0 additions & 2 deletions lib/lazy_high_charts/layout_helper.rb
@@ -1,5 +1,4 @@
# coding: utf-8

module LazyHighCharts
module LayoutHelper

Expand Down Expand Up @@ -53,4 +52,3 @@ def build_html_output(type, placeholder, object, &block)
end
end
end

19 changes: 12 additions & 7 deletions lib/lazy_high_charts/railtie.rb
@@ -1,15 +1,20 @@
# encoding: utf-8

require 'lazy_high_charts'
require 'lazy_high_charts/layout_helper.rb'

require 'rails'

module LazyHighCharts
class Railtie < Rails::Railtie
initializer 'lazy_high_charts.initialize', :after => :after_initialize do
ActionView::Base.send :include, LazyHighCharts::LayoutHelper
ActionView::Base.send(:include, LazyHighCharts::LayoutHelper)

class Railtie < ::Rails::Railtie
config.before_configuration do
config.action_view.javascript_expansions[:high_charts] = %w(highcharts)
end

initializer 'lazy_high_charts.initialize' do
ActiveSupport.on_load(:action_view) do
include LazyHighCharts::LayoutHelper
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/lazy_high_charts/version.rb
@@ -1,3 +1,3 @@
module LazyHighCharts
VERSION = "1.0.8"
VERSION = "1.1.5"
end
2 changes: 1 addition & 1 deletion rails/init.rb
@@ -1,2 +1,2 @@
# encoding: utf-8
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
require File.expand_path(File.join(File.dirname(__FILE__), "..", "init"))
36 changes: 16 additions & 20 deletions spec/high_chart_spec.rb
Expand Up @@ -2,7 +2,6 @@

Record = Struct.new(:frequency, :amplitude)


describe "HighChart" do
before(:each) do
@collection = [Record.new(1,15), Record.new(2,30), Record.new(4,40)]
Expand All @@ -15,8 +14,6 @@
@flot = LazyHighCharts::HighChart.new(@placeholder, @html_options) {|chart| chart.options = @options }
end



# this is almost all flotomatic stuff
describe "initialization" do
it "should take an optional 'placeholder' argument" do
Expand All @@ -30,16 +27,15 @@

it "should set options by default" do
LazyHighCharts::HighChart.new.options.should == {
:plot_options=>{:areaspline=>{}},
:x_axis=>{},
:chart=>{:defaultSeriesType=>nil, :renderTo=>nil},
:y_axis=>{:title=>{:text=>nil},
:labels=>{}},
:title=>{:text=>"example test title from highcharts gem"},
:subtitle=>{},
:credits=>{:enabled=>false},
:legend=>{:layout=>"vertical", :style=>{}},
:tooltip=>{:enabled=>true}}
:title=>{:text=>"example test title from highcharts gem"},
:legend=>{:layout=>"vertical", :style=>{}},
:xAxis=>{},
:yAxis=>{:title=>{:text=>nil}, :labels=>{}},
:tooltip=>{:enabled=>true},
:credits=>{:enabled=>false},
:plotOptions=>{:areaspline=>{}},
:chart=>{:defaultSeriesType=>"areaspline", :renderTo=>nil},
:subtitle=>{}}
end

it "should set data empty by default" do
Expand Down Expand Up @@ -70,11 +66,11 @@
f.options[:chart][:defaultSeriesType] = "area"
f.options[:chart][:inverted] = true
f.options[:legend][:layout] = "horizontal"
f.options[:x_axis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
f.options[:xAxis][:categories] = ["uno" ,"dos" , "tres" , "cuatro"]
end
chart.data.should == [{:name=>"John", :data=>[3, 20]}, {:name=>"Jane", :data=>[1, 3]}]
chart.options[:legend][:layout].should == "horizontal"
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
chart.options[:xAxis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
chart.options[:chart][:defaultSeriesType].should == "area"
chart.options[:chart][:inverted].should == true
end
Expand All @@ -85,12 +81,12 @@
f.series(:name=>'Jane', :data=>[1, 3] )
f.title({ :text=>"example test title from controller"})
# without overriding
f.x_axis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
f.xAxis(:categories => ["uno" ,"dos" , "tres" , "cuatro"] , :labels=>{:rotation=>-45 , :align => 'right'})
f.chart({:defaultSeriesType=>"spline" , :renderTo => "myRenderArea" , :inverted => true})
end
chart.options[:x_axis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
chart.options[:x_axis][:labels][:rotation].should == -45
chart.options[:x_axis][:labels][:align].should == "right"
chart.options[:xAxis][:categories].should == ["uno" ,"dos" , "tres" , "cuatro"]
chart.options[:xAxis][:labels][:rotation].should == -45
chart.options[:xAxis][:labels][:align].should == "right"
chart.options[:chart][:defaultSeriesType].should == "spline"
chart.options[:chart][:renderTo].should == "myRenderArea"
chart.options[:chart][:inverted].should == true
Expand All @@ -111,4 +107,4 @@

end

end
end
1 change: 0 additions & 1 deletion spec/lazy_high_charts_spec.rb
@@ -1,6 +1,5 @@
# coding: utf-8
require File.dirname(__FILE__) + '/spec_helper'
require 'pp'

describe HighChartsHelper do
include LazyHighCharts::LayoutHelper
Expand Down

0 comments on commit e477109

Please sign in to comment.