highcharts-js-rails 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -1
  3. data/.rspec +0 -1
  4. data/.travis.yml +6 -0
  5. data/CHANGELOG.md +7 -0
  6. data/{lib/LICENSE → LICENSE} +1 -1
  7. data/README.md +16 -13
  8. data/highcharts-js-rails.gemspec +3 -5
  9. data/lib/highcharts-js-rails.rb +1 -1
  10. data/lib/highcharts.rb +4 -3
  11. data/lib/highcharts/axis/plot_bands.rb +1 -1
  12. data/lib/highcharts/axis/plot_lines.rb +1 -1
  13. data/lib/highcharts/axis/x.rb +6 -8
  14. data/lib/highcharts/axis/y.rb +6 -6
  15. data/lib/highcharts/base.rb +8 -8
  16. data/lib/highcharts/{color.rb → colors.rb} +0 -0
  17. data/lib/highcharts/engine.rb +2 -0
  18. data/lib/highcharts/legend.rb +2 -2
  19. data/lib/highcharts/plot_options.rb +13 -13
  20. data/lib/highcharts/plot_options/plot_type.rb +7 -7
  21. data/lib/highcharts/plot_options/plot_type/marker.rb +1 -1
  22. data/lib/highcharts/plot_options/plot_type/marker/states.rb +2 -2
  23. data/lib/highcharts/plot_options/plot_type/states.rb +1 -1
  24. data/lib/highcharts/plot_options/plot_type/states/hover.rb +1 -1
  25. data/lib/highcharts/point.rb +2 -2
  26. data/spec/highcharts/axis/x_spec.rb +51 -0
  27. data/spec/highcharts/base_spec.rb +55 -1
  28. data/spec/highcharts/series_spec.rb +25 -0
  29. data/spec/highcharts_spec.rb +65 -0
  30. data/spec/spec_helper.rb +4 -4
  31. data/vendor/assets/javascripts/highcharts-more.js +2290 -1387
  32. data/vendor/assets/javascripts/highcharts.js +2712 -1720
  33. data/vendor/assets/javascripts/highcharts/adapters/mootools.js +15 -30
  34. data/vendor/assets/javascripts/highcharts/adapters/prototype.js +10 -79
  35. data/vendor/assets/javascripts/highcharts/modules/canvas-tools.js +1 -1
  36. data/vendor/assets/javascripts/highcharts/modules/data.js +57 -32
  37. data/vendor/assets/javascripts/highcharts/modules/exporting.js +180 -229
  38. data/vendor/assets/javascripts/highcharts/modules/funnel.js +284 -0
  39. data/vendor/assets/javascripts/highcharts/themes/dark-blue.js +11 -20
  40. data/vendor/assets/javascripts/highcharts/themes/dark-green.js +12 -20
  41. data/vendor/assets/javascripts/highcharts/themes/gray.js +15 -20
  42. data/vendor/assets/javascripts/highcharts/themes/grid.js +8 -0
  43. metadata +34 -38
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 104e6d6a6c11a70d570d6be756cba2e7eee8182e
4
+ data.tar.gz: 9e2affd411da4ff0f835c6d35a8b5cb71a35d14b
5
+ SHA512:
6
+ metadata.gz: 5443ecd849f92fa8c4e1b358ec64120db2533103b0066e2bf2e66c2479c2f7418005a535d0feb444339e1f2a809c034d9d4b3be0da267fe104ee451385847f94
7
+ data.tar.gz: fa1b7175e87e2082d4422f19d811552d5be44d5119854cb91048766753d546fedd4e4eb851daf338104466f8feb5ec21ec73cc2cede6072be75bb9d591dab6d5
data/.gitignore CHANGED
@@ -1,7 +1,8 @@
1
1
  *.gem
2
2
  .bundle
3
3
  .DS_Store
4
- .rvmrc
4
+ .ruby-version
5
+ .ruby-gemset
5
6
  Gemfile.lock
6
7
  coverage/
