chartkick 0.0.1

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.

@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 17460bd45d49b250595d30520c3fcaa24bdbbd37
4
+ data.tar.gz: 8b02dd2a160331f62fd65e5ecf10e263ee49e6e6
5
+ SHA512:
6
+ metadata.gz: 1a671fb0e0386dbb8d4987729735740ba66400f4f127e6710fa79b8e232f2de654d37ffa36997b9229be8d02322cc8498cec936c68bb31388c25f85c401e9e36
7
+ data.tar.gz: 9da602eeabb3002b50c63d48faae4c22894115be6ec10735b597ea62309f06b9852f9b0540f2c4e122aa875564c1b84e571e90c31794206f0697d87089dc831d
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chartkick.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrew Kane
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,65 @@
1
+ # Chartkick
2
+
3
+ Create beautiful Javascript charts with one line of Ruby
4
+
5
+ [Demo](http://ankane.github.io/chartkick/)
6
+
7
+ :two_hearts: A perfect companion to [groupdate](http://ankane.github.io/groupdate/)
8
+
9
+ Works with Rails 3.0+
10
+
11
+ ## Usage
12
+
13
+ Line chart
14
+
15
+ ```erb
16
+ <%= line_chart User.group_by_day(:created_at).count %>
17
+ ```
18
+
19
+ Pie chart
20
+
21
+ ```erb
22
+ <%= pie_chart Goal.group("goals.name").count %>
23
+ ```
24
+
25
+ Column chart
26
+
27
+ ```erb
28
+ <%= column_chart Task.group_by_hour_of_day(:created_at).count %>
29
+ ```
30
+
31
+ Multiple series (line chart only)
32
+
33
+ ```erb
34
+ <%= line_chart Goal.all.map{|goal| {:name => goal.name, :data => goal.feats.group_by_week(:created_at).count } } %>
35
+ ```
36
+
37
+ Customize (id and height)
38
+
39
+ ```erb
40
+ <%= line_chart User.group_by_day(:created_at).count, :id => "users-chart", :height => "500px" %>
41
+ ```
42
+
43
+ ## Installation
44
+
45
+ Add this line to your application's Gemfile:
46
+
47
+ ```ruby
48
+ gem "chartkick"
49
+ ```
50
+
51
+ And add the javascript files to your views.
52
+
53
+ ```erb
54
+ <!-- 1. Google Charts first -->
55
+ <!-- 2. chartkick.js runs as a Rails engine - no need to install it -->
56
+ <%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
57
+ ```
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,127 @@
1
+ /*jslint browser: true, indent: 2 */
2
+ /*global google*/
3
+
4
+ (function() {
5
+ 'use strict';
6
+
7
+ google.load("visualization", "1.0", {"packages": ["corechart"]});
8
+
9
+ // Set chart options
10
+ var defaultOptions = {
11
+ fontName: "'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helvetica, sans-serif",
12
+ pointSize: 6,
13
+ legend: {
14
+ textStyle: {
15
+ fontSize: 12,
16
+ color: "#444"
17
+ },
18
+ alignment: "center"
19
+ },
20
+ curveType: "function",
21
+ hAxis: {
22
+ textStyle: {
23
+ color: "#666",
24
+ fontSize: 12
25
+ },
26
+ gridlines: {
27
+ color: "transparent"
28
+ },
29
+ baselineColor: "#ccc"
30
+ },
31
+ vAxis: {
32
+ textStyle: {
33
+ color: "#666",
34
+ fontSize: 12
35
+ },
36
+ baselineColor: "#ccc",
37
+ viewWindow: {
38
+ min: 0
39
+ }
40
+ },
41
+ tooltip: {
42
+ textStyle: {
43
+ color: "#666",
44
+ fontSize: 12
45
+ }
46
+ }
47
+ }, Chartkick = {
48
+ LineChart: function(elementId, series) {
49
+ google.setOnLoadCallback(function() {
50
+ // Create the data table.
51
+ var data = new google.visualization.DataTable(), rows = {}, i, j, k, s, d, rows2 = [], options, chart;
52
+
53
+ data.addColumn("datetime", "");
54
+ for (i = 0; i < series.length; i += 1) {
55
+ s = series[i];
56
+ data.addColumn("number", s.name);
57
+
58
+ for (j = 0; j < s.data.length; j += 1) {
59
+ d = s.data[j];
60
+ if (!rows[d[0]]) {
61
+ rows[d[0]] = new Array(series.length);
62
+ }
63
+ rows[d[0]][i] = d[1];
64
+ }
65
+ }
66
+
67
+ // columns
68
+ rows2 = [];
69
+ for (k in rows) {
70
+ rows2.push([new Date(k * 1000)].concat(rows[k]));
71
+ }
72
+ data.addRows(rows2);
73
+
74
+ options = defaultOptions; // TODO clone
75
+ if (series.length > 1) {
76
+ options.legend.position = "right";
77
+ } else {
78
+ options.legend.position = "none";
79
+ }
80
+ options.chartArea = null;
81
+
82
+ chart = new google.visualization.LineChart(document.getElementById(elementId));
83
+ chart.draw(data, options);
84
+ });
85
+ },
86
+ PieChart: function(elementId, series) {
87
+ google.setOnLoadCallback(function() {
88
+ // Create the data table.
89
+ var data = new google.visualization.DataTable();
90
+
91
+ // columns
92
+ data.addColumn("string", "");
93
+ data.addColumn("number", "Value");
94
+ data.addRows(series);
95
+
96
+ var options = defaultOptions; // TODO clone
97
+ options.legend.position = "right";
98
+ options.chartArea = {
99
+ top: "10%",
100
+ height: "80%"
101
+ };
102
+
103
+ var chart = new google.visualization.PieChart(document.getElementById(elementId));
104
+ chart.draw(data, options);
105
+ });
106
+ },
107
+ ColumnChart: function(elementId, series) {
108
+ google.setOnLoadCallback(function() {
109
+ var data = new google.visualization.DataTable();
110
+
111
+ // columns
112
+ data.addColumn("string", "");
113
+ data.addColumn("number", "Value");
114
+ data.addRows(series);
115
+
116
+ var options = defaultOptions; // TODO clone
117
+ options.legend.position = "none";
118
+ options.chartArea = null;
119
+
120
+ var chart = new google.visualization.ColumnChart(document.getElementById(elementId));
121
+ chart.draw(data, options);
122
+ });
123
+ }
124
+ };
125
+
126
+ window.Chartkick = Chartkick;
127
+ })();
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chartkick/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "chartkick"
8
+ spec.version = Chartkick::VERSION
9
+ spec.authors = ["Andrew Kane"]
10
+ spec.email = ["acekane1@gmail.com"]
11
+ spec.description = %q{Create beautiful Javascript charts with one line of Ruby}
12
+ spec.summary = %q{Create beautiful Javascript charts with one line of Ruby}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "railties", ">= 3.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,3 @@
1
+ require "chartkick/version"
2
+ require "chartkick/engine"
3
+ require "chartkick/helper"
@@ -0,0 +1,16 @@
1
+ module Chartkick
2
+ class Engine < ::Rails::Engine
3
+
4
+ initializer "precompile", :group => :all do |app|
5
+ # use a proc instead of a string
6
+ app.config.assets.precompile << Proc.new{|path| path == "chartkick.js" }
7
+ end
8
+
9
+ initializer "helper" do |app|
10
+ ActiveSupport.on_load(:action_view) do
11
+ include Helper
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ module Chartkick
2
+ module Helper
3
+
4
+ def line_chart(series, options = {})
5
+ unless series.is_a?(Array) and series[0].is_a?(Hash)
6
+ series = [{:name => "Value", :data => series}]
7
+ end
8
+ series.each do |s|
9
+ s[:data] = s[:data].map{|k, v| [k.is_a?(Time) ? k : Time.parse(k), v] }.sort_by{|k, v| k }.map{|k, v| [k.to_i, v.to_f] }
10
+ end
11
+
12
+ html, element_id = chartkick_div(options)
13
+ html << content_tag(:script) do
14
+ concat "new Chartkick.LineChart(#{element_id.to_json}, #{series.to_json});".html_safe
15
+ end
16
+ html
17
+ end
18
+
19
+ def pie_chart(series, options = {})
20
+ series = series.to_a
21
+ html, element_id = chartkick_div(options)
22
+ html << content_tag(:script) do
23
+ concat "new Chartkick.PieChart(#{element_id.to_json}, #{series.to_json});".html_safe
24
+ end
25
+ html
26
+ end
27
+
28
+ def column_chart(series, options = {})
29
+ series = series.map{|k,v| [k.to_s, v.to_f] }
30
+ html, element_id = chartkick_div(options)
31
+ html << content_tag(:script) do
32
+ concat "new Chartkick.ColumnChart(#{element_id.to_json}, #{series.to_json});".html_safe
33
+ end
34
+ html
35
+ end
36
+
37
+ private
38
+
39
+ def chartkick_div(options)
40
+ @chartkick_chart_id ||= 0
41
+ element_id = options[:id] || "chart-#{@chartkick_chart_id += 1}"
42
+ height = options[:height] || "300px"
43
+ [content_tag(:div, :id => element_id, :style => "height: #{height};") {}, element_id]
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Chartkick
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chartkick
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Create beautiful Javascript charts with one line of Ruby
56
+ email:
57
+ - acekane1@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - app/assets/javascripts/chartkick.js
68
+ - chartkick.gemspec
69
+ - lib/chartkick.rb
70
+ - lib/chartkick/engine.rb
71
+ - lib/chartkick/helper.rb
72
+ - lib/chartkick/version.rb
73
+ homepage: ''
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Create beautiful Javascript charts with one line of Ruby
97
+ test_files: []