example-heatmap-click.html
9.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>heatmap.js | Examples: Realtime Click Heatmap</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="index, follow">
<meta name="description" content="heatmap.js example showing a realtime click heatmap">
<meta name="keywords" content="click heatmap, realtime click heatmap">
<meta name="author" content="Patrick Wied">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/prettify.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.html">heatmap.js</a>
<div class="nav-collapse">
<ul class="nav">
<li><a href="index.html">Home</a></li>
<li class="active"><a href="examples.html" title="heatmap.js examples">Examples</a></li>
<li><a href="showcases.html" title="Real World Usage of heatmap.js">Showcases</a></li>
<li><a href="https://github.com/pa7/heatmap.js/blob/master/README.md" target="_blank" title="Documentation on Github">Documentation</a></li>
<li><a href="contact.html" title="Contact for Support & Feedback">Contact</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<div class="page-header">
<h1>
Examples
<small>See how easy it is to create heatmaps with heatmap.js</small>
</h1>
</div>
<div class="row">
<div class="span4 well" style="padding:8px 0;">
<ul class="nav nav-list">
<li class="nav-header">
Basic Examples
</li>
<li>
<a href="examples.html" title="static heatmap example">Static Heatmap</a>
</li>
<li>
<a href="example-heatmap-legend.html" title="static heatmap example with legend">Static Heatmap with Legend</a>
</li>
<li class="active">
<a href="example-heatmap-click.html" title="realtime heatmap example showing mouse clicks">Realtime Heatmap - Mouse Clicks</a>
</li>
<li>
<a href="example-heatmap-mousemove.html" title="realtime heatmap example showing mouse movement">Realtime Heatmap - Mouse Movement</a>
</li>
<li class="nav-header">
Map Layer Examples
</li>
<li>
<a href="example-heatmap-googlemaps.html" title="google maps v3 heatmap layer example">Google Maps V3 Layer</a>
</li>
<li>
<a href="example-heatmap-openlayers.html" title="openlayers heatmap layer example">Openlayers Layer</a>
</li>
<li>
<a href="example-heatmap-openlayers-renderer.html" title="openlayers heatmap renderer vectorial layers example">Openlayers Renderer for vectorial layers</a>
</li>
<li>
<a href="example-heatmap-arcgis.html" title="arcgis heatmap example">ArcGIS Layer</a>
</li>
<li>
<a href="example-heatmap-leaflet.html" title="leaflet heatmap example">Leaflet Layer</a>
</li>
</ul>
</div>
<div class="tabbable span7" style="width:615px;"> <!-- Onlyrequired for left/right tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#tab1" data-toggle="tab">Live Demo</a></li>
<li><a href="#tab2" data-toggle="tab">Code</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<div style="padding:8px 0">This example shows a realtime heatmap with click data, if you click on the surface to the right it will add the datapoint right after the click.</div>
<div class="alert alert-info">Click on the heatmap in order to create datapoints!</div>
<div id="heatmapArea" class="well" style="width:610px;padding:0;height:400px;cursor:pointer;position:relative;">
</div>
</div>
<div class="tab-pane" id="tab2">
<pre class="prettyprint linenums">
<!DOCTYPE html>
<html lang="en">
...
<script type="text/javascript" src="heatmap.js"></script>
<script type="text/javascript">
window.onload = function(){
// heatmap configuration
var config = {
element: document.getElementById("heatmapArea"),
radius: 30,
opacity: 50,
legend: {
position: 'br',
title: 'Example Distribution'
}
};
//creates and initializes the heatmap
var heatmap = h337.create(config);
document.getElementById("heatmapArea").onclick = function(e){
// layerX and layerY is deprecated and will be removed,
// use another way of determining the x and y position in an element
heatmap.store.addDataPoint(e.layerX, e.layerY, 1);
};
};
</script>
</html>
</pre>
</div>
</div>
</div>
</div>
<hr>
<footer>
<p style="width:330px;margin:auto;">heatmap.js by <a href="http://www.patrick-wied.at/" title="patrick wied javascript developer" target="_blank">Patrick Wied</a> (<a href="http://twitter.com/patrickwied" target="_blank">@patrickwied</a>) 2011-2013</p>
</footer>
<a href="https://github.com/pa7/heatmap.js" target="_blank"><img style="position: fixed; top: 0; left: 0; border: 0;z-index:10000" src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub"></a>
</div> <!-- /container -->
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/prettify.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/bootstrap-tab.js"></script>
<script type="text/javascript" src="src/heatmap.js"></script>
<script type="text/javascript">
!function($){
$(function(){
window.prettyPrint && prettyPrint();
var heatmap = h337.create({
element: $("#heatmapArea")[0],
radius: 30,
opacity: 50,
legend: {
position: 'br',
title: 'Click Distribution'
}
});
window.heatmap = heatmap;
var generateData = function(){
var max = (Math.random()*10+1) >> 0,
data = [],
length = 20,
width = heatmap.get("width"),
height = heatmap.get("height");
while(length--){
data.push({
x: (Math.random()*width) >> 0,
y: (Math.random()*height) >> 0,
count: (Math.random()*max) >> 0
});
}
return {
max: max,
data: data
};
};
$('#heatmapArea').click(function(e){
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
heatmap.store.addDataPoint(x, y, 1);
});
});
}(window.jQuery)
</script>
<!-- Remove this from your site, it's my analytics script !-->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.patrick-wied.at/helper/piwik/" : "http://www.patrick-wied.at/helper/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://www.patrick-wied.at/helper/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End of Analytics Script -->
</body>
</html>