chartkick 1.2.3 → 1.2.4

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: c3d82466b6703318eaead4b787e2029ed81b6419
4
- data.tar.gz: 6a94782f3c4fbfd27171e03e89e1288e97221287
3
+ metadata.gz: c4ad83e0908f7d19f80e1777c9b06b1bc9bb4e5f
4
+ data.tar.gz: eae7fc7ec9cb6ae8e1a207ae11fe5e728953cf95
5
5
  SHA512:
6
- metadata.gz: b14d7a3cd54eb4d67af1efa3776c7f9c5bf6c07c8d8d22aff8294312236095b1ab5de4850c330d938aae2f0b21108c31aacad0da73a0248b190da79fbf637884
7
- data.tar.gz: ce3df7336aa518bc1c3859c7e113607bd851779c5efc23b483f1154fdc2913d207ab0fffc6ed86b82f9743a1d656f4034bba4e67520769c2bff06d851c006684
6
+ metadata.gz: 1703d7ff64748ebd96aa952e9804f40b7abfeb719a18d4730529612d5fe17513ee95a1d6cb8da5b54f8148c2b0ccdb135c28e5ed2f095ddcb081a3f310390425
7
+ data.tar.gz: c6e81a464f25d378e64bb8976681e51a2d5b5cdb97eff53379c09874b24d02a0d8b0afa30ea80bbe4f7e78624c37db79c62c7e8b395d085b0d9193e8658768c6
@@ -1,3 +1,8 @@
1
+ ## 1.2.4
2
+
3
+ - Added global options
4
+ - Added `colors` option
5
+
1
6
  ## 1.2.3
2
7
 
3
8
  - Added geo chart
data/README.md CHANGED
@@ -88,6 +88,12 @@ Min and max values (except pie chart)
88
88
  <%= line_chart data, min: 1000, max: 5000 %>
89
89
  ```
90
90
 
91
+ Colors
92
+
93
+ ```erb
94
+ <%= line_chart data, colors: ["pink", "#999"] %>
95
+ ```
96
+
91
97
  Stacked columns or bars
92
98
 
93
99
  ```erb
@@ -106,6 +112,8 @@ You can pass options directly to the charting library with:
106
112
  <%= line_chart data, library: {backgroundColor: "#eee"} %>
107
113
  ```
108
114
 
115
+ 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
+
109
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.
110
118
 
111
119
  ```erb
@@ -118,10 +126,16 @@ Then, in your layout:
118
126
  <%= yield_content :charts_js %> <%# Padrino %>
119
127
  ```
120
128
 
121
- To make this the default, create an initializer with:
129
+ ### Global Options
130
+
131
+ To set options for all of your charts, create an initializer with:
122
132
 
123
133
  ```ruby
124
- Chartkick.content_for = :charts_js
134
+ Chartkick.options = {
135
+ height: "400px",
136
+ colors: ["pink", "#999"],
137
+ content_for: :charts_js
138
+ }
125
139
  ```
126
140
 
127
141
  ### Data
@@ -129,6 +129,10 @@
129
129
  setStacked(options);
130
130
  }
131
131
 
132
+ if (opts.colors) {
133
+ options.colors = opts.colors;
134
+ }
135
+
132
136
  // merge library last
133
137
  options = merge(options, opts.library || {});
134
138
 
@@ -323,7 +327,11 @@
323
327
  };
324
328
 
325
329
  this.renderPieChart = function (chart) {
326
- var options = merge(defaultOptions, chart.options.library || {});
330
+ var chartOptions = {};
331
+ if (chart.options.colors) {
332
+ chartOptions.colors = chart.options.colors;
333
+ }
334
+ var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
327
335
  options.chart.renderTo = chart.element.id;
328
336
  options.series = [{
329
337
  type: "pie",
@@ -536,6 +544,9 @@
536
544
  height: "80%"
537
545
  }
538
546
  };
547
+ if (chart.options.colors) {
548
+ chartOptions.colors = chart.options.colors;
549
+ }
539
550
  var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
540
551
 
541
552
  var data = new google.visualization.DataTable();
@@ -600,7 +611,7 @@
600
611
  var chartOptions = {
601
612
  legend: "none",
602
613
  colorAxis: {
603
- colors: ["#f6c7b6", "#ce502d"]
614
+ colors: chart.options.colors || ["#f6c7b6", "#ce502d"]
604
615
  }
605
616
  };
606
617
  var options = merge(merge(defaultOptions, chartOptions), chart.options.library || {});
@@ -6,5 +6,7 @@ require "chartkick/sinatra" if defined?(Sinatra)
6
6
  module Chartkick
7
7
  class << self
8
8
  attr_accessor :content_for
9
+ attr_accessor :options
9
10
  end
11
+ self.options = {}
10
12
  end
@@ -32,7 +32,7 @@ module Chartkick
32
32
 
33
33
  def chartkick_chart(klass, data_source, options, &block)
34
34
  @chartkick_chart_id ||= 0
35
- options = options.dup
35
+ options = chartkick_deep_merge(Chartkick.options, options)
36
36
  element_id = options.delete(:id) || "chart-#{@chartkick_chart_id += 1}"
37
37
  height = options.delete(:height) || "300px"
38
38
  # content_for: nil must override default
@@ -57,5 +57,15 @@ JS
57
57
  html.respond_to?(:html_safe) ? html.html_safe : html
58
58
  end
59
59
 
60
+ # https://github.com/rails/rails/blob/master/activesupport/lib/active_support/core_ext/hash/deep_merge.rb
61
+ def chartkick_deep_merge(hash_a, hash_b)
62
+ hash_a = hash_a.dup
63
+ hash_b.each_pair do |k,v|
64
+ tv = hash_a[k]
65
+ hash_a[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
66
+ end
67
+ hash_a
68
+ end
69
+
60
70
  end
61
71
  end
@@ -1,3 +1,3 @@
1
1
  module Chartkick
2
- VERSION = "1.2.3"
2
+ VERSION = "1.2.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane