5390 |
29 Apr 19 |
nicklas |
1 |
|
5390 |
29 Apr 19 |
nicklas |
var Plate = function() |
5390 |
29 Apr 19 |
nicklas |
3 |
{ |
5390 |
29 Apr 19 |
nicklas |
var plate = {}; |
5390 |
29 Apr 19 |
nicklas |
plate.rows = 8; |
5390 |
29 Apr 19 |
nicklas |
plate.columns = 12; |
5390 |
29 Apr 19 |
nicklas |
plate.wells = []; |
5390 |
29 Apr 19 |
nicklas |
plate.wellPainter = null; |
5390 |
29 Apr 19 |
nicklas |
9 |
|
5390 |
29 Apr 19 |
nicklas |
10 |
/** |
5390 |
29 Apr 19 |
nicklas |
Initialize a plate with the given number of rows and columns. |
5390 |
29 Apr 19 |
nicklas |
12 |
*/ |
5392 |
02 May 19 |
nicklas |
plate.init = function(rows, columns, wellPainter) |
5390 |
29 Apr 19 |
nicklas |
14 |
{ |
5390 |
29 Apr 19 |
nicklas |
if (rows) plate.rows = rows; |
5390 |
29 Apr 19 |
nicklas |
if (columns) plate.columns = columns; |
5390 |
29 Apr 19 |
nicklas |
if (wellPainter) plate.wellPainter = wellPainter; |
5390 |
29 Apr 19 |
nicklas |
18 |
|
5390 |
29 Apr 19 |
nicklas |
for (var c = 0; c < plate.columns; c++) |
5390 |
29 Apr 19 |
nicklas |
20 |
{ |
5390 |
29 Apr 19 |
nicklas |
for (var r = 0; r < plate.rows; r++) |
5390 |
29 Apr 19 |
nicklas |
22 |
{ |
5390 |
29 Apr 19 |
nicklas |
plate.wells[plate.wells.length] = new Well(r, c); |
5390 |
29 Apr 19 |
nicklas |
24 |
} |
5390 |
29 Apr 19 |
nicklas |
25 |
} |
5390 |
29 Apr 19 |
nicklas |
26 |
} |
5390 |
29 Apr 19 |
nicklas |
27 |
|
5390 |
29 Apr 19 |
nicklas |
28 |
/** |
5390 |
29 Apr 19 |
nicklas |
Change the well painter for the plate. |
5390 |
29 Apr 19 |
nicklas |
30 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.setWellPainter = function(wellPainter) |
5390 |
29 Apr 19 |
nicklas |
32 |
{ |
5390 |
29 Apr 19 |
nicklas |
plate.wellPainter = wellPainter; |
5390 |
29 Apr 19 |
nicklas |
34 |
} |
5390 |
29 Apr 19 |
nicklas |
35 |
|
5390 |
29 Apr 19 |
nicklas |
36 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get the number of rows on the plate. |
5390 |
29 Apr 19 |
nicklas |
38 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getRows = function() |
5390 |
29 Apr 19 |
nicklas |
40 |
{ |
5390 |
29 Apr 19 |
nicklas |
return plate.rows; |
5390 |
29 Apr 19 |
nicklas |
42 |
} |
5390 |
29 Apr 19 |
nicklas |
43 |
|
5390 |
29 Apr 19 |
nicklas |
44 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get the number of columns on the plate. |
5390 |
29 Apr 19 |
nicklas |
46 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getColumns = function() |
5390 |
29 Apr 19 |
nicklas |
48 |
{ |
5390 |
29 Apr 19 |
nicklas |
return plate.columns; |
5390 |
29 Apr 19 |
nicklas |
50 |
} |
5390 |
29 Apr 19 |
nicklas |
51 |
|
5392 |
02 May 19 |
nicklas |
plate.getFirstEmptyColumn = function() |
5390 |
29 Apr 19 |
nicklas |
53 |
{ |
5392 |
02 May 19 |
nicklas |
for (var column = 0; column < plate.columns; column++) |
5392 |
02 May 19 |
nicklas |
55 |
{ |
5392 |
02 May 19 |
nicklas |
var colIsEmpty = true; |
5392 |
02 May 19 |
nicklas |
var wellNo = column * plate.rows; |
5392 |
02 May 19 |
nicklas |
for (var row = 0; row < plate.rows; row++) |
5392 |
02 May 19 |
nicklas |
59 |
{ |
5392 |
02 May 19 |
nicklas |
if (plate.wells[wellNo+row].extract) break; |
5392 |
02 May 19 |
nicklas |
61 |
} |
5392 |
02 May 19 |
nicklas |
if (row == plate.rows) return column; |
5392 |
02 May 19 |
nicklas |
63 |
} |
5392 |
02 May 19 |
nicklas |
return -1; |
5390 |
29 Apr 19 |
nicklas |
65 |
} |
5390 |
29 Apr 19 |
nicklas |
66 |
|
5390 |
29 Apr 19 |
nicklas |
67 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells on the plate. |
5390 |
29 Apr 19 |
nicklas |
69 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getWells = function() |
5390 |
29 Apr 19 |
nicklas |
71 |
{ |
5390 |
29 Apr 19 |
nicklas |
return plate.wells; |
5390 |
29 Apr 19 |
nicklas |
73 |
} |
5390 |
29 Apr 19 |
nicklas |
74 |
|
5390 |
29 Apr 19 |
nicklas |
75 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells in the given row. First row is 0. |
5390 |
29 Apr 19 |
nicklas |
77 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getRow = function(row) |
5390 |
29 Apr 19 |
nicklas |
79 |
{ |
5390 |
29 Apr 19 |
nicklas |
var result = []; |
5390 |
29 Apr 19 |
nicklas |
for (var i = row; result.length < plate.columns; i += plate.rows) |
5390 |
29 Apr 19 |
nicklas |
82 |
{ |
5390 |
29 Apr 19 |
nicklas |
result[result.length] = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
84 |
} |
5390 |
29 Apr 19 |
nicklas |
return result; |
5390 |
29 Apr 19 |
nicklas |
86 |
} |
5390 |
29 Apr 19 |
nicklas |
87 |
|
5390 |
29 Apr 19 |
nicklas |
88 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells in the given column. First column is 0. |
5390 |
29 Apr 19 |
nicklas |
90 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getColumn = function(column) |
5390 |
29 Apr 19 |
nicklas |
92 |
{ |
5390 |
29 Apr 19 |
nicklas |
var result = []; |
5390 |
29 Apr 19 |
nicklas |
for (var i = column*plate.rows; result.length < plate.rows; i++) |
5390 |
29 Apr 19 |
nicklas |
95 |
{ |
5390 |
29 Apr 19 |
nicklas |
result[result.length] = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
97 |
} |
5390 |
29 Apr 19 |
nicklas |
return result; |
5390 |
29 Apr 19 |
nicklas |
99 |
} |
5390 |
29 Apr 19 |
nicklas |
100 |
|
5390 |
29 Apr 19 |
nicklas |
101 |
/** |
5446 |
24 May 19 |
nicklas |
Get all wells between the given start and end column (inclusive). |
5440 |
20 May 19 |
nicklas |
103 |
*/ |
5446 |
24 May 19 |
nicklas |
plate.getPool = function(startCol, endCol) |
5440 |
20 May 19 |
nicklas |
105 |
{ |
5440 |
20 May 19 |
nicklas |
var result = []; |
5446 |
24 May 19 |
nicklas |
var numCols = endCol - startCol + 1; |
5446 |
24 May 19 |
nicklas |
for (var i = startCol*plate.rows; result.length < plate.rows*numCols; i++) |
5440 |
20 May 19 |
nicklas |
109 |
{ |
5446 |
24 May 19 |
nicklas |
result[result.length] = plate.wells[i]; |
5440 |
20 May 19 |
nicklas |
111 |
} |
5440 |
20 May 19 |
nicklas |
return result; |
5440 |
20 May 19 |
nicklas |
113 |
} |
5440 |
20 May 19 |
nicklas |
114 |
|
5440 |
20 May 19 |
nicklas |
115 |
|
5440 |
20 May 19 |
nicklas |
116 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get the well at the given coordinate. |
5390 |
29 Apr 19 |
nicklas |
118 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getWell = function(row, column) |
5390 |
29 Apr 19 |
nicklas |
120 |
{ |
5390 |
29 Apr 19 |
nicklas |
return plate.wells[row + column * plate.rows]; |
5390 |
29 Apr 19 |
nicklas |
122 |
} |
5390 |
29 Apr 19 |
nicklas |
123 |
|
5397 |
03 May 19 |
nicklas |
plate.getWellByLocation = function(location) |
5397 |
03 May 19 |
nicklas |
125 |
{ |
5397 |
03 May 19 |
nicklas |
var row = Reggie.alphaToWell(location.substring(0,1)); |
5397 |
03 May 19 |
nicklas |
var column = parseInt(location.substring(1))-1; |
5397 |
03 May 19 |
nicklas |
return plate.getWell(row, column); |
5397 |
03 May 19 |
nicklas |
129 |
} |
5397 |
03 May 19 |
nicklas |
130 |
|
5390 |
29 Apr 19 |
nicklas |
131 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells that contains extract with a given name. |
5390 |
29 Apr 19 |
nicklas |
133 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getWellsByName = function(name) |
5390 |
29 Apr 19 |
nicklas |
135 |
{ |
5390 |
29 Apr 19 |
nicklas |
var result = []; |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < plate.wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
138 |
{ |
5390 |
29 Apr 19 |
nicklas |
var well = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
if (well.extract && well.extract.name == name) |
5390 |
29 Apr 19 |
nicklas |
141 |
{ |
5390 |
29 Apr 19 |
nicklas |
result[result.length] = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
143 |
} |
5390 |
29 Apr 19 |
nicklas |
144 |
} |
5390 |
29 Apr 19 |
nicklas |
return result; |
5390 |
29 Apr 19 |
nicklas |
146 |
} |
5390 |
29 Apr 19 |
nicklas |
147 |
|
5390 |
29 Apr 19 |
nicklas |
148 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells that are selected. |
5390 |
29 Apr 19 |
nicklas |
150 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getSelected = function() |
5390 |
29 Apr 19 |
nicklas |
152 |
{ |
5390 |
29 Apr 19 |
nicklas |
var selected = []; |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < plate.wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
155 |
{ |
5390 |
29 Apr 19 |
nicklas |
var well = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
if (well.selected) |
5390 |
29 Apr 19 |
nicklas |
158 |
{ |
5390 |
29 Apr 19 |
nicklas |
selected[selected.length] = well; |
5390 |
29 Apr 19 |
nicklas |
160 |
} |
5390 |
29 Apr 19 |
nicklas |
161 |
} |
5390 |
29 Apr 19 |
nicklas |
return selected; |
5390 |
29 Apr 19 |
nicklas |
163 |
} |
5390 |
29 Apr 19 |
nicklas |
164 |
|
5390 |
29 Apr 19 |
nicklas |
165 |
/** |
5390 |
29 Apr 19 |
nicklas |
Set the selected status for all wells in the array. |
5390 |
29 Apr 19 |
nicklas |
The wells are automatically repainted. |
5390 |
29 Apr 19 |
nicklas |
168 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.setSelected = function(wells, select) |
5390 |
29 Apr 19 |
nicklas |
170 |
{ |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
172 |
{ |
5390 |
29 Apr 19 |
nicklas |
var well = wells[i]; |
5390 |
29 Apr 19 |
nicklas |
well.selected = select; |
5390 |
29 Apr 19 |
nicklas |
well.paint(plate.wellPainter, plate.poolSchema); |
5390 |
29 Apr 19 |
nicklas |
176 |
} |
5390 |
29 Apr 19 |
nicklas |
177 |
} |
5390 |
29 Apr 19 |
nicklas |
178 |
|
5390 |
29 Apr 19 |
nicklas |
179 |
/** |
5390 |
29 Apr 19 |
nicklas |
Get all wells which are used (well.extract has been set) |
5390 |
29 Apr 19 |
nicklas |
181 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.getUsed = function() |
5390 |
29 Apr 19 |
nicklas |
183 |
{ |
5390 |
29 Apr 19 |
nicklas |
var used = []; |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < plate.wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
186 |
{ |
5390 |
29 Apr 19 |
nicklas |
var well = plate.wells[i]; |
5390 |
29 Apr 19 |
nicklas |
if (well.extract) |
5390 |
29 Apr 19 |
nicklas |
189 |
{ |
5390 |
29 Apr 19 |
nicklas |
used[used.length] = well; |
5390 |
29 Apr 19 |
nicklas |
191 |
} |
5390 |
29 Apr 19 |
nicklas |
192 |
} |
5390 |
29 Apr 19 |
nicklas |
return used; |
5390 |
29 Apr 19 |
nicklas |
194 |
} |
5390 |
29 Apr 19 |
nicklas |
195 |
|
5392 |
02 May 19 |
nicklas |
196 |
/** |
5392 |
02 May 19 |
nicklas |
Remove extract from all wells. |
5392 |
02 May 19 |
nicklas |
198 |
*/ |
5392 |
02 May 19 |
nicklas |
plate.clear = function(wells, clearSelected) |
5392 |
02 May 19 |
nicklas |
200 |
{ |
5392 |
02 May 19 |
nicklas |
if (wells.length == 0) return; |
5392 |
02 May 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
5392 |
02 May 19 |
nicklas |
203 |
{ |
5392 |
02 May 19 |
nicklas |
var well = wells[i]; |
5392 |
02 May 19 |
nicklas |
well.extract = null; |
5440 |
20 May 19 |
nicklas |
well.poolNum = -1; |
5392 |
02 May 19 |
nicklas |
if (clearSelected) well.selected = false; |
5392 |
02 May 19 |
nicklas |
208 |
} |
5392 |
02 May 19 |
nicklas |
209 |
} |
5390 |
29 Apr 19 |
nicklas |
210 |
|
5390 |
29 Apr 19 |
nicklas |
211 |
/** |
5390 |
29 Apr 19 |
nicklas |
Toggle the selected status for all wells in the array. |
5390 |
29 Apr 19 |
nicklas |
The next status is determined by the current status of |
5390 |
29 Apr 19 |
nicklas |
the first well in the array. |
5390 |
29 Apr 19 |
nicklas |
215 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.toggleSelected = function(wells) |
5390 |
29 Apr 19 |
nicklas |
217 |
{ |
5390 |
29 Apr 19 |
nicklas |
if (wells.length == 0) return; |
5390 |
29 Apr 19 |
nicklas |
plate.setSelected(wells, !wells[0].selected); |
5390 |
29 Apr 19 |
nicklas |
220 |
} |
5390 |
29 Apr 19 |
nicklas |
221 |
|
5390 |
29 Apr 19 |
nicklas |
222 |
/** |
5392 |
02 May 19 |
nicklas |
Test the filter function on all wells and select or de-select |
5392 |
02 May 19 |
nicklas |
the well if it matches/not matches. |
5392 |
02 May 19 |
nicklas |
225 |
*/ |
5392 |
02 May 19 |
nicklas |
plate.selectByFilter = function(wells, filter) |
5392 |
02 May 19 |
nicklas |
227 |
{ |
5392 |
02 May 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
5392 |
02 May 19 |
nicklas |
229 |
{ |
5392 |
02 May 19 |
nicklas |
var well = wells[i]; |
5392 |
02 May 19 |
nicklas |
well.selected = filter(well); |
5392 |
02 May 19 |
nicklas |
232 |
} |
5392 |
02 May 19 |
nicklas |
plate.paint(wells); |
5392 |
02 May 19 |
nicklas |
234 |
} |
5392 |
02 May 19 |
nicklas |
235 |
|
5392 |
02 May 19 |
nicklas |
236 |
/** |
5390 |
29 Apr 19 |
nicklas |
Enable or disable highlight of the given wells. |
5390 |
29 Apr 19 |
nicklas |
238 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.setHighlight = function(wells, highlightClass, on) |
5390 |
29 Apr 19 |
nicklas |
240 |
{ |
5390 |
29 Apr 19 |
nicklas |
var tmpClass = on ? highlightClass : null; |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
243 |
{ |
5390 |
29 Apr 19 |
nicklas |
var well = wells[i]; |
5390 |
29 Apr 19 |
nicklas |
well.highlightClass = tmpClass; |
5390 |
29 Apr 19 |
nicklas |
Doc.addOrRemoveClass(well.tag, highlightClass, on); |
5390 |
29 Apr 19 |
nicklas |
247 |
} |
5390 |
29 Apr 19 |
nicklas |
248 |
} |
5390 |
29 Apr 19 |
nicklas |
249 |
|
5390 |
29 Apr 19 |
nicklas |
250 |
/** |
5390 |
29 Apr 19 |
nicklas |
Paint the given wells. |
5390 |
29 Apr 19 |
nicklas |
252 |
*/ |
5390 |
29 Apr 19 |
nicklas |
plate.paint = function(wells) |
5390 |
29 Apr 19 |
nicklas |
254 |
{ |
5390 |
29 Apr 19 |
nicklas |
for (var i = 0; i < wells.length; i++) |
5390 |
29 Apr 19 |
nicklas |
256 |
{ |
5392 |
02 May 19 |
nicklas |
wells[i].paint(plate.wellPainter); |
5390 |
29 Apr 19 |
nicklas |
258 |
} |
5390 |
29 Apr 19 |
nicklas |
259 |
} |
5390 |
29 Apr 19 |
nicklas |
260 |
|
5390 |
29 Apr 19 |
nicklas |
return plate; |
5390 |
29 Apr 19 |
nicklas |
262 |
}(); |
5390 |
29 Apr 19 |
nicklas |
263 |
|
5390 |
29 Apr 19 |
nicklas |
264 |
/** |
5390 |
29 Apr 19 |
nicklas |
Represents a well on the plate. Each well is created when |
5390 |
29 Apr 19 |
nicklas |
the page is loaded and is initially empty. |
5390 |
29 Apr 19 |
nicklas |
267 |
*/ |
5390 |
29 Apr 19 |
nicklas |
function Well(row, column) |
5390 |
29 Apr 19 |
nicklas |
269 |
{ |
5390 |
29 Apr 19 |
nicklas |
this.row = row; |
5390 |
29 Apr 19 |
nicklas |
this.column = column; |
5440 |
20 May 19 |
nicklas |
this.poolNum = -1; |
5390 |
29 Apr 19 |
nicklas |
this.selected = false; |
5390 |
29 Apr 19 |
nicklas |
this.highlighClass = null; |
5390 |
29 Apr 19 |
nicklas |
this.extract = null; |
5390 |
29 Apr 19 |
nicklas |
this.warning = null; |
5390 |
29 Apr 19 |
nicklas |
this.error = null; |
5390 |
29 Apr 19 |
nicklas |
278 |
|
5390 |
29 Apr 19 |
nicklas |
this.tag = document.getElementById('well.'+row+'.'+column); |
5390 |
29 Apr 19 |
nicklas |
280 |
} |
5390 |
29 Apr 19 |
nicklas |
281 |
|
5390 |
29 Apr 19 |
nicklas |
282 |
/** |
5390 |
29 Apr 19 |
nicklas |
Set the extract item that is put into this well. Use |
5390 |
29 Apr 19 |
nicklas |
'null' to clear the well. The extract should always |
5390 |
29 Apr 19 |
nicklas |
have a 'name' property, and an 'id' property if it |
5390 |
29 Apr 19 |
nicklas |
exists in the database. |
5390 |
29 Apr 19 |
nicklas |
287 |
*/ |
5390 |
29 Apr 19 |
nicklas |
Well.prototype.setExtract = function(extract) |
5390 |
29 Apr 19 |
nicklas |
289 |
{ |
5390 |
29 Apr 19 |
nicklas |
this.extract = extract; |
5390 |
29 Apr 19 |
nicklas |
291 |
} |
5390 |
29 Apr 19 |
nicklas |
292 |
|
5390 |
29 Apr 19 |
nicklas |
Well.prototype.setWarning = function(warning) |
5390 |
29 Apr 19 |
nicklas |
294 |
{ |
5390 |
29 Apr 19 |
nicklas |
this.warning = warning; |
5390 |
29 Apr 19 |
nicklas |
296 |
} |
5390 |
29 Apr 19 |
nicklas |
297 |
|
5390 |
29 Apr 19 |
nicklas |
Well.prototype.hasWarning = function() |
5390 |
29 Apr 19 |
nicklas |
299 |
{ |
5401 |
07 May 19 |
nicklas |
return this.warning != null || this.extract && this.extract.warning != null; |
5390 |
29 Apr 19 |
nicklas |
301 |
} |
5390 |
29 Apr 19 |
nicklas |
302 |
|
5390 |
29 Apr 19 |
nicklas |
Well.prototype.setError = function(error) |
5390 |
29 Apr 19 |
nicklas |
304 |
{ |
5390 |
29 Apr 19 |
nicklas |
this.error = error; |
5390 |
29 Apr 19 |
nicklas |
306 |
} |
5390 |
29 Apr 19 |
nicklas |
307 |
|
5390 |
29 Apr 19 |
nicklas |
Well.prototype.hasError = function() |
5390 |
29 Apr 19 |
nicklas |
309 |
{ |
5401 |
07 May 19 |
nicklas |
return this.error != null || this.extract && this.extract.error != null; |
5390 |
29 Apr 19 |
nicklas |
311 |
} |
5390 |
29 Apr 19 |
nicklas |
312 |
|
5392 |
02 May 19 |
nicklas |
Well.prototype.getClassName = function(wellPainter) |
5390 |
29 Apr 19 |
nicklas |
314 |
{ |
5390 |
29 Apr 19 |
nicklas |
var c = this.column; |
5390 |
29 Apr 19 |
nicklas |
var cls = 'well col-'+c; |
5390 |
29 Apr 19 |
nicklas |
if (this.selected) cls += ' selected'; |
5390 |
29 Apr 19 |
nicklas |
if (!this.extract) cls += ' empty'; |
5390 |
29 Apr 19 |
nicklas |
if (this.hasError()) cls += ' err'; |
5390 |
29 Apr 19 |
nicklas |
if (this.hasWarning()) cls += ' warning'; |
5390 |
29 Apr 19 |
nicklas |
if (this.highlightClass) cls += ' ' + this.highlightClass; |
5390 |
29 Apr 19 |
nicklas |
322 |
|
5390 |
29 Apr 19 |
nicklas |
if (wellPainter) |
5390 |
29 Apr 19 |
nicklas |
324 |
{ |
5392 |
02 May 19 |
nicklas |
cls += ' ' + wellPainter.getClassNameForWell(this); |
5390 |
29 Apr 19 |
nicklas |
326 |
} |
5390 |
29 Apr 19 |
nicklas |
return cls; |
5390 |
29 Apr 19 |
nicklas |
328 |
} |
5390 |
29 Apr 19 |
nicklas |
329 |
|
5392 |
02 May 19 |
nicklas |
Well.prototype.getText = function(wellPainter) |
5390 |
29 Apr 19 |
nicklas |
331 |
{ |
5390 |
29 Apr 19 |
nicklas |
var text = ''; |
5390 |
29 Apr 19 |
nicklas |
if (wellPainter) |
5390 |
29 Apr 19 |
nicklas |
334 |
{ |
5392 |
02 May 19 |
nicklas |
text = wellPainter.getWellText(this); |
5390 |
29 Apr 19 |
nicklas |
336 |
} |
5390 |
29 Apr 19 |
nicklas |
else |
5390 |
29 Apr 19 |
nicklas |
338 |
{ |
5390 |
29 Apr 19 |
nicklas |
if (this.extract) |
5390 |
29 Apr 19 |
nicklas |
340 |
{ |
5399 |
06 May 19 |
nicklas |
text += '<div class="name">'+Strings.encodeTags(this.extract.name)+'</div>' |
5390 |
29 Apr 19 |
nicklas |
342 |
} |
5390 |
29 Apr 19 |
nicklas |
343 |
} |
5390 |
29 Apr 19 |
nicklas |
if (this.hasError()) |
5390 |
29 Apr 19 |
nicklas |
345 |
{ |
5399 |
06 May 19 |
nicklas |
text += '<div class="err-msg">'+(this.error || this.extract.error)+'</div>'; |
5390 |
29 Apr 19 |
nicklas |
347 |
} |
5390 |
29 Apr 19 |
nicklas |
if (this.hasWarning()) |
5390 |
29 Apr 19 |
nicklas |
349 |
{ |
5401 |
07 May 19 |
nicklas |
text += '<div class="warn-msg">'+(this.warning || this.extract.warning)+'</div>'; |
5390 |
29 Apr 19 |
nicklas |
351 |
} |
5390 |
29 Apr 19 |
nicklas |
return text; |
5390 |
29 Apr 19 |
nicklas |
353 |
} |
5390 |
29 Apr 19 |
nicklas |
354 |
|
5392 |
02 May 19 |
nicklas |
Well.prototype.paint = function(wellPainter) |
5390 |
29 Apr 19 |
nicklas |
356 |
{ |
5390 |
29 Apr 19 |
nicklas |
this.warning = null; |
5390 |
29 Apr 19 |
nicklas |
this.error = null; |
5392 |
02 May 19 |
nicklas |
this.tag.innerHTML = this.getText(wellPainter); |
5392 |
02 May 19 |
nicklas |
this.tag.className = this.getClassName(wellPainter); |
5390 |
29 Apr 19 |
nicklas |
361 |
} |
5390 |
29 Apr 19 |
nicklas |
362 |
|
5448 |
27 May 19 |
nicklas |
363 |
/** |
5448 |
27 May 19 |
nicklas |
Helper class for counting items with the same 'key' value. |
5448 |
27 May 19 |
nicklas |
The 'key' that has the highest count is stored in 'maxKey' |
5448 |
27 May 19 |
nicklas |
and the count for that key in 'maxCount'. All other keys |
5448 |
27 May 19 |
nicklas |
and counts are found in the 'counts' map. |
5448 |
27 May 19 |
nicklas |
368 |
*/ |
5448 |
27 May 19 |
nicklas |
function ItemCounter() |
5448 |
27 May 19 |
nicklas |
370 |
{ |
5448 |
27 May 19 |
nicklas |
this.numCounted = 0; |
5448 |
27 May 19 |
nicklas |
this.maxCount = 0; |
5460 |
03 Jun 19 |
nicklas |
this.maxKey = ''; |
5448 |
27 May 19 |
nicklas |
this.counts = {}; |
5448 |
27 May 19 |
nicklas |
375 |
} |
5390 |
29 Apr 19 |
nicklas |
376 |
|
5448 |
27 May 19 |
nicklas |
ItemCounter.prototype.count = function(key) |
5448 |
27 May 19 |
nicklas |
378 |
{ |
5448 |
27 May 19 |
nicklas |
if (!key) return; |
5448 |
27 May 19 |
nicklas |
this.numCounted++; |
5448 |
27 May 19 |
nicklas |
var c = this.counts[key]; |
5448 |
27 May 19 |
nicklas |
c = c ? c+1 : 1; |
5448 |
27 May 19 |
nicklas |
this.counts[key] = c; |
5448 |
27 May 19 |
nicklas |
if (c > this.maxCount) |
5448 |
27 May 19 |
nicklas |
385 |
{ |
5448 |
27 May 19 |
nicklas |
this.maxKey = key; |
5448 |
27 May 19 |
nicklas |
this.maxCount = c; |
5448 |
27 May 19 |
nicklas |
388 |
} |
5448 |
27 May 19 |
nicklas |
389 |
} |
5448 |
27 May 19 |
nicklas |
390 |
|
5448 |
27 May 19 |
nicklas |
ItemCounter.prototype.numKeys = function() |
5448 |
27 May 19 |
nicklas |
392 |
{ |
5448 |
27 May 19 |
nicklas |
return Object.keys(this.counts).length; |
5448 |
27 May 19 |
nicklas |
394 |
} |
5448 |
27 May 19 |
nicklas |
395 |
|
5518 |
20 Jun 19 |
nicklas |
var MipsColor = function() |
5518 |
20 Jun 19 |
nicklas |
397 |
{ |
5518 |
20 Jun 19 |
nicklas |
var color = {}; |
5518 |
20 Jun 19 |
nicklas |
399 |
|
5519 |
20 Jun 19 |
nicklas |
var PRESET = { |
5599 |
13 Sep 19 |
nicklas |
'ID': 'bg-green', |
5599 |
13 Sep 19 |
nicklas |
'B1B2': 'bg-blue' |
5519 |
20 Jun 19 |
nicklas |
403 |
}; |
5599 |
13 Sep 19 |
nicklas |
var MORE_COLORS = ['bg-yellow', 'bg-gray', 'bg-green-dk', 'bg-blue-dk', 'bg-yellow-dk']; |
5519 |
20 Jun 19 |
nicklas |
405 |
|
5518 |
20 Jun 19 |
nicklas |
var nextColor = 0; |
5518 |
20 Jun 19 |
nicklas |
var colorMap = {}; |
5518 |
20 Jun 19 |
nicklas |
408 |
|
5518 |
20 Jun 19 |
nicklas |
color.reset = function() |
5518 |
20 Jun 19 |
nicklas |
410 |
{ |
5518 |
20 Jun 19 |
nicklas |
colorMap = {}; |
5518 |
20 Jun 19 |
nicklas |
nextColor = 0; |
5518 |
20 Jun 19 |
nicklas |
413 |
} |
5518 |
20 Jun 19 |
nicklas |
414 |
|
5519 |
20 Jun 19 |
nicklas |
415 |
/* |
5600 |
13 Sep 19 |
nicklas |
Get a color preset for the given MIPs panel. A preset is selected |
5600 |
13 Sep 19 |
nicklas |
if the mipsPanel starts with the name of one of the entries in PRESET. |
5600 |
13 Sep 19 |
nicklas |
For example: ID_v1 --> ID --> bg-green |
5519 |
20 Jun 19 |
nicklas |
419 |
*/ |
5600 |
13 Sep 19 |
nicklas |
color.getPresetColor = function(mipsPanel) |
5519 |
20 Jun 19 |
nicklas |
421 |
{ |
5519 |
20 Jun 19 |
nicklas |
for (var p in PRESET) |
5519 |
20 Jun 19 |
nicklas |
423 |
{ |
5600 |
13 Sep 19 |
nicklas |
if (mipsPanel.indexOf(p) == 0) |
5519 |
20 Jun 19 |
nicklas |
425 |
{ |
5519 |
20 Jun 19 |
nicklas |
return PRESET[p]; |
5519 |
20 Jun 19 |
nicklas |
427 |
} |
5519 |
20 Jun 19 |
nicklas |
428 |
} |
5519 |
20 Jun 19 |
nicklas |
return null; |
5519 |
20 Jun 19 |
nicklas |
430 |
} |
5519 |
20 Jun 19 |
nicklas |
431 |
|
5519 |
20 Jun 19 |
nicklas |
432 |
/** |
5600 |
13 Sep 19 |
nicklas |
Get a color for the given MIPs panel. If a color has already been |
5519 |
20 Jun 19 |
nicklas |
assigned, the same color is returned. Otherwise, we check if the MIPs |
5600 |
13 Sep 19 |
nicklas |
panel is one of the presets. If not, a color is assigned from |
5519 |
20 Jun 19 |
nicklas |
MORE_COLORS in order. |
5519 |
20 Jun 19 |
nicklas |
437 |
*/ |
5600 |
13 Sep 19 |
nicklas |
color.getColor = function(mipsPanel) |
5518 |
20 Jun 19 |
nicklas |
439 |
{ |
5600 |
13 Sep 19 |
nicklas |
var c = colorMap[mipsPanel]; |
5518 |
20 Jun 19 |
nicklas |
if (!c) |
5518 |
20 Jun 19 |
nicklas |
442 |
{ |
5600 |
13 Sep 19 |
nicklas |
c = color.getPresetColor(mipsPanel); |
5519 |
20 Jun 19 |
nicklas |
if (!c) |
5519 |
20 Jun 19 |
nicklas |
445 |
{ |
5519 |
20 Jun 19 |
nicklas |
c = MORE_COLORS[nextColor++]; |
5519 |
20 Jun 19 |
nicklas |
if (nextColor >= MORE_COLORS.length) nextColor = 0; |
5519 |
20 Jun 19 |
nicklas |
448 |
} |
5600 |
13 Sep 19 |
nicklas |
colorMap[mipsPanel] = c; |
5518 |
20 Jun 19 |
nicklas |
450 |
} |
5518 |
20 Jun 19 |
nicklas |
return c; |
5518 |
20 Jun 19 |
nicklas |
452 |
} |
5518 |
20 Jun 19 |
nicklas |
453 |
|
5518 |
20 Jun 19 |
nicklas |
return color; |
5518 |
20 Jun 19 |
nicklas |
455 |
}(); |