simple-gcharts 0.1.0
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 +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +113 -0
- data/Rakefile +2 -0
- data/app/helpers/google_chart_helper.rb +17 -0
- data/lib/simple-gcharts/version.rb +3 -0
- data/lib/simple-gcharts.rb +8 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef9c9bbefb6c2ec887e3ff317194365baf920f06
|
4
|
+
data.tar.gz: 787ffd771ef5149652ff94244cea7758e44f073c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e621639e7b743378288e634820d18b240e40753a974709c4d2d39eb2a35911180ecbb6c906ffa51f7d3c3a0a3c313e7e6fdf7b4935542b4ad993dc5122d2b253
|
7
|
+
data.tar.gz: 4ea982391e2998a0abd838e8cc86268e5a2c7d1d06eaf12200d04ea21f12bec57982891c9c00dc1f6204d1327bcb745edbfc72fa81d4725de1f0ab45f2580430
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Charles Julian Knight
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Simple GCharts
|
2
|
+
|
3
|
+
Create Google Charts in your views using ruby, with no Javascript required. This library
|
4
|
+
will serialize your data andautomatically load any required charts packages, and render
|
5
|
+
your charts for you. Requires jQuery.
|
6
|
+
|
7
|
+
## Example [PieChart](https://developers.google.com/chart/interactive/docs/gallery/piechart#example)
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
class ActivitiesController < ActionController::Base
|
11
|
+
def graphs
|
12
|
+
@activities = {
|
13
|
+
'Work' => 11,
|
14
|
+
'Eat' => 2,
|
15
|
+
'Commute' => 2,
|
16
|
+
'Watch TV' => 2,
|
17
|
+
'Sleep' => 7
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
```erb
|
24
|
+
# views/activities/graphs.html.erb
|
25
|
+
<%= google_chart :pie, ['Task', 'Hours per Day'], @activities.map { |k,v| [k, v] }, { title: 'My Daily Activities' } %>
|
26
|
+
```
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem 'simple-gcharts'
|
34
|
+
```
|
35
|
+
|
36
|
+
And then execute:
|
37
|
+
|
38
|
+
$ bundle
|
39
|
+
|
40
|
+
Or install it yourself as:
|
41
|
+
|
42
|
+
$ gem install simple-gcharts
|
43
|
+
|
44
|
+
Add script to `application.js` (or appropriate page)
|
45
|
+
|
46
|
+
```js
|
47
|
+
//= require jquery
|
48
|
+
//= require simple-gcharts
|
49
|
+
```
|
50
|
+
|
51
|
+
## Usage
|
52
|
+
|
53
|
+
See the [Google Charts Documentation](https://developers.google.com/chart) for chart type descriptions and options.
|
54
|
+
|
55
|
+
### google_chart
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
def google_chart type, headers, data, opts={}, chart_id="chart-#{SecureRandom.hex(10)}", parent_tag=:div
|
59
|
+
```
|
60
|
+
|
61
|
+
| Argument | Description |
|
62
|
+
| ---- | ---- |
|
63
|
+
| `type` | The type of chart (e.g. `:line`, see [below](#chart-types)) |
|
64
|
+
| `headers` | The column data. Can be column name or object |
|
65
|
+
| `data` | A 2-D array of data rows. `headers` and `data` combined are passed to [`arrayToDataTable()`](https://developers.google.com/chart/interactive/docs/datatables_dataviews#arraytodatatable) |
|
66
|
+
| `opts` | Options passed to `chart.draw()` |
|
67
|
+
| `chart_id` | The HTML id attribute to use for the chart |
|
68
|
+
| `parent_tag` | The tag used to wrap the child tags |
|
69
|
+
|
70
|
+
Ruby can't make Javascript date objects, but fortunately Google Charts supports [an alternate syntax](https://developers.google.com/chart/interactive/docs/datesandtimes#dates-and-times-using-the-date-string-representation) for date and time datatypes. You can use `chart_date_format` to convert DateTime objects to the proper format.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
def chart_date_format(datetime, time=false)
|
74
|
+
if time
|
75
|
+
datetime.strftime "Date(%Y, %m, %d, %H, %M, %S)"
|
76
|
+
else
|
77
|
+
datetime.strftime "Date(%Y, %m, %d)"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
### Chart Types
|
83
|
+
|
84
|
+
| Types |
|
85
|
+
| ---- |
|
86
|
+
| :annotation |
|
87
|
+
| :area |
|
88
|
+
| :bubble |
|
89
|
+
| :bar |
|
90
|
+
| :calendar |
|
91
|
+
| :candlestick |
|
92
|
+
| :column |
|
93
|
+
| :combo |
|
94
|
+
| :gantt |
|
95
|
+
| :gauge |
|
96
|
+
| :geochart |
|
97
|
+
| :histogram |
|
98
|
+
| :line |
|
99
|
+
| :map |
|
100
|
+
| :orgchart |
|
101
|
+
| :pie |
|
102
|
+
| :snakey |
|
103
|
+
| :scatter |
|
104
|
+
| :stepped |
|
105
|
+
| :table |
|
106
|
+
| :timeline |
|
107
|
+
| :treemap |
|
108
|
+
| :word |
|
109
|
+
|
110
|
+
## License
|
111
|
+
|
112
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
113
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
module GoogleChartHelper
|
2
|
+
|
3
|
+
def google_chart type, headers, data, opts={}, chart_id="chart-#{SecureRandom.hex(10)}", parent_tag=:div
|
4
|
+
content_tag(parent_tag) do
|
5
|
+
c = content_tag(:script, {data: data.prepend(headers), options: opts}.to_json, {type: "text/json", chart: chart_id}, false)
|
6
|
+
c << content_tag(:div, "", class: "google-chart", id: chart_id, chart_type: type)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def chart_date_format(datetime, time=false)
|
11
|
+
if time
|
12
|
+
datetime.strftime "Date(%Y, %m, %d, %H, %M, %S)"
|
13
|
+
else
|
14
|
+
datetime.strftime "Date(%Y, %m, %d)"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple-gcharts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Charles Julian Knight
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jquery-rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: A helper and some javascript to make it easy to generate Google Charts.
|
70
|
+
email:
|
71
|
+
- charles@rabidaudio.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- app/helpers/google_chart_helper.rb
|
80
|
+
- lib/simple-gcharts.rb
|
81
|
+
- lib/simple-gcharts/version.rb
|
82
|
+
homepage: https://github.com/rabidaudio/simple-gcharts
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata: {}
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 2.4.8
|
103
|
+
signing_key:
|
104
|
+
specification_version: 4
|
105
|
+
summary: A simple library for creating Google Charts in Rails.
|
106
|
+
test_files: []
|