highcharts-js-rails 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  *.gem
2
2
  .bundle
3
+ .rvmrc
3
4
  Gemfile.lock
5
+ coverage/
4
6
  pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/LICENSE CHANGED
@@ -4,4 +4,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
4
 
5
5
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
6
 
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Highcharts::VERSION
8
8
  s.authors = ['Alex Robbin']
9
9
  s.email = ['agrobbin@gmail.com']
10
- s.homepage = 'http://github.com/agrobbin/highcharts-js-rails'
10
+ s.homepage = 'https://github.com/agrobbin/highcharts-js-rails'
11
11
  s.summary = %q{Easily configure a Highcharts JS chart for use in a Rails application}
12
12
  s.description = s.summary
13
13
 
@@ -18,9 +18,10 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ['lib']
20
20
 
21
+ s.add_dependency 'actionpack', '~> 3.0'
22
+ s.add_dependency 'railties', '~> 3.0'
21
23
  s.add_development_dependency 'bundler'
22
- s.add_development_dependency 'simplecov'
23
24
  s.add_development_dependency 'rake'
24
25
  s.add_development_dependency 'rspec'
25
- s.add_dependency 'actionpack', '~> 3.0'
26
+ s.add_development_dependency 'simplecov'
26
27
  end
data/lib/highcharts.rb CHANGED
@@ -1,8 +1,3 @@
1
- require 'highcharts/axis'
2
- require 'highcharts/base'
3
- require 'highcharts/chart'
4
- require 'highcharts/legend'
5
- require 'highcharts/plot_options'
6
- require 'highcharts/rails'
7
- require 'highcharts/series'
8
- require 'highcharts/version'
1
+ require 'rails'
2
+
3
+ %w(base axis chart legend plot_options rails series version).each {|f| require "highcharts/#{f}"}
@@ -1,48 +1,49 @@
1
1
  module Highcharts
2
2
  class Axis < Base
3
-
3
+
4
4
  attr_accessor :title, :categories, :tickInterval, :min, :max, :labels, :opposite
5
-
5
+
6
6
  def to_s
7
7
  "{" +
8
8
  [render_title, render_categories, render_tickInterval, render_options(:objects => 'min max opposite'), render_labels].flatten.compact.join(',') +
9
9
  "}"
10
10
  end
11
-
12
- def render_title
13
- title.present? ? "title: {text: '#{title}'}" : nil
14
- end
15
-
16
- def render_categories
17
- return nil unless categories.present?
18
- "categories: [#{categories.collect {|c| "'#{format_category(c)}'"}.join(', ')}]" # need to encapsulate each category in quotes and format it before joining them with a comma
19
- end
20
-
21
- def render_tickInterval
22
- return tickInterval if tickInterval.present?
23
- return nil unless categories.present?
24
- "tickInterval: #{(Math.sqrt(categories.length) < 5 ? 1 : Math.sqrt(categories.length)).floor}"
25
- end
26
-
27
- def format_category(category)
28
- case category
29
- when Date
30
- category.strftime("%b. %d")
31
- when Time
32
- category.strftime("%H:%M")
33
- when DateTime
34
- category.strftime("%b. %d, %H:%M")
35
- else
36
- category.to_s
11
+
12
+ private
13
+ def render_title
14
+ title.present? ? "title: {text: '#{title}'}" : nil
37
15
  end
38
- end
39
-
40
- def render_labels
41
- return nil unless labels.present?
42
- "labels: {" +
43
- "formatter: function(){ return '#{labels[:prepend]}' + this.value + '#{labels[:append]}'; }" +
44
- "}"
45
- end
46
-
16
+
17
+ def render_categories
18
+ return nil unless categories.present?
19
+ "categories: [#{categories.collect {|c| "'#{format_category(c)}'"}.join(', ')}]" # need to encapsulate each category in quotes and format it before joining them with a comma
20
+ end
21
+
22
+ def render_tickInterval
23
+ return tickInterval if tickInterval.present?
24
+ return nil unless categories.present?
25
+ "tickInterval: #{(Math.sqrt(categories.length) < 5 ? 1 : Math.sqrt(categories.length)).floor}"
26
+ end
27
+
28
+ def format_category(category)
29
+ case category
30
+ when Date
31
+ category.strftime("%b. %d")
32
+ when Time
33
+ category.strftime("%H:%M")
34
+ when DateTime
35
+ category.strftime("%b. %d, %H:%M")
36
+ else
37
+ category.to_s
38
+ end
39
+ end
40
+
41
+ def render_labels
42
+ return nil unless labels.present?
43
+ "labels: {" +
44
+ "formatter: function(){ return '#{labels[:prepend]}' + this.value + '#{labels[:append]}'; }" +
45
+ "}"
46
+ end
47
+
47
48
  end
