chartkick 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chartkick might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea705341b63c82aef63f8da9e1f98d8caad46097
4
- data.tar.gz: 955115a1463d433fa2c14d70541ff7ac9f62c3eb
3
+ metadata.gz: ca7e47f1dbaaa98f3c7e1ca1e4dc52ab6cb4262b
4
+ data.tar.gz: de76a0f1276d12212b37f2a8366649ff22f187e8
5
5
  SHA512:
6
- metadata.gz: 48540e759da663290d91093ce58ef3e59258682f441401c1cde301057b83f8bcefda8a62a9d76ea8efbf4661eb9998c6d4463f8b4d239de75fd720d9a41d3f57
7
- data.tar.gz: 845ca4aee7e2262a14dd46dfb73d5b975955f7bf86fd19de7f7407ea3889b9829789752b16441f9fb24b5b9e041650c8aca5821b172cc69034fb7b61ef8b1317
6
+ metadata.gz: 7d4f116d8ac99364ef648f5ee4f9416327c8ea77e647d5606028fe549c2c771c9245676b09b8032ac2df9b9b41e3bc47209911a7daecc562c73742077af8be96
7
+ data.tar.gz: c67bdceab693294cb60867edaf7d467a0ea2c46f05791bc1f294b1b35ace97aa9290851117e90eeda336ac0ebe08a8e7cec0af4bd09e525effc496ca19053385
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.2.2
2
+
3
+ - Added global `content_for` option
4
+ - Added `stacked` option
5
+
1
6
  ## 1.2.1
2
7
 
3
8
  - Added localization for Google Charts
data/README.md CHANGED
@@ -82,6 +82,12 @@ Min and max values (except pie chart)
82
82
  <%= line_chart data, :min => 1000, :max => 5000 %>
83
83
  ```
84
84
 
85
+ Stacked columns or bars
86
+
87
+ ```erb
88
+ <%= column_chart data, :stacked => true %>
89
+ ```
90
+
85
91
  You can pass options directly to the charting library with:
86
92
 
87
93
  ```erb
@@ -91,13 +97,19 @@ You can pass options directly to the charting library with:
91
97
  You can also pass a content_for option, which will put the javascript in a content block. This is great for including all of your javascript at the bottom of the page.
92
98
 
93
99
  ```erb
94
- <%= line_chart data, :content_for => :js_initialization %>
100
+ <%= line_chart data, :content_for => :charts_js %>
95
101
  ```
96
102
  Then, in your layout:
97
103
 
98
104
  ```erb
99
- <%= yield :js_initialization %> <%# Rails %>
100
- <%= yield_content :js_initialization %> <%# Padrino %>
105
+ <%= yield :charts_js %> <%# Rails %>
106
+ <%= yield_content :charts_js %> <%# Padrino %>
107
+ ```
108
+
109
+ To make this the default, create an initializer with:
110
+
111
+ ```ruby
112
+ Chartkick.content_for = :charts_js
101
113
  ```
102
114
 
103
115
  ### Data
@@ -154,6 +166,12 @@ If you prefer Highcharts, use:
154
166
 
