heatmap-rails 0.1.2 → 0.1.3
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/app/controllers/points_controller.rb +5 -0
- data/lib/heatmap/rails.rb +1 -1
- data/lib/heatmap/rails/helper.rb +113 -14
- data/lib/heatmap/rails/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: 3ee4ef0f55873798ec7a01874168a45a0b457495
|
4
|
+
data.tar.gz: c3380e20bc6dd155eaff287a246a7fce1e3f1024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29babce180685c54115c5d6190483b3e344b63fc5da852ae91d42ddc8fbe91d953b3c12fc5800fb9c50f6574e13811ccf219b8512b57b405f5f1cce944dab670
|
7
|
+
data.tar.gz: 7e83034fdf416e3e5f50815c5969540ad8a1f42548a4eac35aae6406712815a2a780d83672285ae903243b63655b7807ce98c5d0f7a58c8315358562bdae4403
|
@@ -13,5 +13,10 @@ class PointsController < ApplicationController
|
|
13
13
|
HeatMap.create(path: params[:move_data]["#{i}"][:path], click_type: 'move',xpath: params[:move_data]["#{i}"][:xpath], offset_x: params[:move_data]["#{i}"][:offset_x], offset_y: params[:move_data]["#{i}"][:offset_y])
|
14
14
|
end
|
15
15
|
end
|
16
|
+
if params[:scroll_data].present? && params[:total_scrolls].to_i > 0
|
17
|
+
for i in 0..params[:total_scrolls].to_i-1
|
18
|
+
HeatMap.create(path: params[:scroll_data]["#{i}"][:path], click_type: 'scroll',xpath: params[:scroll_data]["#{i}"][:xpath], offset_x: params[:scroll_data]["#{i}"][:offset_x], offset_y: params[:scroll_data]["#{i}"][:offset_y])
|
19
|
+
end
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/heatmap/rails.rb
CHANGED
data/lib/heatmap/rails/helper.rb
CHANGED
@@ -7,6 +7,7 @@ module Heatmap
|
|
7
7
|
|
8
8
|
click = options[:click] || Heatmap::Rails.options[:click]
|
9
9
|
move = options[:move] || Heatmap::Rails.options[:move]
|
10
|
+
scroll = options[:scroll] || Heatmap::Rails.options[:scroll]
|
10
11
|
html_element = options[:html_element] || Heatmap::Rails.options[:html_element]
|
11
12
|
html = ""
|
12
13
|
|
@@ -14,6 +15,40 @@ module Heatmap
|
|
14
15
|
<script type="text/javascript">
|
15
16
|
$( document ).ready(function() {
|
16
17
|
var move_array = [];
|
18
|
+
var scroll_array = [];
|
19
|
+
|
20
|
+
(function() {
|
21
|
+
document.onwheel = handleWheelMove;
|
22
|
+
function handleWheelMove(event) {
|
23
|
+
var dot, eventDoc, doc, body, offsetX, offsetY;
|
24
|
+
event = event || window.event;
|
25
|
+
if (event.offsetX == null && event.clientX != null) {
|
26
|
+
eventDoc = (event.target && event.target.ownerDocument) || document;
|
27
|
+
doc = eventDoc.documentElement;
|
28
|
+
body = eventDoc.body;
|
29
|
+
event.offsetX = event.clientX +
|
30
|
+
(doc && doc.scrollLeft || body && body.scrollLeft || 0) -
|
31
|
+
(doc && doc.clientLeft || body && body.clientLeft || 0);
|
32
|
+
event.offsetY = event.clientY +
|
33
|
+
(doc && doc.scrollTop || body && body.scrollTop || 0) -
|
34
|
+
(doc && doc.clientTop || body && body.clientTop || 0 );
|
35
|
+
}
|
36
|
+
var xpath_element = xpathstring(event);
|
37
|
+
var element_width = event.target.getBoundingClientRect().width;
|
38
|
+
var element_height= event.target.getBoundingClientRect().height;
|
39
|
+
offset_x_element = event.offsetX / element_width;
|
40
|
+
offset_y_element = event.offsetY / element_height;
|
41
|
+
var pageCoords = { path: window.location.pathname, type: 'scroll', xpath: xpath_element, offset_x: offset_x_element , offset_y: offset_y_element, };
|
42
|
+
|
43
|
+
scroll_array.push(pageCoords);
|
44
|
+
if (scroll_array.length >= parseInt(#{scroll})) {
|
45
|
+
var coordinates = scroll_array;
|
46
|
+
sendRequest({'scroll_data': coordinates, 'total_scrolls': #{scroll} });
|
47
|
+
scroll_array = [];
|
48
|
+
}
|
49
|
+
}
|
50
|
+
})();
|
51
|
+
|
17
52
|
document.querySelector('#{html_element}').onmousemove = function(ev) {
|
18
53
|
var xpath_element = xpathstring(ev);
|
19
54
|
var element_width = ev.target.getBoundingClientRect().width;
|
@@ -119,12 +154,25 @@ JS
|
|
119
154
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
120
155
|
end
|
121
156
|
|
122
|
-
def show_heatmap(path)
|
123
|
-
|
157
|
+
def show_heatmap(path,type = false)
|
158
|
+
if type
|
159
|
+
heatmap = HeatMap.where(path: path.to_s , click_type: type)
|
160
|
+
heatmap_count = HeatMap.where(path: path.to_s , click_type: type).count
|
161
|
+
type = type + 's'
|
162
|
+
else
|
163
|
+
heatmap = HeatMap.where(path: path.to_s)
|
164
|
+
heatmap_count = HeatMap.where(path: path.to_s).count
|
165
|
+
type = 'heatmaps'
|
166
|
+
end
|
124
167
|
@data_points = []
|
125
168
|
@data_xpaths = []
|
169
|
+
@scroll_data = []
|
126
170
|
heatmap.each do |coordinate|
|
127
|
-
|
171
|
+
if (coordinate.click_type == "scroll")
|
172
|
+
@scroll_data.push({xpath: coordinate.xpath, offset_x: coordinate.offset_x, offset_y:coordinate.offset_y})
|
173
|
+
else
|
174
|
+
@data_xpaths.push({xpath: coordinate.xpath, offset_x: coordinate.offset_x, offset_y:coordinate.offset_y, value: 100})
|
175
|
+
end
|
128
176
|
end
|
129
177
|
html = ""
|
130
178
|
js = <<JS
|
@@ -133,6 +181,25 @@ JS
|
|
133
181
|
container: document.querySelector('body'),
|
134
182
|
radius: 40
|
135
183
|
});
|
184
|
+
window.onload = function() {
|
185
|
+
var parent_div = document.createElement("div");
|
186
|
+
var text_div = document.createElement("span");
|
187
|
+
parent_div.style.padding= "14px";
|
188
|
+
parent_div.style.position = "absolute";
|
189
|
+
parent_div.style.top = "0";
|
190
|
+
parent_div.style.right = "0";
|
191
|
+
parent_div.style.background ="rgba(0, 0, 0, 0.7)";
|
192
|
+
parent_div.style.color ="white";
|
193
|
+
parent_div.style.textAlign ="center";
|
194
|
+
var text_node = document.createTextNode("#{type.capitalize} Recorded");
|
195
|
+
text_div.appendChild(text_node);
|
196
|
+
parent_div.appendChild(text_div);
|
197
|
+
var numeric_div = document.createElement("h1");
|
198
|
+
var numeric_node = document.createTextNode("#{heatmap_count}");
|
199
|
+
numeric_div.appendChild(numeric_node);
|
200
|
+
parent_div.appendChild(numeric_div);
|
201
|
+
document.body.appendChild(parent_div);
|
202
|
+
}
|
136
203
|
function getOffset( path ) {
|
137
204
|
el = document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
138
205
|
var _x = 0;
|
@@ -149,24 +216,56 @@ JS
|
|
149
216
|
}
|
150
217
|
var xpath = JSON.parse('#{raw(@data_xpaths.to_json.html_safe)}');
|
151
218
|
var data_xpath = xpath.map(function(path){
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
219
|
+
if (path != null) {
|
220
|
+
element = getElement(path.xpath);
|
221
|
+
if (element != null){
|
222
|
+
width = element.getBoundingClientRect().width;
|
223
|
+
height = element.getBoundingClientRect().height;
|
224
|
+
var x_coord = getOffset(path.xpath).x+ (width * path.offset_x);
|
225
|
+
var y_coord = getOffset(path.xpath).y+ (height * path.offset_y);
|
226
|
+
delete path["xpath"];
|
227
|
+
delete path["offset_x"];
|
228
|
+
delete path["offset_y"];
|
229
|
+
path.x = Math.ceil(parseFloat(x_coord));
|
230
|
+
path.y = Math.ceil(parseFloat(y_coord));
|
231
|
+
return path;
|
232
|
+
}
|
233
|
+
}
|
162
234
|
});
|
235
|
+
// Removed: Null Xpath(s)
|
236
|
+
var data_xpath = data_xpath.filter(function(val){ return val!==undefined; });
|
237
|
+
|
163
238
|
heatmapInstance.addData(data_xpath);
|
239
|
+
var scroll = JSON.parse('#{raw(@scroll_data.to_json.html_safe)}');
|
240
|
+
var scroll_data = scroll.map(function(element){
|
241
|
+
width = getElement(element.xpath).getBoundingClientRect().width;
|
242
|
+
height = getElement(element.xpath).getBoundingClientRect().height;
|
243
|
+
dot = document.createElement('div');
|
244
|
+
dot.className = "dot";
|
245
|
+
dot.style.left = (getOffset(element.xpath).x+ (width * element.offset_x)) + "px";
|
246
|
+
dot.style.top = (getOffset(element.xpath).y+ (height * element.offset_y) )+ "px";
|
247
|
+
delete element["xpath"];
|
248
|
+
delete element["offset_x"];
|
249
|
+
delete element["offset_y"];
|
250
|
+
dot.style.backgroundColor ="white";
|
251
|
+
dot.style.position ="absolute";
|
252
|
+
dot.style.borderWidth ="8px";
|
253
|
+
dot.style.borderStyle ="solid";
|
254
|
+
var colors = Array('#ee3e32', '#f68838' ,'#fbb021', '#1b8a5a','#1d4877');
|
255
|
+
var color = colors[Math.floor(Math.random()*colors.length)];
|
256
|
+
dot.style.borderColor = color;
|
257
|
+
dot.style.borderRadius ="50%";
|
258
|
+
dot.style.opacity ="0.7";
|
259
|
+
var arrow_node = document.createTextNode("\u21C5");
|
260
|
+
dot.appendChild(arrow_node);
|
261
|
+
document.body.appendChild(dot);
|
262
|
+
});
|
263
|
+
|
164
264
|
</script>
|
165
265
|
JS
|
166
266
|
|
167
267
|
html += js
|
168
268
|
html.respond_to?(:html_safe) ? html.html_safe : html
|
169
269
|
end
|
170
|
-
|
171
270
|
end
|
172
271
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heatmap-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|