flotilla-rails 0.0.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.
- data/LICENSE +20 -0
- data/README.md +24 -0
- data/lib/flotilla-rails.rb +1 -0
- data/lib/flotilla/rails.rb +3 -0
- data/lib/flotilla/rails/railtie.rb +14 -0
- data/lib/flotilla/rails/version.rb +7 -0
- data/lib/flotilla/rails/view_helper.rb +86 -0
- data/vendor/assets/javascripts/flotilla.js +2 -0
- metadata +79 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Hannes Gustafsson
|
2
|
+
Copyright (c) 2007 Joshua Miller
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
this software and associated documentation files (the "Software"), to deal in
|
6
|
+
the Software without restriction, including without limitation the rights to
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
8
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
9
|
+
so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
12
|
+
copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
20
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Flotilla
|
2
|
+
Flotilla is a Rails plugin that provides the functionality of the [flot.js](http://www.flotcharts.org) plugin for [jQuery](http://jquery.com) within Rails applications.
|
3
|
+
|
4
|
+
# flotilla-rails
|
5
|
+
This is an adaptation of [joshuamiller/flotilla](http://github.com/joshuamiller/flotilla). It is compatible with the rails asset pipeline.
|
6
|
+
|
7
|
+
To use it just include it in your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'flotilla-rails'
|
11
|
+
```
|
12
|
+
|
13
|
+
and either include the javascript inline, using the default `:js_includes` option or include the javascript in your `application.js`:
|
14
|
+
|
15
|
+
```javascript
|
16
|
+
//= require flotilla
|
17
|
+
```
|
18
|
+
|
19
|
+
and skip the generation of the inline javascript. This is all you need to plot a graph in your view. Example:
|
20
|
+
```ruby
|
21
|
+
chart("graph", { "Store 1" => { :collection => @store_one, :x => :date, :y => :sales } }, { :js_includes => false })
|
22
|
+
```
|
23
|
+
|
24
|
+
For more information you should check out the [Flotilla docs](http://flotilla.rubyforge.org/) or [joshuamiller/flotilla](http://github.com/joshuamiller/flotilla).
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'flotilla/rails' if defined?(Rails)
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'flotilla/rails/view_helper'
|
2
|
+
|
3
|
+
module Flotilla
|
4
|
+
module Rails
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
initializer "flotilla.view_helper" do |app|
|
7
|
+
ActionView::Base.send :include, ViewHelper
|
8
|
+
end
|
9
|
+
initializer "flotilla.asset_paths" do |app|
|
10
|
+
app.config.assets.paths << File.join(File.expand_path(Gem::Specification.find_by_name('flotilla-rails').gem_dir), 'vendor/assets/javascripts')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Flotilla
|
2
|
+
module Rails
|
3
|
+
module ViewHelper
|
4
|
+
|
5
|
+
# Insert a flot chart into the page. <tt>placeholder</tt> should be the
|
6
|
+
# name of the div that will hold the chart, <tt>collections</tt> is a hash
|
7
|
+
# of legends (as strings) and datasets with options as hashes, <tt>options</tt>
|
8
|
+
# contains graph-wide options.
|
9
|
+
#
|
10
|
+
# Example usage:
|
11
|
+
#
|
12
|
+
# chart("graph_div", {
|
13
|
+
# "January" => { :collection => @january, :x => :day, :y => :sales, :options => { :lines => {:show =>true}} },
|
14
|
+
# "February" => { :collection => @february, :x => :day, :y => :sales, :options => { :points => {:show =>true} } },
|
15
|
+
# :grid => { :backgroundColor => "#fffaff" })
|
16
|
+
#
|
17
|
+
# Options:
|
18
|
+
# :js_includes - includes flot library inline
|
19
|
+
# :js_tags - wraps resulting javascript in javascript tags if true. Defaults to true.
|
20
|
+
# :placeholder_tag - appends a placeholder div for graph
|
21
|
+
# :placeholder_size - specifys the size of the placeholder div
|
22
|
+
def chart(placeholder, series, options = {}, html_options = {})
|
23
|
+
html_options.reverse_merge!({ :js_includes => true, :js_tags => true, :placeholder_tag => true, :placeholder_size => "800x300" })
|
24
|
+
width, height = html_options[:placeholder_size].split("x") if html_options[:placeholder_size].respond_to?(:split)
|
25
|
+
|
26
|
+
data, x_is_date, y_is_date = series_to_json(series)
|
27
|
+
if x_is_date
|
28
|
+
options[:xaxis] ||= {}
|
29
|
+
options[:xaxis].merge!({ :mode => 'time' })
|
30
|
+
end
|
31
|
+
if y_is_date
|
32
|
+
options[:yaxis] ||= {}
|
33
|
+
options[:yaxis].merge!({ :mode => 'time' })
|
34
|
+
end
|
35
|
+
|
36
|
+
if html_options[:js_includes]
|
37
|
+
chart_js = <<-EOF
|
38
|
+
<!--[if IE]><script language="javascript" type="text/javascript" src="/assets/excanvas.js"></script><![endif]-->
|
39
|
+
<script language="javascript" type="text/javascript" src="/assets/jquery.flot.js"></script>
|
40
|
+
<script type="text/javascript">
|
41
|
+
$(function () {
|
42
|
+
jQuery.plot($('##{placeholder}'), #{data}, #{options.to_json});
|
43
|
+
});
|
44
|
+
</script>
|
45
|
+
EOF
|
46
|
+
else
|
47
|
+
chart_js = <<-EOF
|
48
|
+
$(function () {
|
49
|
+
jQuery.plot($('##{placeholder}'), #{data}, #{options.to_json});
|
50
|
+
});
|
51
|
+
EOF
|
52
|
+
end
|
53
|
+
|
54
|
+
chart_js = html_options[:js_tags] ? javascript_tag(chart_js) : chart_js
|
55
|
+
output = html_options[:placeholder_tag] ? chart_js + content_tag(:div, nil, :id => placeholder, :style => "width:#{width}px;height:#{height}px;") : chart_js
|
56
|
+
output.html_safe
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def series_to_json(series)
|
61
|
+
data_sets = []
|
62
|
+
x_is_date, y_is_date = false, false
|
63
|
+
series.each do |name, values|
|
64
|
+
set, data = {}, []
|
65
|
+
set[:label] = name
|
66
|
+
first = values[:collection].first
|
67
|
+
if first
|
68
|
+
x_is_date = first.send(values[:x]).acts_like?(:date) || first.send(values[:x]).acts_like?(:time)
|
69
|
+
y_is_date = first.send(values[:y]).acts_like?(:date) || first.send(values[:y]).acts_like?(:time)
|
70
|
+
end
|
71
|
+
values[:collection].each do |object|
|
72
|
+
x_value, y_value = object.send(values[:x]), object.send(values[:y])
|
73
|
+
x = x_is_date ? x_value.to_time.to_i * 1000 : x_value.to_f
|
74
|
+
y = y_is_date ? y_value.to_time.to_i * 1000 : y_value.to_f
|
75
|
+
data << [x,y]
|
76
|
+
end
|
77
|
+
set[:data] = data
|
78
|
+
values[:options].each {|option, parameters| set[option] = parameters } if values[:options]
|
79
|
+
data_sets << set
|
80
|
+
end
|
81
|
+
return data_sets.to_json, x_is_date, y_is_date
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flotilla-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Hannes Gustafsson
|
9
|
+
- Joshua Miller
|
10
|
+
- Mathias Sulser
|
11
|
+
- Jerry Cheung
|
12
|
+
- Logan Leger
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
date: 2012-10-25 00:00:00.000000000Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: json
|
20
|
+
requirement: &70272598552880 !ruby/object:Gem::Requirement
|
21
|
+
none: false
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.7.3
|
26
|
+
type: :runtime
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: *70272598552880
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: flot-rails
|
31
|
+
requirement: &70272598552440 !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ~>
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 0.0.2
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: *70272598552440
|
40
|
+
description: Flotilla compatible with the asset pipeline.
|
41
|
+
email:
|
42
|
+
- hnnsgstfssn@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/flotilla/rails/railtie.rb
|
48
|
+
- lib/flotilla/rails/version.rb
|
49
|
+
- lib/flotilla/rails/view_helper.rb
|
50
|
+
- lib/flotilla/rails.rb
|
51
|
+
- lib/flotilla-rails.rb
|
52
|
+
- vendor/assets/javascripts/flotilla.js
|
53
|
+
- LICENSE
|
54
|
+
- README.md
|
55
|
+
homepage: http://github.com/hnnsgstfssn/flotilla-rails
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: Flotilla compatible with the asset pipeline.
|
79
|
+
test_files: []
|