chartjs-ror 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -8
- data/lib/chartjs.rb +12 -3
- data/lib/chartjs/chart_helpers.rb +5 -3
- data/lib/chartjs/engine.rb +9 -0
- data/lib/chartjs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70560e2b456473a72835faec8fb3747a4b8ca1c3
|
4
|
+
data.tar.gz: a0ac4716a25acd1fe9c5d982b739147314ded6a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d8bf948ec87c2d2df3e29cae59726cd3613cae13e58d94c5f311c54e8ba2fcafa3db8336c62c642419d984cd023415048ca1e55ad8a5abb5fcf61dc2bd9a5b7
|
7
|
+
data.tar.gz: 41e7684be82798cf71c7698389733507af5477997da92e77c089a566355ee58f2018a1e263c4e4b1f4e41800e1f408375d061f9611790cb1fc82280158fbc508
|
data/README.md
CHANGED
@@ -5,8 +5,13 @@ Simplifies using [Chart.js][] in Rails views.
|
|
5
5
|
* All of Chart.js's features via one line of Ruby.
|
6
6
|
* Renders charts on page load rather than DOMContentReady ([reason][browsersupport]).
|
7
7
|
* Animates unless you have Modernizr and it doesn't detect canvas support ([reason][browsersupport]). You can manually override this.
|
8
|
-
* Optional alternative
|
9
|
-
*
|
8
|
+
* Optional alternative abscissa scale calculations (see [Chart.js#132][calculations]).
|
9
|
+
* Optional utility method for filling in gaps in integer series.
|
10
|
+
|
11
|
+
|
12
|
+
## Current Chart.js version
|
13
|
+
|
14
|
+
This gem includes [Chart.js v1.0.1](https://github.com/nnnick/Chart.js/tree/v1.0.1).
|
10
15
|
|
11
16
|
|
12
17
|
## Installation
|
@@ -35,12 +40,30 @@ Each chart type has a corresponding helper for your views. The helper methods t
|
|
35
40
|
|
36
41
|
|
37
42
|
```erb
|
38
|
-
<%= line_chart
|
39
|
-
<%= bar_chart
|
40
|
-
<%= radar_chart
|
41
|
-
<%=
|
42
|
-
<%= pie_chart
|
43
|
-
<%= doughnut_chart
|
43
|
+
<%= line_chart data, options %>
|
44
|
+
<%= bar_chart data, options %>
|
45
|
+
<%= radar_chart data, options %>
|
46
|
+
<%= polar_area_chart data, options %>
|
47
|
+
<%= pie_chart data, options %>
|
48
|
+
<%= doughnut_chart data, options %>
|
49
|
+
```
|
50
|
+
|
51
|
+
If you don't want these helpers – perhaps they clash with other methods in your views – add this initializer to your app:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# config/initializers/chartjs.rb
|
55
|
+
Chartjs.no_confict!
|
56
|
+
```
|
57
|
+
|
58
|
+
You can use these helpers instead:
|
59
|
+
|
60
|
+
```erb
|
61
|
+
<%= chartjs_line_chart data, options %>
|
62
|
+
<%= chartjs_bar_chart data, options %>
|
63
|
+
<%= chartjs_radar_chart data, options %>
|
64
|
+
<%= chartjs_polar_area_chart data, options %>
|
65
|
+
<%= chartjs_pie_chart data, options %>
|
66
|
+
<%= chartjs_doughnut_chart data, options %>
|
44
67
|
```
|
45
68
|
|
46
69
|
For example, to render a [line chart][linechart] in Javascript:
|
data/lib/chartjs.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
-
require 'chartjs/engine'
|
2
|
-
require "chartjs/version"
|
3
|
-
|
4
1
|
module Chartjs
|
2
|
+
@@no_conflict = false
|
3
|
+
|
4
|
+
def self.no_conflict!
|
5
|
+
@@no_conflict = true
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.no_conflict
|
9
|
+
@@no_conflict
|
10
|
+
end
|
5
11
|
end
|
12
|
+
|
13
|
+
require 'chartjs/engine'
|
14
|
+
require "chartjs/version"
|
@@ -3,9 +3,9 @@ module Chartjs
|
|
3
3
|
|
4
4
|
%w[ Line Bar Radar PolarArea Pie Doughnut ].each do |type|
|
5
5
|
camel_type = type.gsub(/(\w)([A-Z])/, '\1_\2').downcase
|
6
|
-
define_method "#{camel_type}_chart" do |data, options = {}| # def
|
7
|
-
chart type, data, options
|
8
|
-
end
|
6
|
+
define_method "chartjs_#{camel_type}_chart" do |data, options = {}| # def chartjs_polar_area_chart(data, options = {})
|
7
|
+
chart type, data, options # chart 'PolarArea', data, options
|
8
|
+
end # end
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -37,6 +37,8 @@ module Chartjs
|
|
37
37
|
<<-END.squish.html_safe
|
38
38
|
(function() {
|
39
39
|
var initChart = function() {
|
40
|
+
window.Chart && window.Chart[#{element_id.to_json}] && window.Chart[#{element_id.to_json}].destroy();
|
41
|
+
|
40
42
|
var data = #{data.to_json};
|
41
43
|
var opts = #{options.to_json};
|
42
44
|
if (!("animation" in opts)) {
|
data/lib/chartjs/engine.rb
CHANGED
@@ -5,6 +5,15 @@ module Chartjs
|
|
5
5
|
class Engine < Rails::Engine
|
6
6
|
initializer 'chartjs.chart_helpers' do
|
7
7
|
ActionView::Base.send :include, Chartjs::ChartHelpers
|
8
|
+
|
9
|
+
unless ::Chartjs.no_conflict
|
10
|
+
ActionView::Base.class_eval do
|
11
|
+
%w[ line bar radar polar_area pie doughnut ].each do |type|
|
12
|
+
alias :"#{type}_chart" :"chartjs_#{type}_chart"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
ActionView::Base.send :include, Chartjs::AxisHelpers
|
9
18
|
end
|
10
19
|
end
|
data/lib/chartjs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chartjs-ror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|