48
- end
49
+ end
@@ -1,10 +1,12 @@
1
+ require 'action_view'
2
+
1
3
  module Highcharts
2
4
  class Base < ActionView::Base
3
-
5
+
4
6
  def initialize(*args)
5
7
  args.extract_options!.each {|arg, value| self.send("#{arg}=", value)}
6
8
  end
7
-
9
+
8
10
  def render_options(args)
9
11
  attrs = []
10
12
  args.each do |t, a|
@@ -14,6 +16,6 @@ module Highcharts
14
16
  end
15
17
  attrs
16
18
  end
17
-
19
+
18
20
  end
19
- end
21
+ end
@@ -1,12 +1,12 @@
1
1
  module Highcharts
2
2
  class Chart < Base
3
3
  include ActionView::Helpers
4
-
4
+
5
5
  attr_accessor :container, :title, :subtitle, :plot_options, :xAxes, :yAxes, :legend, :series, :tooltip
6
-
6
+
7
7
  def to_s
8
8
  check_required_fields
9
-
9
+
10
10
  javascript_tag do
11
11
  safe_concat("$(function(){" +
12
12
  "new Highcharts.Chart({" +
@@ -15,66 +15,67 @@ module Highcharts
15
15
  "});")
16
16
  end
17
17
  end
18
-
19
- def render_all
20
- content = [render_container, render_titles, render_plot_options, render_axes, render_series, render_legend, render_tooltip].flatten.compact.join(",")
21
- if Rails.env.production?
22
- content
23
- else
24
- content.gsub(/(,|{|\[)/, "\\1\n").gsub(/(}|])/, "\n\\1")
18
+
19
+ private
20
+ def render_all
21
+ content = [render_container, render_titles, render_plot_options, render_axes, render_series, render_legend, render_tooltip].flatten.compact.join(",")
22
+ if Rails.env.production?
23
+ content
24
+ else
25
+ content.gsub(/(,|{|\[)/, "\\1\n").gsub(/(}|\])/, "\n\\1")
26
+ end
25
27
  end
26
- end
27
-
28
- def check_required_fields
29
- %w(container title series).each do |required_argument|
30
- raise ArgumentError, ":#{required_argument} must be passed" if send(required_argument).blank? || (send(required_argument).is_a?(Array) && send(required_argument).length == 0)
28
+
29
+ def check_required_fields
30
+ %w(container title series).each do |required_argument|
31
+ raise ArgumentError, ":#{required_argument} must be passed" if send(required_argument).blank? || (send(required_argument).is_a?(Array) && send(required_argument).length == 0)
32
+ end
31
33
  end
32
- end
33
-
34
- def render_container
35
- "chart: {renderTo: '#{container}'}"
36
- end
37
-
38
- def render_titles
39
- %w(title subtitle).collect do |t|
40
- "#{t}: {text: '#{send(t)}'}" if send(t).present?
34
+
35
+ def render_container
36
+ "chart: {renderTo: '#{container}'}"
41
37
  end
