chartkick 1.2.4 → 1.2.5

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: c4ad83e0908f7d19f80e1777c9b06b1bc9bb4e5f
4
- data.tar.gz: eae7fc7ec9cb6ae8e1a207ae11fe5e728953cf95
3
+ metadata.gz: d0dba34a7302ee5f73cba7e55be0014c639431d6
4
+ data.tar.gz: f72f4d80febb09fd928abdf75c3967bbdeeb6d21
5
5
  SHA512:
6
- metadata.gz: 1703d7ff64748ebd96aa952e9804f40b7abfeb719a18d4730529612d5fe17513ee95a1d6cb8da5b54f8148c2b0ccdb135c28e5ed2f095ddcb081a3f310390425
7
- data.tar.gz: c6e81a464f25d378e64bb8976681e51a2d5b5cdb97eff53379c09874b24d02a0d8b0afa30ea80bbe4f7e78624c37db79c62c7e8b395d085b0d9193e8658768c6
6
+ metadata.gz: 73351da6753359cb7af17028059d3077788c2f8a6912f79f96243923a58bf0ab64911004661352efaceff634ceff5742eafa98b27a45d7a9e97365933d8b8ab2
7
+ data.tar.gz: 4cadd3bf93432e26968faf47c822c228ed184e228324cffbaa8b7e4188ec5140647ffd9d87e84f67bf3b2c56376bab7ed0548d7ce076e4954fb2773d13f54e13
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.2.5
2
+
3
+ - Added support for multiple groups
4
+ - Added `html` option
5
+
1
6
  ## 1.2.4
2
7
 
3
8
  - Added global options
data/README.md CHANGED
@@ -6,9 +6,11 @@ Create beautiful Javascript charts with one line of Ruby. No more fighting with
6
6
 
7
7
  Works with Rails, Sinatra and most browsers (including IE 6)
8
8
 
