mountain-goat 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/generators/mg/mg_generator.rb +2 -2
- data/init.rb +0 -1
- data/lib/mountain-goat.rb +0 -2
- data/lib/mountain-goat/controllers/mg/report_items_controller.rb +1 -1
- data/lib/mountain-goat/controllers/mg/tests_controller.rb +0 -16
- data/lib/mountain-goat/m_g.rb +20 -19
- data/lib/mountain-goat/models/mg/choice.rb +6 -0
- data/lib/mountain-goat/public/g-funnel.js +1 -1
- data/lib/mountain-goat/version.rb +1 -1
- data/lib/mountain-goat/views/mountain_goat/mg/records/_records.html.erb +1 -1
- data/lib/mountain-goat/views/mountain_goat/mg/records/index.html.erb +0 -1
- data/lib/mountain-goat/views/mountain_goat/mg/reports/_report.html.erb +1 -1
- data/lib/mountain-goat/views/mountain_goat/mg/tests/show.html.erb +14 -11
- metadata +5 -15
- data/lib/mgflotilla.rb +0 -170
- data/lib/mountain-goat/public/jquery.flot.js +0 -2615
- data/lib/mountain-goat/views/mountain_goat/mg/goals/.tmp_show.html.erb.86489~ +0 -32
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__chart.html.erb.73596~ +0 -18
- data/lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__show.html.erb.52502~ +0 -29
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_form.html.erb.42949~ +0 -26
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_report_items.html.erb.96264~ +0 -5
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_edit.html.erb.39909~ +0 -33
- data/lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_show.html.erb.37905~ +0 -18
- data/lib/mountain-goat/views/mountain_goat/mg/tests/.tmp_show.html.erb.19989~ +0 -63
data/README.md
CHANGED
@@ -40,13 +40,13 @@ For more information, read my blog post on how mountain goat quickly accomplishe
|
|
40
40
|
|
41
41
|
## Upgrade from < 1.0.0
|
42
42
|
|
43
|
-
If you are upgrading from Mountain Goat < 1.0.
|
43
|
+
If you are upgrading from Mountain Goat < 1.0.4, please run the following command (please overwrite mountain-goat.yml when prompted):
|
44
44
|
|
45
|
-
./script/generate mg --update=1.0.0,1.0.
|
45
|
+
./script/generate mg --update=1.0.0,1.0.4
|
46
46
|
|
47
47
|
rake db:migrate
|
48
48
|
|
49
|
-
This will install new migrations necessary for version 1.0.
|
49
|
+
This will install new migrations necessary for version 1.0.4. Leave out the 1.0.0 from the command if you are upgrading from version 1.0.0.
|
50
50
|
|
51
51
|
## Install
|
52
52
|
|
@@ -267,6 +267,7 @@ As mountain goat is a suite that is added into your project dynamically, the fol
|
|
267
267
|
* mg_reports
|
268
268
|
|
269
269
|
## Change log
|
270
|
+
1.0.4 - More Bug-fixes / Remove Flot Graphs Entirely
|
270
271
|
1.0.3 - Some overall bug-fixes and start to use Raphael Graphs
|
271
272
|
1.0.2 - Big UI overhaul ~ Robert
|
272
273
|
- Renamed objects to reflect real-world thinking (e.g. metric => test)
|
@@ -2,7 +2,7 @@ class MgGenerator < Rails::Generator::Base
|
|
2
2
|
def add_options!(opt)
|
3
3
|
opt.on('-p', '--password=password', String, "Your password to access Mountain Goat") { |v| options[:password] = v}
|
4
4
|
opt.on('-w', '--wkhtmltopdf=/path/to/dir', String, "Path to installation of wkhtmltopdf (optional)") { |v| options[:wkhtmltopdf] = v}
|
5
|
-
opt.on('-u', '--update=1.0.0,1.0.
|
5
|
+
opt.on('-u', '--update=1.0.0,1.0.4', String, "If you have previously installed Mountain Goat, use to generate *update* tables.") { |v| options[:update] = v}
|
6
6
|
puts <<-HELPFUL_INSTRUCTIONS
|
7
7
|
|
8
8
|
Mountain Goat is your home for in-house bandit testing.
|
@@ -42,7 +42,7 @@ class MgGenerator < Rails::Generator::Base
|
|
42
42
|
m.migration_template 'update_mountain_goat_tables.rb', 'db/migrate', { :migration_file_name => "update_mountain_goat_tables" }
|
43
43
|
end
|
44
44
|
|
45
|
-
if update.include?("1.0.3") || update.include?("1.0.2") || update.include?("1.0.1")
|
45
|
+
if update.include?("1.0.4") || update.include?("1.0.3") || update.include?("1.0.2") || update.include?("1.0.1")
|
46
46
|
m.migration_template 'update_mountain_goat_tables_v2.rb', 'db/migrate', { :migration_file_name => "update_mountain_goat_tables_v2" }
|
47
47
|
end
|
48
48
|
|
data/init.rb
CHANGED
data/lib/mountain-goat.rb
CHANGED
@@ -4,8 +4,6 @@ require 'active_support'
|
|
4
4
|
require 'action_controller'
|
5
5
|
require 'action_controller/routing'
|
6
6
|
|
7
|
-
require File.join([File.dirname(__FILE__), 'mgflotilla'])
|
8
|
-
|
9
7
|
require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/mg'])
|
10
8
|
require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/mountain_goat_controller'])
|
11
9
|
require File.join([File.dirname(__FILE__), 'mountain-goat/controllers/mg/tests_controller'])
|
@@ -22,7 +22,7 @@ class Mg::ReportItemsController < Mg
|
|
22
22
|
raise ArgumentError, "Invalid report" if @report.nil?
|
23
23
|
|
24
24
|
@report_item = @report.mg_report_items.new(params[:report_item].clone.delete_if { |k, v| k.intern == :reportable || k.intern == :pivot } )
|
25
|
-
@report_item.order = @report.mg_report_items.maximum(:order) + 1 # @report.mg_report_items.to_a.map { |ri| ri.order }.push(0).max + 1# -- weird sqlite3 bugs
|
25
|
+
@report_item.order = ( @report.mg_report_items.maximum(:order) || 0 ) + 1 # @report.mg_report_items.to_a.map { |ri| ri.order }.push(0).max + 1# -- weird sqlite3 bugs
|
26
26
|
|
27
27
|
if !params[:report_item][:reportable].blank?
|
28
28
|
id, model = params[:report_item][:reportable].split('-')
|
@@ -18,22 +18,6 @@ class Mg::TestsController < Mg
|
|
18
18
|
# GET /mg/tests/1.xml
|
19
19
|
def show
|
20
20
|
@test = Mg::Test.find(params[:id])
|
21
|
-
|
22
|
-
@rates = {}
|
23
|
-
@rates[:served] = []
|
24
|
-
@rates[:reward_count] = []
|
25
|
-
@rates[:reward_rates] = []
|
26
|
-
@rates[:titles] = {}
|
27
|
-
i = 0
|
28
|
-
@test.mg_choices.each do |mv|
|
29
|
-
@rates[:served].push( { :choice_type => i, :value => mv.served } )
|
30
|
-
@rates[:reward_count].push( { :choice_type => i, :value => mv.reward_count } )
|
31
|
-
@rates[:reward_rates].push( { :choice_type => i, :value => mv.reward_rate } )
|
32
|
-
@rates[:titles].merge!({i => mv.name})
|
33
|
-
i += 1
|
34
|
-
end
|
35
|
-
|
36
|
-
logger.warn @rates[:titles].inspect
|
37
21
|
|
38
22
|
respond_to do |format|
|
39
23
|
format.html # show.html.erb
|
data/lib/mountain-goat/m_g.rb
CHANGED
@@ -1,23 +1,4 @@
|
|
1
1
|
|
2
|
-
################
|
3
|
-
# Setup PDFKit #
|
4
|
-
################
|
5
|
-
|
6
|
-
begin
|
7
|
-
require 'pdfkit'
|
8
|
-
rescue LoadError
|
9
|
-
raise "Mountain Goat Reports will not work without the 'pdfkit' gem (please run `gem install pdfkit`)"
|
10
|
-
end
|
11
|
-
|
12
|
-
######################
|
13
|
-
# Setup svg-graph #
|
14
|
-
######################
|
15
|
-
|
16
|
-
begin
|
17
|
-
require 'SVG/Graph/TimeSeries'
|
18
|
-
rescue LoadError
|
19
|
-
raise "Mountain Goat Reports will not work without the 'svg-graph' gem (please run `gem install svg-graph`)"
|
20
|
-
end
|
21
2
|
|
22
3
|
############################
|
23
4
|
# TODO: Verify Email Setup #
|
@@ -25,6 +6,26 @@ end
|
|
25
6
|
|
26
7
|
class MG
|
27
8
|
def self.deliver(delivery_set = nil)
|
9
|
+
################
|
10
|
+
# Setup PDFKit #
|
11
|
+
################
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'pdfkit'
|
15
|
+
rescue LoadError
|
16
|
+
raise "Mountain Goat Reports will not work without the 'pdfkit' gem (please run `gem install pdfkit`)"
|
17
|
+
end
|
18
|
+
|
19
|
+
######################
|
20
|
+
# Setup svg-graph #
|
21
|
+
######################
|
22
|
+
|
23
|
+
begin
|
24
|
+
require 'SVG/Graph/TimeSeries'
|
25
|
+
rescue LoadError
|
26
|
+
raise "Mountain Goat Reports will not work without the 'svg-graph' gem (please run `gem install svg-graph`)"
|
27
|
+
end
|
28
|
+
|
28
29
|
mg_yml = YAML::load(File.open("#{RAILS_ROOT}/config/mountain-goat.yml"))
|
29
30
|
|
30
31
|
if mg_yml.blank? || mg_yml[RAILS_ENV].blank? || mg_yml[RAILS_ENV]['wkhtmltopdf'].blank?
|
@@ -47,4 +47,10 @@ class Mg::Choice < ActiveRecord::Base
|
|
47
47
|
return nil if self.reward_count == 0 || self.reward_count.nil? || self.reward.nil?
|
48
48
|
return self.reward / self.reward_count.to_f
|
49
49
|
end
|
50
|
+
|
51
|
+
# What is the average reward given to this choice
|
52
|
+
def avg_points_per_serve
|
53
|
+
return nil if self.served == 0 || self.served.nil? || self.reward.nil?
|
54
|
+
return self.reward / self.served.to_f
|
55
|
+
end
|
50
56
|
end
|
@@ -58,7 +58,7 @@ Raphael.fn.g.funnelchart = function (cx, cy, cw, ch, values, opts) {
|
|
58
58
|
var path = trap(sx0, sy0, w0, w1, sh);
|
59
59
|
var p = this.path(path).attr({fill: opts.colors && opts.colors[i] || this.g.colors[i] || "#666", stroke: opts.stroke || "#fff", "stroke-width": (opts.strokewidth == null ? 1 : opts.strokewidth), "stroke-linejoin": "round"});
|
60
60
|
if (values[i].labeltext)
|
61
|
-
p.insetLabel = this.text(sx0 + w0 / 2.0, sy0 + sh / 3.0, values[i].labeltext + ( i > 0 ? ( " " + ( ( values[i]
|
61
|
+
p.insetLabel = this.text(sx0 + w0 / 2.0, sy0 + sh / 3.0, values[i].labeltext + ( i > 0 ? ( " " + ( ( values[i] * 100 / values[i - 1] ).toFixed(2) ) + "%" ) : "")).attr({font: "20px Helvetica", stroke: "#fff", fill: "#bbb", "fill-opacity": 0.95, "stroke-opacity": 0 });
|
62
62
|
|
63
63
|
p.value = values[i];
|
64
64
|
sectors.push(p);
|
@@ -2,7 +2,6 @@
|
|
2
2
|
<h1><% if @goal %><%=h @goal.name %><% else %>Comprehensive<% end %> Records</h1>
|
3
3
|
<div class="container-content">
|
4
4
|
<div class="recent-record" data-reload="true" data-record-id="<%= @records.count > 0 ? @records.first.id : -1 %>" data-goal-id="<%= @goal ? @goal.id : '' %>"></div>
|
5
|
-
<a class="button" href="javascript:void(0)" class="reload">Reload</a>
|
6
5
|
|
7
6
|
<% if @records.count > 0 %>
|
8
7
|
<ul class="record-list">
|
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
<h4><%=h report.description %></h4>
|
17
17
|
|
18
|
-
<% report.
|
18
|
+
<% report.mg_report_items.each do |report_item| %>
|
19
19
|
<div class="svg-chart">
|
20
20
|
<%= render 'mg/report_items/svg_chart', :report_item => report_item %>
|
21
21
|
</div>
|
@@ -8,21 +8,24 @@
|
|
8
8
|
<% else %>
|
9
9
|
<div class="statboard">
|
10
10
|
<div class="flyer-analysis statpad">
|
11
|
-
<div class="title">
|
11
|
+
<div class="title">Serves</div>
|
12
12
|
<div class="statbody">
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
<div id="chart_item_mg_test_#{@test.id}_served %>" data-raphael="pie"
|
14
|
+
data-x="<%= @test.mg_choices.map { |c| "'#{c.name}'" }.join(',') %>"
|
15
|
+
data-y="<%= @test.mg_choices.map { |c| c.served }.join(',') %>"
|
16
|
+
style="width: 425px; height: 260px;" />
|
17
|
+
</div>
|
17
18
|
|
18
19
|
</div>
|
19
20
|
</div>
|
20
21
|
<div class="flyer-analysis statpad">
|
21
|
-
<div class="title">
|
22
|
+
<div class="title">Avg. Rewards</div>
|
22
23
|
<div class="statbody">
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
<div id="chart_item_mg_test_#{@test.id}_avg_reward %>" data-raphael="pie"
|
25
|
+
data-x="<%= @test.mg_choices.map { |c| "'#{c.name}'" }.join(',') %>"
|
26
|
+
data-y="<%= @test.mg_choices.map { |c| c.reward / c.served unless c.reward.blank? || c.served.blank? || c.served == 0 }.join(',') %>"
|
27
|
+
style="width: 425px; height: 260px;" />
|
28
|
+
</div>
|
26
29
|
|
27
30
|
</div>
|
28
31
|
</div>
|
@@ -46,8 +49,8 @@
|
|
46
49
|
<span class="category choice"><%=h choice.name %></span>
|
47
50
|
<span class="category served"><%= choice.served %></span>
|
48
51
|
<span class="category hit-points"><%= choice.reward || "None" %></span>
|
49
|
-
<span class="category hit-points-avg"><%=h choice.
|
50
|
-
<span class="category actions"><a href="<%=
|
52
|
+
<span class="category hit-points-avg"><%=h choice.avg_points_per_serve || "N/A" %></span>
|
53
|
+
<span class="category actions"><a href="<%= edit_mg_choice_url choice %>">Edit</a></span>
|
51
54
|
</li>
|
52
55
|
<% end %>
|
53
56
|
</ul>
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mountain-goat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Geoffrey Hayes
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-10-
|
19
|
+
date: 2011-10-13 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +80,6 @@ files:
|
|
80
80
|
- generators/mg/templates/update_mountain_goat_tables_v2.rb
|
81
81
|
- init.rb
|
82
82
|
- install.rb
|
83
|
-
- lib/mgflotilla.rb
|
84
83
|
- lib/mountain-goat.rb
|
85
84
|
- lib/mountain-goat/analytics.rb
|
86
85
|
- lib/mountain-goat/controllers/mg/choices_controller.rb
|
@@ -118,7 +117,6 @@ files:
|
|
118
117
|
- lib/mountain-goat/public/g-raphael-min.js
|
119
118
|
- lib/mountain-goat/public/jqModel.css
|
120
119
|
- lib/mountain-goat/public/jqModel.js
|
121
|
-
- lib/mountain-goat/public/jquery.flot.js
|
122
120
|
- lib/mountain-goat/public/jquery.raphael.js
|
123
121
|
- lib/mountain-goat/public/jquery.timeago.js
|
124
122
|
- lib/mountain-goat/public/mg.css
|
@@ -137,7 +135,6 @@ files:
|
|
137
135
|
- lib/mountain-goat/views/mountain_goat/mg/choices/index.html.erb
|
138
136
|
- lib/mountain-goat/views/mountain_goat/mg/choices/new.html.erb
|
139
137
|
- lib/mountain-goat/views/mountain_goat/mg/choices/show.html.erb
|
140
|
-
- lib/mountain-goat/views/mountain_goat/mg/goals/.tmp_show.html.erb.86489~
|
141
138
|
- lib/mountain-goat/views/mountain_goat/mg/goals/_goal_form.html.erb
|
142
139
|
- lib/mountain-goat/views/mountain_goat/mg/goals/_goal_meta_type_form.html.erb
|
143
140
|
- lib/mountain-goat/views/mountain_goat/mg/goals/edit.html.erb
|
@@ -153,8 +150,6 @@ files:
|
|
153
150
|
- lib/mountain-goat/views/mountain_goat/mg/records/index.html.erb
|
154
151
|
- lib/mountain-goat/views/mountain_goat/mg/records/new.html.erb
|
155
152
|
- lib/mountain-goat/views/mountain_goat/mg/records/show.html.erb
|
156
|
-
- lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__chart.html.erb.73596~
|
157
|
-
- lib/mountain-goat/views/mountain_goat/mg/report_items/.tmp__show.html.erb.52502~
|
158
153
|
- lib/mountain-goat/views/mountain_goat/mg/report_items/_chart.html.erb
|
159
154
|
- lib/mountain-goat/views/mountain_goat/mg/report_items/_funnel.html.erb
|
160
155
|
- lib/mountain-goat/views/mountain_goat/mg/report_items/_report_item_form.html.erb
|
@@ -164,10 +159,6 @@ files:
|
|
164
159
|
- lib/mountain-goat/views/mountain_goat/mg/report_items/edit.html.erb
|
165
160
|
- lib/mountain-goat/views/mountain_goat/mg/report_items/new.html.erb
|
166
161
|
- lib/mountain-goat/views/mountain_goat/mg/report_mailer/report.html.erb
|
167
|
-
- lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_form.html.erb.42949~
|
168
|
-
- lib/mountain-goat/views/mountain_goat/mg/reports/.tmp__report_report_items.html.erb.96264~
|
169
|
-
- lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_edit.html.erb.39909~
|
170
|
-
- lib/mountain-goat/views/mountain_goat/mg/reports/.tmp_show.html.erb.37905~
|
171
162
|
- lib/mountain-goat/views/mountain_goat/mg/reports/_report.html.erb
|
172
163
|
- lib/mountain-goat/views/mountain_goat/mg/reports/_report_form.html.erb
|
173
164
|
- lib/mountain-goat/views/mountain_goat/mg/reports/_report_report_items.html.erb
|
@@ -175,7 +166,6 @@ files:
|
|
175
166
|
- lib/mountain-goat/views/mountain_goat/mg/reports/index.html.erb
|
176
167
|
- lib/mountain-goat/views/mountain_goat/mg/reports/new.html.erb
|
177
168
|
- lib/mountain-goat/views/mountain_goat/mg/reports/show.html.erb
|
178
|
-
- lib/mountain-goat/views/mountain_goat/mg/tests/.tmp_show.html.erb.19989~
|
179
169
|
- lib/mountain-goat/views/mountain_goat/mg/tests/_test_form.html.erb
|
180
170
|
- lib/mountain-goat/views/mountain_goat/mg/tests/edit.html.erb
|
181
171
|
- lib/mountain-goat/views/mountain_goat/mg/tests/index.html.erb
|
@@ -235,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
225
|
requirements: []
|
236
226
|
|
237
227
|
rubyforge_project: mountain-goat
|
238
|
-
rubygems_version: 1.
|
228
|
+
rubygems_version: 1.6.2
|
239
229
|
signing_key:
|
240
230
|
specification_version: 3
|
241
231
|
summary: A/B Testing to the edge
|
data/lib/mgflotilla.rb
DELETED
@@ -1,170 +0,0 @@
|
|
1
|
-
#begin
|
2
|
-
# require 'json'
|
3
|
-
#rescue LoadError
|
4
|
-
# p "Flotilla will not work without the 'json' gem"
|
5
|
-
#end
|
6
|
-
|
7
|
-
module MGFlotilla
|
8
|
-
module Helpers
|
9
|
-
|
10
|
-
# Insert a flot chart into the page. <tt>placeholder</tt> should be the
|
11
|
-
# name of the div that will hold the chart, <tt>collections</tt> is a hash
|
12
|
-
# of legends (as strings) and datasets with options as hashes, <tt>options</tt>
|
13
|
-
# contains graph-wide options.
|
14
|
-
#
|
15
|
-
# Example usage:
|
16
|
-
#
|
17
|
-
# chart("graph_div", {
|
18
|
-
# "January" => { :collection => @january, :x => :day, :y => :sales, :options => { :lines => {:show =>true}} },
|
19
|
-
# "February" => { :collection => @february, :x => :day, :y => :sales, :options => { :points => {:show =>true} } },
|
20
|
-
# :grid => { :backgroundColor => "#fffaff" })
|
21
|
-
#
|
22
|
-
# Options:
|
23
|
-
# :js_includes - includes flot library inline
|
24
|
-
# :js_tags - wraps resulting javascript in javascript tags if true. Defaults to true.
|
25
|
-
# :placeholder_tag - appends a placeholder div for graph
|
26
|
-
# :placeholder_size - specifys the size of the placeholder div
|
27
|
-
def mg_chart(placeholder, series, options = {}, html_options = {})
|
28
|
-
html_options.reverse_merge!({ :js_includes => true, :js_tags => true, :placeholder_tag => true, :placeholder_size => "800x300", :pie_hover => false, :pie_hover_absolute => false })
|
29
|
-
width, height = html_options[:placeholder_size].split("x") if html_options[:placeholder_size].respond_to?(:split)
|
30
|
-
additional_js = mg_get_additional_js(placeholder, html_options)
|
31
|
-
|
32
|
-
data, x_is_date, y_is_date = mg_series_to_json(series)
|
33
|
-
if x_is_date
|
34
|
-
options[:xaxis] ||= {}
|
35
|
-
options[:xaxis].merge!({ :mode => 'time' })
|
36
|
-
end
|
37
|
-
if y_is_date
|
38
|
-
options[:yaxis] ||= {}
|
39
|
-
options[:yaxis].merge!({ :mode => 'time' })
|
40
|
-
end
|
41
|
-
|
42
|
-
if html_options[:js_includes]
|
43
|
-
chart_js = <<-EOF
|
44
|
-
<script type="text/javascript">
|
45
|
-
(function () {
|
46
|
-
if (typeof(jQuery) == 'undefined') {
|
47
|
-
alert("Please include jQuery to view flot");
|
48
|
-
} else {
|
49
|
-
if (typeof(jQuery.plot) == 'undefined') {
|
50
|
-
$('##{placeholder}').html("<span class='flot-error'>Please include jQuery.plot to view flot</span>");
|
51
|
-
} else {
|
52
|
-
var plot = jQuery.plot($('##{placeholder}'), #{data}, #{options.to_json});
|
53
|
-
#{additional_js}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
})();
|
57
|
-
</script>
|
58
|
-
EOF
|
59
|
-
else
|
60
|
-
chart_js = <<-EOF
|
61
|
-
(function () {
|
62
|
-
if (typeof(jQuery) == 'undefined') {
|
63
|
-
alert("Please include jQuery to view flot");
|
64
|
-
} else {
|
65
|
-
if (typeof(jQuery.plot) == 'undefined') {
|
66
|
-
$('##{placeholder}').html("<span class='flot-error'>Please include jQuery.plot to view flot</span>");
|
67
|
-
} else {
|
68
|
-
var plot = jQuery.plot($('##{placeholder}'), #{data}, #{options.to_json});
|
69
|
-
#{additional_js}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
})();
|
73
|
-
EOF
|
74
|
-
end
|
75
|
-
|
76
|
-
html_options[:js_tags] ? javascript_tag(chart_js) : chart_js
|
77
|
-
output = html_options[:placeholder_tag] ? content_tag(:div, nil, :id => placeholder, :style => "width:#{width}px;height:#{height}px;", :class => "chart") + chart_js : chart_js
|
78
|
-
output.html_safe
|
79
|
-
end
|
80
|
-
|
81
|
-
private
|
82
|
-
def mg_series_to_json(series)
|
83
|
-
data_sets = []
|
84
|
-
x_is_date, y_is_date = false, false
|
85
|
-
series.each do |name, values|
|
86
|
-
set, data = {}, []
|
87
|
-
set[:label] = name
|
88
|
-
first = values[:collection].first
|
89
|
-
logger.warn "Collection is: #{values[:collection].inspect}"
|
90
|
-
if first #&& !values[:collection].is_a?(Array)
|
91
|
-
if first.is_a?(Hash)
|
92
|
-
x_is_date = first[values[:x]].acts_like?(:date) || first[values[:x]].acts_like?(:time)
|
93
|
-
y_is_date = first[values[:y]].acts_like?(:date) || first[values[:y]].acts_like?(:time)
|
94
|
-
else
|
95
|
-
x_is_date = first.send(values[:x]).acts_like?(:date) || first.send(values[:x]).acts_like?(:time)
|
96
|
-
y_is_date = first.send(values[:y]).acts_like?(:date) || first.send(values[:y]).acts_like?(:time)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
values[:collection].each do |object|
|
100
|
-
if values[:collection].is_a?(Hash) || object.is_a?(Hash)
|
101
|
-
x_value, y_value = object[values[:x]], object[values[:y]]
|
102
|
-
#logger.warn "A: Object is: #{object}, x,y: #{[x_value, y_value]} from #{[values[:x], values[:y]]}"
|
103
|
-
else
|
104
|
-
x_value, y_value = object.send(values[:x]), object.send(values[:y])
|
105
|
-
#logger.warn "B: Object is: #{object}, x,y: #{[x_value, y_value]}"
|
106
|
-
end
|
107
|
-
x = x_is_date ? x_value.to_time.to_i * 1000 : x_value.to_f
|
108
|
-
y = y_is_date ? y_value.to_time.to_i * 1000 : y_value.to_f
|
109
|
-
#logger.warn "Tally x,y: #{[x, y]}"
|
110
|
-
data << [x,y]
|
111
|
-
end
|
112
|
-
set[:data] = data
|
113
|
-
values[:options].each {|option, parameters| set[option] = parameters } if values[:options]
|
114
|
-
data_sets << set
|
115
|
-
end
|
116
|
-
return data_sets.to_json, x_is_date, y_is_date
|
117
|
-
end
|
118
|
-
|
119
|
-
def mg_get_additional_js(placeholder, options)
|
120
|
-
res = ""
|
121
|
-
if options[:pie_hover]
|
122
|
-
res << <<-EOF
|
123
|
-
function showTooltip(x, y, contents) {
|
124
|
-
$('<div id="tooltip">' + contents + '</div>').css( {
|
125
|
-
position: 'absolute',
|
126
|
-
//display: 'none',
|
127
|
-
top: y + 5,
|
128
|
-
left: x + 5,
|
129
|
-
border: '1px solid #fdd',
|
130
|
-
padding: '2px',
|
131
|
-
'background-color': '#fee',
|
132
|
-
opacity: 0.80
|
133
|
-
}).appendTo("body");//.fadeIn(200);
|
134
|
-
}
|
135
|
-
|
136
|
-
var previousPoint = null;
|
137
|
-
$('##{placeholder}').bind('mouseout', function() {
|
138
|
-
plot.unhighlight();
|
139
|
-
$("#tooltip").remove();
|
140
|
-
$(this).data('previous-post', -1);
|
141
|
-
});
|
142
|
-
|
143
|
-
$('##{placeholder}').bind('plothover', function(event, pos, item) {
|
144
|
-
if (item) {
|
145
|
-
if ($(this).data('previous-post') != item.seriesIndex) {
|
146
|
-
plot.unhighlight();
|
147
|
-
plot.highlight(item.series, item.datapoint);
|
148
|
-
$(this).data('previous-post', item.seriesIndex);
|
149
|
-
}
|
150
|
-
$("#tooltip").remove();
|
151
|
-
#{ options[:line_hover_absolute] ? "y = 'on ' + (new Date(item.datapoint[0])).toDateString() + ': ' + item.datapoint[1] + ' #{options[:item_title] || ''}'" : !options[:pie_hover_absolute] ? "y = item.datapoint[0].toFixed(0) + '%';" : "y = item.datapoint[1][0][1] + ' #{options[:item_title] || ''}'" }
|
152
|
-
showTooltip(pos.pageX, pos.pageY, item.series.label + " " + y);
|
153
|
-
} else {
|
154
|
-
//console.log('unhighlight (3)');
|
155
|
-
plot.unhighlight();
|
156
|
-
$("#tooltip").remove();
|
157
|
-
previousPost = $(this).data('previous-post', -1);
|
158
|
-
}
|
159
|
-
});
|
160
|
-
EOF
|
161
|
-
end
|
162
|
-
|
163
|
-
res
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
class ActionView::Base
|
169
|
-
include MGFlotilla::Helpers
|
170
|
-
end
|