42
- end
43
-
44
- def render_plot_options
45
- return nil unless plot_options.present?
46
- "plotOptions: {" +
47
- Array.wrap(plot_options).collect {|po| PlotOptions.new(po)}.join(',') +
48
- "}"
49
- end
50
-
51
- def render_axes
52
- result = %w(x y).collect do |axis|
53
- return nil unless send("#{axis}Axes").present?
54
- "#{axis}Axis: [" +
55
- Array.wrap(send("#{axis}Axes")).collect {|a| Axis.new(a)}.join(',') +
38
+
39
+ def render_titles
40
+ %w(title subtitle).collect do |t|
41
+ "#{t}: {text: '#{send(t)}'}" if send(t).present?
42
+ end
43
+ end
44
+
45
+ def render_plot_options
46
+ return nil unless plot_options.present?
47
+ "plotOptions: {" +
48
+ Array.wrap(plot_options).collect {|po| PlotOptions.new(po)}.join(',') +
49
+ "}"
50
+ end
51
+
52
+ def render_axes
53
+ result = %w(x y).collect do |axis|
54
+ return nil unless send("#{axis}Axes").present?
55
+ "#{axis}Axis: [" +
56
+ Array.wrap(send("#{axis}Axes")).collect {|a| Axis.new(a)}.join(',') +
57
+ "]"
58
+ end
59
+ result.compact.join(",")
60
+ end
61
+
62
+ def render_legend
63
+ return nil unless legend.present?
64
+ Legend.new(legend)
65
+ end
66
+
67
+ def render_series
68
+ "series: [" +
69
+ Array.wrap(series).collect {|s| Series.new(s)}.join(',') +
56
70
  "]"
57
71
  end
58
- result.compact.join(",")
59
- end
60
-
61
- def render_legend
62
- return nil unless legend.present?
63
- Legend.new(legend)
64
- end
65
-
66
- def render_series
67
- "series: [" +
68
- Array.wrap(series).collect {|s| Series.new(s)}.join(',') +
69
- "]"
70
- end
71
-
72
- def render_tooltip
73
- return nil unless tooltip.present?
74
- "tooltip: {" +
75
- "formatter: function(){ return #{tooltip}; }" +
76
- "}"
77
- end
78
-
72
+
73
+ def render_tooltip
74
+ return nil unless tooltip.present?
75
+ "tooltip: {" +
76
+ "formatter: function(){ return #{tooltip}; }" +
77
+ "}"
78
+ end
79
+
79
80
  end
80
- end
81
+ end
@@ -1,8 +1,8 @@
1
1
  module Highcharts
2
2
  class Legend < Base
3
-
3
+
4
4
  attr_accessor :layout, :align, :verticalAlign, :x, :y, :borderWidth
5
-
5
+
6
6
  def to_s
7
7
  rendered_options = render_options(:strings => 'layout align verticalAlign', :objects => 'x y borderWidth')
8
8
  return nil if rendered_options.length == 0
@@ -10,6 +10,6 @@ module Highcharts
10
10
  rendered_options.join(',') +
11
11
  "}"
12
12
  end
13
-
13
+
14
14
  end
15
- end
15
+ end
@@ -1,23 +1,24 @@
1
1
  module Highcharts
2
2
  class PlotOptions < Base
3
-
3
+
4
4
  attr_accessor :type, :data_labels, :legend
5
-
5
+
6
6
  def to_s
7
7
  "#{type}: {" +
8
8
  [render_data_labels, render_legend].flatten.compact.join(',') +
9
9
  "}"
10
10
  end
11
-
12
- def render_data_labels
13
- "dataLabels: {" +
14
- "enabled: #{data_labels == false ? 'false' : 'true'}" +
15
- "}"
16
- end
17
-
18
- def render_legend
19
- "showInLegend: #{legend ? 'true' : 'false'}"
20
- end
21
-
11
+
12
+ private
13
+ def render_data_labels
14
+ "dataLabels: {" +
15
+ "enabled: #{data_labels == false ? 'false' : 'true'}" +
16
+ "}"
17
+ end
18
+
19
+ def render_legend
20
+ "showInLegend: #{legend ? 'true' : 'false'}"
21
+ end
22
+
22
23
  end
23
- end
24
+ end
@@ -3,4 +3,4 @@ module Highcharts
3
3
  class Engine < ::Rails::Engine
4
4
  end
5
5
  end
6
- end
6
+ end
@@ -1,8 +1,8 @@
1
1
  module Highcharts
2
2
  class Series < Base
3
-
3
+
4
4
  attr_accessor :name, :type, :xAxis, :yAxis, :data
5
-
5
+
6
6
  def to_s
7
7
  rendered_options = render_options(:strings => 'name type', :objects => 'xAxis yAxis')