9
- :two_hearts: A perfect companion to [groupdate](https://github.com/ankane/groupdate) and [active_median](https://github.com/ankane/active_median)
9
+ :two_hearts: A perfect companion to [groupdate](https://github.com/ankane/groupdate), [hightop](https://github.com/ankane/hightop), and [active_median](https://github.com/ankane/active_median)
10
10
 
11
- ## Usage
11
+ :speech_balloon: Get [handcrafted updates](http://chartkick.us7.list-manage.com/subscribe?u=952c861f99eb43084e0a49f98&id=6ea6541e8e&group[0][1]=true) for new features
12
+
13
+ ## Charts
12
14
 
13
15
  Line chart
14
16
 
@@ -46,7 +48,7 @@ Geo chart
46
48
  <%= geo_chart Medal.group(:country).count %>
47
49
  ```
48
50
 
49
- Multiple series (except pie chart)
51
+ Multiple series
50
52
 
51
53
  ```erb
52
54
  <%= line_chart @goals.map{|goal|
@@ -54,6 +56,12 @@ Multiple series (except pie chart)
54
56
  } %>
55
57
  ```
56
58
 
59
+ or
60
+
61
+ ```erb
62
+ <%= line_chart Feat.group(:goal_id).group_by_week(:created_at).count %>
63
+ ```
64
+
57
65
  ### Say Goodbye To Timeouts
58
66
 
59
67
  Make your pages load super fast and stop worrying about timeouts. Give each chart its own endpoint.
@@ -74,6 +82,12 @@ end
74
82
 
75
83
  **Note:** This feature requires [jQuery](http://jquery.com/) or [Zepto](http://zeptojs.com/) at the moment.
76
84
 
85
+ For multiple series, add `chart_json` at the end.
86
+
87
+ ```ruby
88
+ render json: Task.group(:goal_id).group_by_day(:completed_at).count.chart_json
89
+ ```
90
+
77
91
  ### Options
78
92
 
79
93
  Id and height
@@ -82,12 +96,14 @@ Id and height
82
96
  <%= line_chart data, id: "users-chart", height: "500px" %>
83
97
  ```
84
98
 
85
- Min and max values (except pie chart)
99
+ Min and max values
86
100
 
87
101
  ```erb
88
102
  <%= line_chart data, min: 1000, max: 5000 %>
89
103
  ```
90
104
 
105
+ `min` defaults to 0 for charts with non-negative values. Use `nil` to let the charting library decide.
106
+
91
107
  Colors
92
108
 
93
109
  ```erb
@@ -114,11 +130,29 @@ You can pass options directly to the charting library with:
114
130
 
115
131
  See the documentation for [Google Charts](https://developers.google.com/chart/interactive/docs/gallery) and [Highcharts](http://api.highcharts.com/highcharts) for more info.
116
132
 
117
- 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.
133
+ ### Global Options
134
+
135
+ To set options for all of your charts, create an initializer `config/initializers/chartkick.rb` with:
118
136
 
119
- ```erb
120
- <%= line_chart data, content_for: :charts_js %>
137
+ ```ruby
138
+ Chartkick.options = {
139
+ height: "400px",
140
+ colors: ["pink", "#999"]
141
+ }
121
142
  ```
143
+
144
+ Customize the html
145
+
146
+ ```ruby
147
+ Chartkick.options[:html] = '<div id="%{id}" style="height: %{height};">Loading...</div>'
148
+ ```
149
+
150
+ You capture the javascript in a content block with:
151
+
152
+ ```ruby
153
+ Chartkick.options[:content_for] = :charts_js
154
+ ```
155
+
122
156
  Then, in your layout:
123
157
 
124
158
  ```erb
@@ -126,17 +160,7 @@ Then, in your layout:
126
160
  <%= yield_content :charts_js %> <%# Padrino %>
127
161
  ```
128
162
 
129
- ### Global Options
130
-
131
- To set options for all of your charts, create an initializer with:
132
-
133
- ```ruby
134
- Chartkick.options = {
135
- height: "400px",
136
- colors: ["pink", "#999"],
137
- content_for: :charts_js
138
- }
139
- ```
163
+ This is great for including all of your javascript at the bottom of the page.
140
164
 
141
165
  ### Data
142
166
 
@@ -397,7 +397,7 @@
397
397
  };
398
398
  adapters.push(HighchartsAdapter);
399
399
  }
400
- if ("google" in window) {
400
+ if (window.google && window.google.setOnLoadCallback) {
401
401
  var GoogleChartsAdapter = new function () {
402
402
  var google = window.google;
403
403
 
data/lib/chartkick.rb CHANGED
@@ -10,3 +10,17 @@ module Chartkick
10
10
  end
11
11
  self.options = {}
12
12
  end
13
+
14
+ # for multiple series
15
+ # use Enumerable so it can be called on arrays
16
+ module Enumerable
17
+ def chart_json
18
+ if is_a?(Hash) and (key = keys.first) and key.is_a?(Array) and key.size == 2
19
+ group_by{|k, v| k[0] }.map do |name, data|
20
+ {name: name, data: data.map{|k, v| [k[1], v] }}
21
+ end
22
+ else
23
+ self
24
+ end.to_json
25
+ end
26
+ end
@@ -33,19 +33,16 @@ module Chartkick
33
33
  def chartkick_chart(klass, data_source, options, &block)
34
34
  @chartkick_chart_id ||= 0
35
35
  options = chartkick_deep_merge(Chartkick.options, options)
36
- element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
37
- height = options.delete(:height) || "300px"
36
+ element_id = options[:id] || "chart-#{@chartkick_chart_id += 1}"
37
+ height = options[:height] || "300px"
38
38
  # content_for: nil must override default
39
39
  content_for = options.has_key?(:content_for) ? options.delete(:content_for) : Chartkick.content_for
40
40
 
41
- html = <<HTML
42
- <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;">
43
- Loading...
44
- </div>
45
- HTML
46
- js = <<JS
41
+ html = (options[:html] || %[<div id="%{id}" style="height: %{height}; text-align: center; color: #999; line-height: %{height}; font-size: 14px; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif;">Loading...</div>]) % {id: ERB::Util.html_escape(element_id), height: ERB::Util.html_escape(height)}
42
+
43
+ js = <<JS
47
44
  <script type="text/javascript">
48
- new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.to_json}, #{options.to_json});
45
+ new Chartkick.#{klass}(#{element_id.to_json}, #{data_source.respond_to?(:chart_json) ? data_source.chart_json : data_source.to_json}, #{options.except(:id, :height, :html).to_json});
49
46
  </script>
50
47
  JS
51
48
  if content_for
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "1.2.4"
2
+ VERSION = "1.2.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler