forked from simogeo/geostats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
executable file
·331 lines (295 loc) · 12.6 KB
/
sample.html
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>geostats.js (by simon georget)</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/jenks.util.js"></script>
<script type="text/javascript" src="lib/geostats.js"></script>
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript" src="tests/openlayers_sample.js"></script>
<style type="text/css">
<!--
body {
font-family: "Lucida Sans Unicode", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
color:#333;
font-size: 0.8em;
background-color: #F7F7F7;
}
#legend, #legend2 {float:left;width:45%;margin:0 1em 2em 0;}
.legend-block {
border: 1px solid #555555;
display: block;
float: left;
height: 12px;
margin: 0.3em 0.8em 0 2em;
width: 20px;
}
.container {margin:0 auto;width:60%;}
.serie strong {color:#333;}
.serie {font-size: .9em;color:#555;}
.classes {margin:0em 4em 2em;}
.cnt { font-size: 0.8em;color:#666;font-style: italic;}
.projectinfo {width:100%;text-align: center;margin:-3em 0 3em;}
a {color:#F47FE7;font-weight: bold;text-shadow: #fff 2px 2px 0px;text-decoration: none;}
a:hover {color:#514F51;}
#map {width:100%;height:500px;border: 1px solid #ccc;background-color: #eee}
h1 {color:#B5B1B1;text-shadow: #fff 2px 2px 0px;text-align: center;margin:2em 0;}
h2 {color:#A2A3F2;text-shadow: #fff 2px 2px 0px;margin:2em 0 1em 0;}
h3 {color:#555;font-size: .9em}
hr {
height: 1px;
margin: -0.5em 0;
padding: 0;
color: #ddd;
background-color: #ddd;
border: 0;
}
#footer {font-size:0.8em;text-align: center;color:#777;margin:2em 0 1em;padding:.3em}
-->
</style>
<script type="text/javascript">
var callback_sample = function(c) {
return Math.round(c);
};
$(document).ready(function() {
$.getJSON('tests/test.json',function(data) {
var items = []; // will store values
// Don't forget to use firebug console to retrieve your data
// console.log(data.features);
$.each(data.features, function(i,feature){
items.push(feature.properties.Pop_2006);
});
var dataJson = items;
// Seventh serie
serie7 = new geostats(dataJson);
// we get Eq interval classification
var a = serie7.getQuantile(5);
//var a = serie7.getEqInterval(5);
//var a = serie7.getJenks(3);
var str = '<strong>Classification Method : <\/strong>' + serie7.method + " :\n";
str += '<div class="classes">';
var ranges = serie7.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
var content = '';
content += '<h2>Sample 7 - Loading data from JSON file (with jQuery)<\/h2>';
content += '<p>' + nl2br(serie7.info()) + '<\/p>';
content += '<p>' + nl2br(str) + '<\/p>';
content += '<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie7.getSortedlist() + '<\/p>';
content += '<hr \/>';
jQuery('#sample-7').html(content);
// sample-8
// for openlayers representation
var color_x = new Array('#e2dee6', '#c2abdd', '#9d87b6', '#735a8f', '#3d2e4e');
// var color_x = new Array('#ee5588', '#44ee11', '#668811', '#000000', '#3d2e4e');
serie7.setColors(color_x);
var class_x = ranges;
var content = serie7.getHtmlLegend();
var content_flare = serie7.getHtmlLegend(null, 'Customized legend, callback function (<em>here round values<\/em>) and feature count', true, callback_sample);
jQuery('#method').html('<p><strong>Classification Method : <\/strong>' + serie7.method + '<\/p>');
jQuery('#legend').html(content);
jQuery('#legend2').html(content_flare);
init(color_x, class_x);
});
});
</script>
<script type="text/javascript">
// from https://raw.github.com/kvz/phpjs/master/functions/strings/nl2br.js
function nl2br (str, is_xhtml) {
// http://kevin.vanzonneveld.net
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Philip Peterson
// + improved by: Onno Marsman
// + improved by: Atli Þór
// + bugfixed by: Onno Marsman
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Brett Zamir (http://brett-zamir.me)
// + improved by: Maximusya
// * example 1: nl2br('Kevin\nvan\nZonneveld');
// * returns 1: 'Kevin<br />\nvan<br />\nZonneveld'
// * example 2: nl2br("\nOne\nTwo\n\nThree\n", false);
// * returns 2: '<br>\nOne<br>\nTwo<br>\n<br>\nThree<br>\n'
// * example 3: nl2br("\nOne\nTwo\n\nThree\n", true);
// * returns 3: '<br />\nOne<br />\nTwo<br />\n<br />\nThree<br />\n'
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
</script>
</head>
<body>
<div class="container">
<h1>geostats - Javascript classification library <em>samples</em></h1>
<p class="projectinfo"><a href="https://github.com/simogeo/geostats" title="geostats Github page">Github page</a> - <a href="https://github.com/simogeo/geostats/archives/master" title="geostats download">download (from github)</a></p>
<script type="text/javascript"><!--
// Samples datasets
// test integer - 14 values
var a1 = Array(12, 22, 5, 8, 43, 2, 34, 12, 34, 36, 5, 21, 23, 45);
// test integer - 17 values
var a2 = Array(12, 22, 5, 8, 43, 2, 34, 12, 34, 36, 5, 21, 23, 45, 12, 31, 38);
// test float - 5 values
var a3 = Array(1.54567, 0.7623122, 1.895432, 2.435357, 0.11143);
// test integer - 10 values
var a4 = Array(12, 22, 5, 8, 43, 2, 34, 12, 34, 36);
// test float
var a5 = Array(0, 1.2, 3, 2.5, 1.6, 2.2, 3.1, 2.8, 1.1, 2.7, 0.1);
// test integer - 11 values
//var a6 = Array(12, 22, 18, 5, 8, 43, 2, 34, 12, 34, 36);
var a6 = Array(12, 22, 18, 5, 8, 43, 2, 34, 12, 34, 36, 4, 9, 35, 12, 42, 43, 56, 12, 23,
43, 19, 11, -1, 51, -6, 34, 33,41, 45, 23, -3, 3, 54, 1, 18, 44, 41,28, 16, 19,
35, 44, 21, 23, -3, 5, 64, 15, 17, 7, 93, 6, 16, 47, 13, 46, 53, 10, 30, 31, 32,
58, 28, 32, 46,53, 31, 2, 36, 41, 23, 3, 8, 15, 54, 35, 79, 15, 83, 6,-9, 78, 74,
56, 78, 45, 62, 19, 70, 23, 51, 73, 67, 78, 34, 52, 61, 60, 11, 26, 48, 15, 2);
// First serie
serie1 = new geostats(a1);
document.write('<h2>Sample 1 - basic statistics methods <\/h2>');
document.write('<p>geostats.min() : ' + serie1.min() + '<\/p>');
document.write('<p>geostats.max() : ' + serie1.max() + '<\/p>');
document.write('<p>geostats.sum() : ' + serie1.sum() + '<\/p>');
document.write('<p>geostats.pop() : ' + serie1.pop() + '<\/p>');
document.write('<p>geostats.mean() : ' + serie1.mean() + '<\/p>');
document.write('<p>geostats.median() : ' + serie1.median() + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie1.getSortedlist() + '<\/p>');
document.write('<hr \/>');
// Second serie
serie2 = new geostats(a2);
document.write('<h2>Sample 2 - geostats.info() <\/h2>');
document.write('<p>' + nl2br(serie2.info()) + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie2.getSortedlist() + '<\/p>');
document.write('<hr \/>');
// Third serie
serie3 = new geostats(a3);
document.write('<h2>Sample 3 - handle both integer and float values <\/h2>');
document.write('<p>' + nl2br(serie3.info()) + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie3.getSortedlist() + '<\/p>');
document.write('<hr \/>');
// Fourth serie
serie4 = new geostats(a4);
// we get Eq interval classification 3 classes
var a = serie4.getEqInterval(3);
var str = '<strong>Classification Method : <\/strong>' + serie4.method + " :\n";
str += '<div class="classes">';
var ranges = serie4.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Eq interval classification 4 classes
var a = serie4.getEqInterval(4);
str += '<strong>Classification Method : <\/strong>' + serie4.method + " :\n";
str += '<div class="classes">';
var ranges = serie4.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Eq interval classification 5 classes
var a = serie4.getEqInterval(5);
str += '<strong>Classification Method : <\/strong>' + serie4.method + " :\n";
str += '<div class="classes">';
var ranges = serie4.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
document.write('<h2>Sample 4 - classification : choose classes number <\/h2>');
document.write('<p>' + nl2br(serie4.info()) + '<\/p>');
document.write('<p>' + nl2br(str) + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie4.getSortedlist() + '<\/p>');
document.write('<hr \/>');
// Fifth serie
var serie5 = new geostats();
serie5.setSerie(a5);
// we get Eq interval classification
var a = serie5.getEqInterval(4);
var str = '<strong>Classification Method : <\/strong>' + serie5.method + " :\n";
str += '<div class="classes">';
var ranges = serie5.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Quantile classification
var a = serie5.getQuantile(4);
str += '<strong>Classification Method : <\/strong>' + serie5.method + " :\n";
str += '<div class="classes">';
var ranges = serie5.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Jenks classification
var a = serie5.getJenks(4);
str += '<strong>Classification Method : <\/strong>' + serie5.method + " :\n";
str += '<div class="classes">';
var ranges = serie5.ranges;
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
document.write('<h2>Sample 5 - classification : choose classification method<\/h2>');
document.write('<h3>Equal Interval, Quantile, Jenks<\/h3>');
document.write('<div>3 methods: <\/div>');
document.write('<ul>');
document.write('<li><em>geostats.getEqInterval(nbClass);<\/em><\/<li>');
document.write('<li><em>geostats.getQuantile(nbClass);<\/em><\/<li>');
document.write('<li><em>geostats.getJenks(nbClass);<\/em><\/<li>');
document.write('<\/ul>');
document.write('<p>' + nl2br(serie5.info()) + '<\/p>');
document.write('<p>' + nl2br(str) + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie5.getSortedlist() + '<\/p>');
document.write('<hr \/>');
// Sixth serie
var serie6 = new geostats(a6);
// we get Eq interval classification
serie6.getEqInterval(3);
var str = '<strong>Classification Method : <\/strong>' + serie6.method + " :\n";
str += '<div class="classes">';
var ranges = serie6.getRanges(a);
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Quantile classification
serie6.getQuantile(5);
str += '<strong>Classification Method : <\/strong>' + serie6.method + " :\n";
str += '<div class="classes">';
var ranges = serie6.getRanges(a);
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
// we get Jenks classification
serie6.getJenks(4);
str += '<strong>Classification Method : <\/strong>' + geostats.method + " :\n";
str += '<div class="classes">';
var ranges = serie6.getRanges(a);
for(i = 0; i < ranges.length ; i++) {
str += ranges[i] + "\n";
}
str += '<\/div>';
document.write('<h2>Sample 6 - choose the right classification<\/h2>');
document.write('<p>' + nl2br(serie6.info()) + '<\/p>');
document.write('<p>' + nl2br(str) + '<\/p>');
document.write('<p class="serie"><strong>Serie (sorted) : <\/strong>' + serie6.getSortedlist() + '<\/p>');
document.write('<hr \/>');
document.write('<div id="sample-7"><\/div>');
--></script>
<div id="sample-8">
<h2>Sample 8 - finally, a choropleth representation (with openlayers)</h2>
<div id="method"></div>
<div id="map"></div>
</div>
<div id="sample-9">
<h2>Sample 9 - dynamic HTML legend with user input, feature count and callback function</h2>
<div id="legend"></div>
<div id="legend2"></div>
</div>
<div style="clear:both"></div>
<div id="footer"><em>geostats.js</em> - Copyright (c) 2011 Simon Georget - released under MIT license</div>
</div>
</body>
</html>