155
167
  You must include `chartkick.js` manually. [Download it here](https://raw.github.com/ankane/chartkick/master/app/assets/javascripts/chartkick.js)
156
168
 
169
+ For Rails 2.3, you must use a script tag for Google Charts due to [this bug](https://rails.lighthouseapp.com/projects/8994/tickets/1664-javascript_include_tag-shouldnt-append-a-js-onto-external-urls).
170
+
171
+ ```html
172
+ <script src="//www.google.com/jsapi"></script>
173
+ ```
174
+
157
175
  ### For Sinatra
158
176
 
159
177
  You must include `chartkick.js` manually. [Download it here](https://raw.github.com/ankane/chartkick/master/app/assets/javascripts/chartkick.js)
@@ -13,7 +13,7 @@
13
13
  'use strict';
14
14
 
15
15
  var Chartkick, ISO8601_PATTERN, DECIMAL_SEPARATOR, defaultOptions, hideLegend,
16
- setMin, setMax, jsOptions, loaded, waitForLoaded, setBarMin, setBarMax, createDataTable, resize;
16
+ setMin, setMax, setStacked, jsOptions, loaded, waitForLoaded, setBarMin, setBarMax, createDataTable, resize;
17
17
 
18
18
  // only functions that need defined specific to charting library
19
19
  var renderLineChart, renderPieChart, renderColumnChart, renderBarChart, renderAreaChart;
@@ -105,7 +105,7 @@
105
105
  return false;
106
106
  }
107
107
 
108
- function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax) {
108
+ function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax, setStacked) {
109
109
  return function (series, opts, chartOptions) {
110
110
  var options = merge({}, defaultOptions);
111
111
  options = merge(options, chartOptions || {});
@@ -128,6 +128,10 @@
128
128
  setMax(options, opts.max);
129
129
  }
130
130
 
131
+ if (opts.stacked) {
132
+ setStacked(options);
133
+ }
134
+
131
135
  // merge library last
132
136
  options = merge(options, opts.library || {});
133
137
 
@@ -149,7 +153,7 @@
149
153
  }
150
154
 
151
155
  function getJSON(element, url, success) {
152
- $.ajax({
156
+ jQuery.ajax({
153
157
  dataType: "json",
154
158
  url: url,
155
159
  success: success,
@@ -275,7 +279,11 @@
275
279
  options.yAxis.max = max;
276
280
  };
277
281
 
278
- jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax);
282
+ setStacked = function (options) {
283
+ options.plotOptions.series.stacking = "normal";
284
+ };
285
+
286
+ jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax, setStacked);
279
287
 
280
288
  renderLineChart = function (element, series, opts, chartType) {
281
289
  chartType = chartType || "spline";
@@ -452,7 +460,11 @@
452
460
  options.hAxis.viewWindow.max = max;
453
461
  };
454
462
 
455
- jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax);
463
+ setStacked = function (options) {
464
+ options.isStacked = true;
465
+ };
466
+
467
+ jsOptions = jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax, setStacked);
456
468
 
457
469
  // cant use object as key
458
470
  createDataTable = function (series, columnType) {
@@ -550,7 +562,7 @@
550
562
  }
551
563
  }
552
564
  };
553
- var options = jsOptionsFunc(defaultOptions, hideLegend, setBarMin, setBarMax)(series, opts, chartOptions);
565
+ var options = jsOptionsFunc(defaultOptions, hideLegend, setBarMin, setBarMax, setStacked)(series, opts, chartOptions);
554
566
  var data = createDataTable(series, "string");
555
567
  var chart = new google.visualization.BarChart(element);
556
568
  resize(function () {
data/lib/chartkick.rb CHANGED
@@ -2,3 +2,9 @@ require "chartkick/version"
2
2
  require "chartkick/helper"
3
3
  require "chartkick/rails" if defined?(Rails)
4
4
  require "chartkick/sinatra" if defined?(Sinatra)
5
+
6
+ module Chartkick
7
+ class << self
8
+ attr_accessor :content_for
9
+ end
10
+ end
@@ -31,6 +31,8 @@ module Chartkick
31
31
  options = options.dup
32
32
  element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
33
33
  height = options.delete(:height) || "300px"
34
+ # content_for: nil must override default
35
+ content_for = options.has_key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
34
36
 
35
37
  html = <<HTML
36
38
  <div id="#{ERB::Util.html_escape(element_id)}" style="height: #{ERB::Util.html_escape(height)}; text-align: center; color: #999; line-height: #{ERB::Util.html_escape(height)}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">
@@ -42,8 +44,8 @@ HTML
42
44
  new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.to_json}, #{options.to_json});
43
45
  </script>
44
46
  JS
45
- if options[:content_for]
46
- content_for(options[:content_for]) { js.respond_to?(:html_safe) ? js.html_safe : js }
47
+ if content_for
48
+ content_for(content_for) { js.respond_to?(:html_safe) ? js.html_safe : js }
47
49
  else
48
50
  html += js
49
51
  end
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-09 00:00:00.000000000 Z
11
+ date: 2014-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Create beautiful Javascript charts with one line of Ruby
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - CHANGELOG.md
64
64
  - Gemfile
65
65
  - LICENSE.txt
@@ -85,17 +85,17 @@ require_paths:
85
85
  - lib
86
86
  required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - '>='
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.0.0
98
+ rubygems_version: 2.2.0
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Create beautiful Javascript charts with one line of Ruby