7
8
  pkg/*
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --colour
2
- --format documentation
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script: bundle exec rspec spec
@@ -1,3 +1,10 @@
1
+ ## v1.0.0 (2013-04-18) ##
2
+
3
+ * Upgrade Highcharts to 3.0.1.
4
+ * Allow both new block-style chart initialization and older chart initialization.
5
+ * Drop any possible support for Ruby 1.8.7.
6
+ * Build out a test suite for the finer points of this gem, including Travis CI support.
7
+
1
8
  ## v0.2.1 (2013-02-25) ##
2
9
 
3
10
  * Loosen dependency on railties to allow 4.0.
@@ -1,4 +1,4 @@
1
- Copyright (C) 2011 Alex Robbin
1
+ Copyright (C) 2013 Alex Robbin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- Highcharts JS Rails
2
- ===================
1
+ # Highcharts JS Rails
2
+
3
+ [![Build Status](https://secure.travis-ci.org/agrobbin/highcharts-js-rails.png?branch=master)](https://travis-ci.org/agrobbin/highcharts-js-rails) [![Dependency Status](https://gemnasium.com/agrobbin/highcharts-js-rails.png)](https://gemnasium.com/agrobbin/highcharts-js-rails)
3
4
 
4
5
  Easily configure a Highcharts JS chart for use in a Rails application.
5
6
 
@@ -25,28 +26,30 @@ Many have a default option assigned to them. Those that have one are listed belo
25
26
  * yAxis.labels: enabled (Boolean)
26
27
  * yAxis.title: text (String)
27
28
 
28
- xAxis Notes
29
- -------
29
+ ## Requirements
30
+
31
+ Highcharts JS Rails requires **Ruby 1.9.2+** and **Rails 3.1+**.
32
+
33
+ ## xAxis Notes
30
34
 
31
35
  * The `categories` option's array of values will be automatically formatted based on its class unless you pass :skip_category_formatting => true.
32
36
  * The `tickInterval` option is only necessary if you want to override automatic tickInterval creation. If the option is not passed or :auto is passed, the tickInterval will be calculated based on the number of categories passed.
33
37
 
34
38
  For the xAxis, yAxis, and series options, you must pass an array of hashes. Each of those hashes will be converted into the appropriate set of options.
35
39
 
36
- Example
37
- --------
40
+ ## Example
38
41
 
39
42
  Ruby:
40
43
 
41
44
  ```ruby
42
45
  chart = Highcharts.new do |chart|
43
- chart.chart(:renderTo => 'graph')
46
+ chart.chart(renderTo: 'graph')
44
47
  chart.title('Highcharts Example')
45
- chart.xAxis(:categories => ['October 12', 'October 13', 'October 14'])
46
- chart.yAxis(:title => 'Impressions', :min => 0)
47
- chart.series(:name => 'Impressions', :yAxis => 0, :type => 'line', :data => [100000, 122000, 127000])
48
- chart.legend(:layout => 'vertical', :align => 'right', :verticalAlign => 'top', :x => -10, :y => 100, :borderWidth => 0)
49
- chart.tooltip(:formatter => "function(){ return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y; }")
48
+ chart.xAxis(categories: ['October 12', 'October 13', 'October 14'])
49
+ chart.yAxis(title: 'Impressions', min: 0)
50
+ chart.series(name: 'Impressions', yAxis: 0, type: 'line', data: [100000, 122000, 127000])
51
+ chart.legend(layout: 'vertical', align: 'right', verticalAlign: 'top', x: -10, y: 100, borderWidth: 0)
52
+ chart.tooltip(formatter: "function(){ return '<b>' + this.series.name + '</b><br/>' + this.x + ': ' + this.y; }")
50
53
  end
51
54
  ```
52
55
 
@@ -55,4 +58,4 @@ HTML/ERB:
55
58
  ```html+erb
56
59
  <%= chart %>
57
60
  <div id="graph" style="width: 400px; height: 200px;"></div>
58
- ```
61
+ ```
@@ -1,11 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
-
4
2
  Gem::Specification.new do |s|
5
3
  s.name = 'highcharts-js-rails'
6
- s.version = '0.2.1'
4
+ s.version = '1.0.0'
7
5
  s.authors = ['Alex Robbin']
8
- s.email = ['agrobbin@gmail.com']
6
+ s.email = ['alex@robbinsweb.biz']
9
7
  s.homepage = 'https://github.com/agrobbin/highcharts-js-rails'
10
8
  s.summary = %q{Easily configure a Highcharts JS chart for use in a Rails application}
11
9
  s.description = s.summary
@@ -17,7 +15,7 @@ Gem::Specification.new do |s|
17
15
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
16
  s.require_paths = ['lib']
19
17
 
20
- s.add_dependency 'railties', '>= 3.1'
18
+ s.add_dependency 'railties', ['>= 3.1', '< 4.1']
21
19
  s.add_development_dependency 'bundler'
22
20
  s.add_development_dependency 'rake'
23
21
  s.add_development_dependency 'rspec'
@@ -8,7 +8,7 @@ require 'highcharts/axis/stack_labels'
8
8
  require 'highcharts/axis/x'
9
9
  require 'highcharts/axis/y'
10
10
  require 'highcharts/chart'
11
- require 'highcharts/color'
11
+ require 'highcharts/colors'
12
12
  require 'highcharts/credits'
13
13
  require 'highcharts/labels'
14
14
  require 'highcharts/legend'
@@ -1,4 +1,5 @@
1
1
  require 'action_view'
2
+ require 'active_support/core_ext/object/to_json'
2
3
 
3
4
  class Highcharts < ActionView::Base
4
5
  include ActionView::Helpers
@@ -8,8 +9,8 @@ class Highcharts < ActionView::Base
8
9
  def initialize
9
10
  @options = {}
10
11
 
11
- @base_options = %w(labels lang loading)
12
- @default_options = %w(chart colors credits legend point series symbols title tooltip)
12
+ @base_options = %w(global labels lang loading navigation pane)
13
+ @default_options = %w(chart colors credits legend series title tooltip)
13
14
  @custom_options = {
14
15
  'plotOptions' => 'PlotOptions',
15
16
  'subtitle' => 'Title',
@@ -17,7 +18,7 @@ class Highcharts < ActionView::Base
17
18
  'yAxis' => 'Axis::Y'
18
19
  }
19
20
 
20
- yield self
21
+ yield self if block_given?
21
22
  end
22
23
 
23
24
  def inspect
@@ -4,7 +4,7 @@ class Highcharts
4
4
 
5
5
  def initialize(opts = {})
6
6
  @suboptions = {
7
- :label => 'Base'
7
+ label: 'Base'
8
8
  }
9
9
  super
10
10
  end
@@ -4,7 +4,7 @@ class Highcharts
4
4
 
5
5
  def initialize(opts = {})
6
6
  @suboptions = {
7
- :label => 'Base'
7
+ label: 'Base'
8
8
  }
9
9
  super
10
10
  end
@@ -7,11 +7,11 @@ class Highcharts
7
7
  def initialize(opts = {})
8
8
  @default = :categories
9
9
  @suboptions = {
10
- :events => 'Axis::Events',
11
- :labels => 'Labels',
12
- :plotBands => 'Axis::PlotBands',
13
- :plotLines => 'Axis::PlotLines',
14
- :title => 'Title'
10
+ events: 'Axis::Events',
11
+ labels: 'Labels',
12
+ plotBands: 'Axis::PlotBands',
13
+ plotLines: 'Axis::PlotLines',
14
+ title: 'Title'
15
15
  }
16
16
  # Check to see if we want to skip automatic formatting of categories.
17
17
  @skip_category_formatting = true if opts.delete(:skip_category_formatting)
@@ -40,14 +40,12 @@ class Highcharts
40
40
  # DateTime
41
41
  #
42
42
  # If the class of the category is none of the above, #to_s is returned.
43
- # You can prevent this by passing :skip_category_formatting => true to the Axis options.
43
+ # You can prevent this by passing `skip_category_formatting: true` to the Axis options.
44
44
  def format_category(category)
45
45
  case category
46
46
  when Date
47
47
  category.strftime("%b. %d")
48
48
  when Time || DateTime
49
- # category.strftime("%H:%M")
50
- # when DateTime
51
49
  category.strftime("%b. %d, %H:%M")
52
50
  else
53
51
  category.to_s
@@ -5,12 +5,12 @@ class Highcharts
5
5
  def initialize(opts = {})
6
6
  @default = :title
7
7
  @suboptions = {
8
- :events => 'Axis::Events',
9
- :labels => 'Labels',
10
- :plotBands => 'Axis::PlotBands',
11
- :plotLines => 'Axis::PlotLines',
12
- :stackLabels => 'Axis::StackLabels',
13
- :title => 'Title'
8
+ events: 'Axis::Events',
9
+ labels: 'Labels',
10
+ plotBands: 'Axis::PlotBands',
11
+ plotLines: 'Axis::PlotLines',
12
+ stackLabels: 'Axis::StackLabels',
13
+ title: 'Title'
14
14
  }
15
15
  super
16
16
  end
@@ -1,5 +1,3 @@
1
- require 'rails'
2
-
3
1
  class Highcharts
4
2
  class Base
5
3
 
@@ -19,6 +17,7 @@ class Highcharts
19
17
  raise ArgumentError, "You must pass a Hash to #{self.class}. You passed #{options.inspect}"
20
18
  end
21
19
  end
20
+
22
21
  # If there is an option that is available as a suboption to the current class,
23
22
  # let's set the option to an instance of that subclass.
24
23
  options.each do |k, v|
@@ -41,12 +40,13 @@ class Highcharts
41
40
  json.join(',')
42
41
  end
43
42
 
44
- # This method is used in #to_json to remove the first and last characters from an option's value.
45
- # In the end this removes the encapsulating quotation marks (") from a specific option, provided
46
- # it is included in the current class's skip_quotation array.
47
- def check_quotation(key, json)
48
- skip_quotation.present? && Array.wrap(skip_quotation).include?(key) ? json[1..-2] : json
49
- end
43
+ private
44
+ # This method is used in #to_json to remove the first and last characters from an option's value.
45
+ # In the end this removes the encapsulating quotation marks (") from a specific option, provided
46
+ # it is included in the current class's skip_quotation array.
47
+ def check_quotation(key, json)
48
+ skip_quotation.present? && Array.wrap(skip_quotation).include?(key) ? json[1..-2] : json
49
+ end
50
50
 
51
51
  end
52
52
  end
File without changes
@@ -1,3 +1,5 @@
1
+ require 'rails'
2
+
1
3
  class Highcharts
2
4
  class Engine < ::Rails::Engine
3
5
  end
@@ -5,10 +5,10 @@ class Highcharts
5
5
  @default = :enabled
6
6
  @skip_quotation = :labelFormatter
7
7
  @suboptions = {
8
- :navigation => 'Base'
8
+ navigation: 'Base'
9
9
  }
10
10
  super
11
11
  end
12
12
 
13
13
  end
14
- end
14
+ end
@@ -3,19 +3,19 @@ class Highcharts
3
3
 
4
4
  def initialize(opts = {})
5
5
  @suboptions = {
6
- :area => 'PlotOptions::PlotType',
7
- :arearange => 'PlotOptions::PlotType',
8
- :areaspline => 'PlotOptions::PlotType',
9
- :areasplinerange => 'PlotOptions::PlotType',
10
- :bar => 'PlotOptions::PlotType',
11
- :column => 'PlotOptions::PlotType',
12
- :columnrange => 'PlotOptions::PlotType',
13
- :gauge => 'PlotOptions::PlotType',
14
- :line => 'PlotOptions::PlotType',
15
- :pie => 'PlotOptions::PlotType',
16
- :series => 'PlotOptions::PlotType',
17
- :scatter => 'PlotOptions::PlotType',
18
- :spline => 'PlotOptions::PlotType'
6
+ area: 'PlotOptions::PlotType',
7
+ arearange: 'PlotOptions::PlotType',
8
+ areaspline: 'PlotOptions::PlotType',
9
+ areasplinerange: 'PlotOptions::PlotType',
10
+ bar: 'PlotOptions::PlotType',
11
+ column: 'PlotOptions::PlotType',
12
+ columnrange: 'PlotOptions::PlotType',
13
+ gauge: 'PlotOptions::PlotType',
14
+ line: 'PlotOptions::PlotType',
15
+ pie: 'PlotOptions::PlotType',
16
+ series: 'PlotOptions::PlotType',
17
+ scatter: 'PlotOptions::PlotType',
18
+ spline: 'PlotOptions::PlotType'
19
19
  }
20
20
  super
21
21
  end
@@ -4,13 +4,13 @@ class Highcharts
4
4
 
5
5
  def initialize(opts = {})
6
6
  @suboptions = {
7
- :dataLabels => 'Labels',
8
- :dial => 'Base',
9
- :events => 'PlotOptions::PlotType::Events',
10
- :marker => 'PlotOptions::PlotType::Marker',
11
- :pivot => 'Base',
12
- :point => 'Point',
13
- :states => 'PlotOptions::PlotType::States'
7
+ dataLabels: 'Labels',
8
+ dial: 'Base',
9
+ events: 'PlotOptions::PlotType::Events',
10
+ marker: 'PlotOptions::PlotType::Marker',
11
+ pivot: 'Base',
12
+ point: 'Point',
13
+ states: 'PlotOptions::PlotType::States'
14
14
  }
15
15
  super
16
16
  end
@@ -6,7 +6,7 @@ class Highcharts
6
6
  def initialize(opts = {})
7
7
  @default = :enabled
8
8
  @suboptions = {
9
- :states => 'PlotOptions::PlotType::Marker::States'
9
+ states: 'PlotOptions::PlotType::Marker::States'
10
10
  }
11
11
  super
12
12
  end
@@ -6,8 +6,8 @@ class Highcharts
6
6
 
7
7
  def initialize(opts = {})
8
8
  @suboptions = {
9
- :hover => 'Base',
10
- :select => 'Base'
9
+ hover: 'Base',
10
+ select: 'Base'
11
11
  }
12
12
  super
13
13
  end
@@ -5,7 +5,7 @@ class Highcharts
5
5
 
6
6
  def initialize(opts = {})
7
7
  @suboptions = {
8
- :hover => 'PlotOptions::PlotType::States::Hover'
8
+ hover: 'PlotOptions::PlotType::States::Hover'
9
9
  }
10
10
  super
11
11
  end
@@ -6,7 +6,7 @@ class Highcharts
6
6
 
7
7
  def initialize(opts = {})
8
8
  @suboptions = {
9
- :marker => 'Base'
9
+ marker: 'Base'
10
10
  }
11
11
  super
12
12
  end
@@ -3,8 +3,8 @@ class Highcharts
3
3
 
4
4
  def initialize(opts = {})
5
5
  @suboptions = {
6
- :events => 'Point::Events',
7
- :marker => 'Base'
6
+ events: 'Point::Events',
7
+ marker: 'Base'
8
8
  }
9
9
  super
10
10
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Highcharts::Axis::X do
4
+
5
+ subject { Highcharts::Axis::X.new(options) }
6
+
7
+ describe "#automate_tick_interval" do
8
+ let(:options) { {categories: (1..50).to_a} }
9
+
10
+ its(:to_json) { should include("\"tickInterval\":7") }
11
+
12
+ context "when tickInterval is explicitly passed" do
13
+ let(:options) { {tickInterval: 5} }
14
+
15
+ its(:to_json) { should eq("\"tickInterval\":5") }
16
+ end
17
+
18
+ context "when tickInterval is :auto" do
19
+ let(:options) { {categories: [1], tickInterval: :auto} }
20
+
21
+ its(:to_json) { should include("\"tickInterval\":1") }
22
+ end
23
+ end
24
+
25
+ describe "#format_category" do
26
+ context "when :skip_category is passed" do
27
+ let(:options) { {categories: [Date.new(2013, 1, 1)], skip_category_formatting: true} }
28
+
29
+ its(:to_json) { should include("\"categories\":[\"2013-01-01\"]") }
30
+ end
31
+
32
+ context "dates" do
33
+ let(:options) { {categories: [Date.new(2013, 1, 1), Date.new(2013, 2, 1)]} }
34
+
35
+ its(:to_json) { should include("\"categories\":[\"Jan. 01\",\"Feb. 01\"]") }
36
+ end
37
+
38
+ context "full dates and times" do
39
+ let(:options) { {categories: [Time.new(2013, 1, 1, 1, 1), Time.new(2013, 2, 1, 1, 1)]} }
40
+
41
+ its(:to_json) { should include("\"categories\":[\"Jan. 01, 01:01\",\"Feb. 01, 01:01\"]") }
42
+ end
43
+
44
+ context "other types of categories" do
45
+ let(:options) { {categories: [1, 2, 3, 4, 5]} }
46
+
47
+ its(:to_json) { should include("\"categories\":[\"1\",\"2\",\"3\",\"4\",\"5\"]") }
48
+ end
49
+ end
50
+
51
+ end