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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +16 -2
- data/app/assets/javascripts/chartkick.js +13 -2
- data/lib/chartkick.rb +2 -0
- data/lib/chartkick/helper.rb +11 -1
- data/lib/chartkick/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ad83e0908f7d19f80e1777c9b06b1bc9bb4e5f
|
4
|
+
data.tar.gz: eae7fc7ec9cb6ae8e1a207ae11fe5e728953cf95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1703d7ff64748ebd96aa952e9804f40b7abfeb719a18d4730529612d5fe17513ee95a1d6cb8da5b54f8148c2b0ccdb135c28e5ed2f095ddcb081a3f310390425
|
7
|
+
data.tar.gz: c6e81a464f25d378e64bb8976681e51a2d5b5cdb97eff53379c09874b24d02a0d8b0afa30ea80bbe4f7e78624c37db79c62c7e8b395d085b0d9193e8658768c6
|
data/CHANGELOG.md
CHANGED
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
|
-
|
129
|
+
### Global Options
|
130
|
+
|
131
|
+
To set options for all of your charts, create an initializer with:
|
122
132
|
|
123
133
|
```ruby
|
124
|
-
Chartkick.
|
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
|
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 || {});
|
data/lib/chartkick.rb
CHANGED
data/lib/chartkick/helper.rb
CHANGED
@@ -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
|
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
|
data/lib/chartkick/version.rb
CHANGED