forked from metpetdb/IMMP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff
More file actions
338 lines (324 loc) · 9.65 KB
/
diff
File metadata and controls
338 lines (324 loc) · 9.65 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
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
332
333
334
335
336
337
338
diff --git a/static/js/create_map.js b/static/js/create_map.js
index 5d882e4..f634fd4 100644
--- a/static/js/create_map.js
+++ b/static/js/create_map.js
@@ -1,8 +1,11 @@
// createMode indicates if we are or are not in create mode
var createMode = false;
var deleteMode = false;
-var x;
-var y;
+
+/** Coordinates of last point clicked on image. */
+var x, y;
+
+/** data store for tagged features/rows */
var ids = [];
function insertAndMapData(x, y, id){
@@ -19,6 +22,17 @@ function insertAndMapData(x, y, id){
mapData(x,y,id);
}
+//////
+/*var a = document.createElement('area');
+a['shape'] = 'circle';
+a['id'] = '1';
+a['data-name'] = '1,all';
+a['coords'] = '191,81,10';
+a['href'] = '#';
+$(".mapper-map").append(a);*/
+
+//////
+
function mapData(x,y,id){
var mapHTML = "<area shape=\"circle\" ";
mapHTML += "id=\"" + id + "\" ";
@@ -50,7 +64,7 @@ function unmapData(id){
return;
}
- ids[id] = "";
+ delete ids[id];
$(".mapper-map").empty(); //clear html ?
@@ -75,12 +89,19 @@ function build_mappings(mappingsString){
}
}
+/**
+ * onClick handler which is attached to the rows after clicking on image
+ *
+ *
+ */
function dataClick(id){
- if(createMode){
+ if (createMode) {
insertAndMapData(x,y,id);
}
createMode = false;
+
+ // use toggle class, elements same as line 120 in csv.js @ 1111c0a373f706c7a6e0d8aa46d3a06258ea7a27
$('.unlinked').removeClass("unlinked");
$('.linked').removeClass("linked");
$('.greyOut').removeClass("greyOut");
-}
\ No newline at end of file
+}
diff --git a/static/js/csv-to-json.js b/static/js/csv-to-json.js
deleted file mode 100644
index 4435300..0000000
--- a/static/js/csv-to-json.js
+++ /dev/null
@@ -1,21 +0,0 @@
-// Found at https://gist.github.com/jssuttles/8fb8b16a152558906469dfefbf88f658
-function csvJSON(csv){
-
- var lines=csv.split('\n');
-
- var result = [];
-
- var headers=lines[0].split(',');
- lines.splice(0, 1);
- lines.forEach(function(line) {
- var obj = {};
- var currentline = line.split(',');
- headers.forEach(function(header, i) {
- obj[header] = currentline[i];
- });
- result.push(obj);
- });
-
- //return result; //JavaScript object
- return JSON.stringify(result); //JSON
-}
\ No newline at end of file
diff --git a/static/js/csv.js b/static/js/csv.js
index 1eedcbe..8570071 100644
--- a/static/js/csv.js
+++ b/static/js/csv.js
@@ -1,12 +1,12 @@
var fileInput = $('#files');
var uploadButton = $('#upload');
-uploadButton.on('click', function() {
+uploadButton.on('click', function uploadButtonClick() {
if (!window.FileReader) {
alert('Your browser is not supported')
}
var input = fileInput.get(0);
-
+
// Create a reader object
var reader = new FileReader();
if (input.files.length) {
@@ -15,10 +15,16 @@ uploadButton.on('click', function() {
$(reader).on('load', processFile);
} else {
alert('Please upload a file before continuing');
- }
+ }
});
+/**
+ * this and show_* runs once when new image
+ *
+ * and once on load
+ * hide is called every time image is loaded in build_table? shouldn't it just be once?
+ */
function hide_csv_import(){
$('#result').empty();
$('#upload').hide();
@@ -45,6 +51,9 @@ function processFile(e) {
}
+/**
+ * HAPPENS ON LAUNCH (document.ready in map.html)
+ */
function build_table(csv){
var csvarray = $.csv.toArrays(csv);
var csvtable = generateTable(csvarray);
@@ -62,39 +71,72 @@ function push_csv_to_db(csv){
});
}
+/**
+ * Normalizes data to Matrix of Strings
+ *
+ * Converts List of strings to list of 1-length lists of strings, passes
+ * through list of list of strings as passed in.
+ *
+ * @param csvData ['string'] or [['string']]
+ * @return matrix of strings
+ */
+function normalizeCSV(csvData) {
+ if (csvData[0].constructor === String) {
+ return csvData.map(function (row) {
+ return [row];
+ });
+ } else if (csvData[0].constructor === Array &&
+ csvData[0][0].constructor === String) {
+ return csvData;
+ } else {
+ // alert('Error: csvData malformed, see console.');
+ console.log(csvData);
+ throw new Error('csvData');
+ }
+}
+
+/**
+var input = ['juan'];
+// var input = ['juan', 'dos', 'tres'];
+// var input = [['juan'], ['dos'], ['tres']];
+var output = normalizeCSV(input);
+
+console.log(output);
+**/
+
// build HTML table data from an array (one or two dimensional)
+/**
+ * normalizes data
+ *
+ * array: if csv
+ * @param data array[''] or array[[]], array[{}]
+ */
function generateTable(data) {
var html = '';
if(typeof(data[0]) === 'undefined') {
return null;
}
- if(data[0].constructor === String) {
- html += '<tr>\r\n';
- for(var item in data) {
- html += '<td>' + data[item] + '</td>\r\n';
- }
- html += '</tr>\r\n';
- }
- if(data[0].constructor === Array) {
- for(var row in data) {
- //HTML addition for new table row (one for every row in CSV)
- html += '<tr onMouseover="tableOver(' + row + ')" onMouseout="tableOut( ' + row + ')" id="' + row + '" onClick="dataClick( ' + row + ')" class="data-row">\r\n';
- for(var item in data[row]) {
- html += '<td>' + data[row][item] + '</td>\r\n';
- }
- html += '<td><button class="btn-danger" onclick="unmapData( ' + row + ' )">Delete Tag</button></td>\r\n';
- html += '</tr>\r\n';
+
+ data = normalizeCSV(data);
+
+ /**
+ * constructs html for rows with listeners for tableOver, tableOut, and Click on rows
+ *
+ * * tableData tag with column info
+ * * button tag to delete with unmapData onclick listener
+ *
+ * @param tableOver, tableOut, dataClick, unmapData
+ */
+ for(var row in data) {
+ //HTML addition for new table row (one for every row in CSV)
+ html += '<tr onMouseover="tableOver(' + row + ')" onMouseout="tableOut( ' + row + ')" id="' + row + '" onClick="dataClick( ' + row + ')" class="data-row">\r\n';
+ for(var item in data[row]) {
+ html += '<td>' + data[row][item] + '</td>\r\n';
}
+ html += '<td><button class="btn-danger" onclick="unmapData( ' + row + ' )">Delete Tag</button></td>\r\n';
+ html += '</tr>\r\n';
}
- if(data[0].constructor === Object) {
- for(var row in data) {
- html += '<tr>\r\n';
- for(var item in data[row]) {
- html += '<td>' + item + ':' + data[row][item] + '</td>\r\n';
- }
- html += '</tr>\r\n'; }
- }
-
+
return html;
}
@@ -110,6 +152,9 @@ function generateTableFromJSON(json) {
}
}
+/**
+ * refactor to use $.fn.toggleClass
+ */
function grey_out(item, index){
$('#result').find('#' + index).removeClass("unlinked");
$('#result').find('#' + index).addClass("linked");
diff --git a/static/js/imagemap.js b/static/js/imagemap.js
deleted file mode 100644
index 9a8d93b..0000000
--- a/static/js/imagemap.js
+++ /dev/null
@@ -1,80 +0,0 @@
-// javascript
-
-// Set up some options objects: 'single_opts' for when a single area is selected, which will show just a border
-// 'all_opts' for when all are highlighted, to use a different effect - shaded white with a white border
-// 'initial_opts' for general options that apply to the whole mapster. 'initial_opts' also includes callbacks
-// onMouseover and onMouseout, which are fired when an area is entered or left. We will use these to show or
-// remove the captions, and also set a flag to let the other code know if we're currently in an area.
-var inArea,
- map = $('#mapper'),
- single_opts = {
- fillColor: 'ff0000',
- fillOpacity: 0.2,
- stroke: true,
- strokeColor: 'ff0000',
- strokeWidth: 2
- },
- all_opts = {
- fillColor: 'ffffff',
- fillOpacity: 0.6,
- stroke: true,
- strokeWidth: 2,
- strokeColor: 'ffffff'
- },
- initial_opts = {
- mapKey: 'data-name',
- isSelectable: false,
- // These are called when user hovers over mapped locations on image
- onMouseover: function (data) {
- inArea = true;
- $( "#" + data.key ).addClass("hovered");
- },
- onMouseout: function (data) {
- inArea = false;
- $( "#" + data.key ).removeClass("hovered");
- }
- };
- opts = $.extend({}, all_opts, initial_opts, single_opts);
-
- // Bind to the image 'mouseover' and 'mouseout' events to activate or deactivate ALL the areas, like the
- // original demo. Check whether an area has been activated with "inArea" - IE<9 fires "onmouseover"
- // again for the image when entering an area, so all areas would stay highlighted when entering
- // a specific area in those browsers otherwise. It makes no difference for other browsers.
-
- map.mapster('unbind')
- .mapster(opts)
- .bind('mouseover', function () {
- if (!inArea) {
- map.mapster('set_options', all_opts)
- .mapster('set', true, 'all')
- .mapster('set_options', single_opts);
- }
- }).bind('mouseout', function () {
- if (!inArea) {
- map.mapster('set', false, 'all');
- }
- });
-
-// These are called when user hovers over data in table
-function tableOver(num){
- map = $('#mapper');
- $( "#" + num ).addClass("hovered");
- map.mapster('set_options', single_opts)
- .mapster('set', true, "" + num);
-
-}
-
-function tableOut(num){
- map = $('#mapper');
- $( "#" + num ).removeClass("hovered");
- map.mapster('set_options', single_opts)
- .mapster('set', false, "" + num);
-
-}
-
-$(document).ready(function() {
- $('img').imgAreaSelect({
- handles: true
- });
-
-});
\ No newline at end of file