8
8
  return nil if rendered_options.length == 0
@@ -10,10 +10,11 @@ module Highcharts
10
10
  [rendered_options, render_data].flatten.compact.join(',') +
11
11
  "}"
12
12
  end
13
-
14
- def render_data
15
- "data: #{data.first.is_a?(Array) ? data : data.collect(&:to_f)}"
16
- end
17
-
13
+
14
+ private
15
+ def render_data
16
+ "data: #{data.first.is_a?(Array) ? data : data.collect(&:to_f)}"
17
+ end
18
+
18
19
  end
19
- end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Highcharts
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Highcharts" do
4
+
5
+ it "should initialize and set args to their corresponding accessors" do
6
+ end
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ # For simplecov
2
+ # https://github.com/colszowka/simplecov
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'rspec'
7
+ require 'highcharts'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highcharts-js-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,19 +12,30 @@ cert_chain: []
12
12
  date: 2012-02-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: bundler
16
- requirement: &70131004346900 !ruby/object:Gem::Requirement
15
+ name: actionpack
16
+ requirement: &70322876824920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
21
+ version: '3.0'
22
+ type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70131004346900
24
+ version_requirements: *70322876824920
25
25
  - !ruby/object:Gem::Dependency
26
- name: simplecov
27
- requirement: &70131004346480 !ruby/object:Gem::Requirement
26
+ name: railties
27
+ requirement: &70322876824420 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70322876824420
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70322876824040 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70131004346480
46
+ version_requirements: *70322876824040
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rake
38
- requirement: &70131004346060 !ruby/object:Gem::Requirement
49
+ requirement: &70322876823580 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70131004346060
57
+ version_requirements: *70322876823580
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: rspec
49
- requirement: &70131004345640 !ruby/object:Gem::Requirement
60
+ requirement: &70322876823160 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,18 +65,18 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70131004345640
68
+ version_requirements: *70322876823160
58
69
  - !ruby/object:Gem::Dependency
59
- name: actionpack
60
- requirement: &70131004345140 !ruby/object:Gem::Requirement
70
+ name: simplecov
71
+ requirement: &70322876822740 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
- - - ~>
74
+ - - ! '>='
64
75
  - !ruby/object:Gem::Version
65
- version: '3.0'
66
- type: :runtime
76
+ version: '0'
77
+ type: :development
67
78
  prerelease: false
68
- version_requirements: *70131004345140
79
+ version_requirements: *70322876822740
69
80
  description: Easily configure a Highcharts JS chart for use in a Rails application
70
81
  email:
71
82
  - agrobbin@gmail.com
@@ -74,6 +85,7 @@ extensions: []
74
85
  extra_rdoc_files: []
75
86
  files:
76
87
  - .gitignore
88
+ - .rspec
77
89
  - CHANGELOG.md
78
90
  - Gemfile
79
91
  - LICENSE
@@ -89,6 +101,8 @@ files:
89
101
  - lib/highcharts/rails.rb
90
102
  - lib/highcharts/series.rb
91
103
  - lib/highcharts/version.rb
104
+ - spec/highcharts/base_spec.rb
105
+ - spec/spec_helper.rb
92
106
  - vendor/.DS_Store
93
107
  - vendor/assets/javascripts/.DS_Store
94
108
  - vendor/assets/javascripts/adapters/mootools.js
@@ -101,7 +115,7 @@ files:
101
115
  - vendor/assets/javascripts/themes/gray.js
102
116
  - vendor/assets/javascripts/themes/grid.js
103
117
  - vendor/assets/javascripts/themes/skies.js
104
- homepage: http://github.com/agrobbin/highcharts-js-rails
118
+ homepage: https://github.com/agrobbin/highcharts-js-rails
105
119
  licenses: []
106
120
  post_install_message:
107
121
  rdoc_options: []
@@ -125,4 +139,6 @@ rubygems_version: 1.8.6
125
139
  signing_key:
126
140
  specification_version: 3
127
141
  summary: Easily configure a Highcharts JS chart for use in a Rails application
128
- test_files: []
142
+ test_files:
143
+ - spec/highcharts/base_spec.rb
144
+ - spec/spec_helper.rb