plate-map 2.0.6 → 3.0.0

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.
@@ -1,409 +0,0 @@
1
- $.widget("DNA.plateMap", {
2
-
3
- plateMapWidget: {},
4
-
5
- options: {
6
- value: 0
7
- },
8
-
9
- addressToLoc: function(address) {
10
- let m = /^([A-Z]+)(\d+)$/.exec(address.trim().toUpperCase());
11
- if (m) {
12
- let row_v = m[1];
13
- let col = parseInt(m[2]) - 1;
14
- let row = 0;
15
- for (let i = 0; i < row_v.length; i++) {
16
- let c = row_v.charCodeAt(i) - 65;
17
- if (i) {
18
- row += 1;
19
- row *= 26;
20
- row += c;
21
- } else {
22
- row = c;
23
- }
24
- }
25
- return {
26
- r: row,
27
- c: col
28
- };
29
- } else {
30
- throw address + " not a proper plate address";
31
- }
32
- },
33
-
34
- locToIndex: function(loc, dimensions) {
35
- if (!dimensions) {
36
- dimensions = this.dimensions;
37
- }
38
- if (!(loc.r >= 0 && loc.r < dimensions.rows)) {
39
- throw "Row index " + (loc.r + 1) + " invalid";
40
- }
41
- if (!(loc.c >= 0 && loc.c < dimensions.cols)) {
42
- throw "Column index " + (loc.c + 1) + " invalid";
43
- }
44
- return loc.r * dimensions.cols + loc.c;
45
- },
46
-
47
- addressToIndex: function(address, dimensions) {
48
- let loc = this.addressToLoc(address);
49
- return this.locToIndex(loc, dimensions);
50
- },
51
-
52
- _rowKey: function(i) {
53
- let c1 = i % 26;
54
- let c2 = (i - c1) / 26;
55
- let code = String.fromCharCode(65 + c1);
56
- if (c2 > 0) {
57
- code = String.fromCharCode(64 + c2) + code;
58
- }
59
- return code;
60
- },
61
-
62
- _colKey: function (i) {
63
- return (i+1).toString(10);
64
- },
65
-
66
- indexToLoc: function(index, dimensions) {
67
- if (!dimensions) {
68
- dimensions = this.dimensions;
69
- }
70
-
71
- if (index >= dimensions.rows * dimensions.cols) {
72
- throw "Index too high: " + index.toString(10);
73
- }
74
- let loc = {};
75
- loc.c = index % dimensions.cols;
76
- loc.r = (index - loc.c) / dimensions.cols;
77
-
78
- return loc;
79
- },
80
-
81
- locToAddress: function(loc) {
82
- return this._rowKey(loc.r) + this._colKey(loc.c);
83
- },
84
-
85
- indexToAddress: function(index, dimensions) {
86
- let loc = this.indexToLoc(index, dimensions);
87
- return this.locToAddress(loc);
88
- },
89
-
90
- getDimensions: function() {
91
- return $.extend(true, {}, this.dimensions);
92
- },
93
-
94
- _create: function() {
95
- let rows = parseInt(this.options.numRows || 8);
96
- let cols = parseInt(this.options.numCols || 12);
97
- this.dimensions = {
98
- rows: rows,
99
- cols: cols
100
- };
101
- this.rowIndex = [];
102
- for (let i = 0; i < rows; i++) {
103
- this.rowIndex.push(this._rowKey(i));
104
- }
105
-
106
- this.target = (this.element[0].id) ? "#" + this.element[0].id : "." + this.element[0].className;
107
-
108
- // Import classes from other files.. Here we import it using extend and add it to this
109
- // object. internally we add to widget.DNA.getPlates.prototype.
110
- // Helpers are methods which return other methods and objects.
111
- // add Objects to plateMapWidget and it will be added to this object.
112
- // set read only well
113
- if (this.options.readOnly) {
114
- this.isReadOnly(true);
115
- }
116
-
117
- for (let component in plateMapWidget) {
118
- if (plateMapWidget.hasOwnProperty(component)) {
119
- // Incase some properties has to initialize with data from options hash,
120
- // we provide it sending this object.
121
- $.extend(this, new plateMapWidget[component](this));
122
- }
123
- }
124
-
125
- this._createInterface();
126
-
127
- this._trigger("created", null, this);
128
-
129
- return this;
130
- },
131
-
132
- _init: function() {
133
- // This is invoked when the user use the plugin after _create is called.
134
- // The point is _create is invoked for the very first time and for all other
135
- // times _init is used.
136
- },
137
-
138
- // wellsData follows syntax: {A1:{field1: val1, field2: val2}, A2:{field1: val1, field2: val2}}
139
- getTextDerivative: function(wellsData) {
140
- let textDerivative = {};
141
- let fieldMap = this.fieldMap;
142
- for (let address in wellsData) {
143
- if (!wellsData.hasOwnProperty(address)) {
144
- continue;
145
- }
146
- let textValWell = {};
147
- let textFieldIdWell = {};
148
- let curWellData = wellsData[address];
149
- for (let fieldId in curWellData) {
150
- if (!curWellData.hasOwnProperty(fieldId)) {
151
- continue;
152
- }
153
- if (fieldId in fieldMap) {
154
- let field = fieldMap[fieldId];
155
- let textVal = field.parseText(curWellData[fieldId]);
156
- textFieldIdWell[field.name] = textVal;
157
- textValWell[fieldId] = textVal;
158
- } else {
159
- // do not convert if not a field
160
- textFieldIdWell[fieldId] = curWellData[fieldId];
161
- textValWell[fieldId] = curWellData[fieldId];
162
- }
163
- }
164
- textDerivative[address] = {
165
- textVal: textValWell,
166
- textFieldVal: textFieldIdWell
167
- };
168
- }
169
-
170
- return textDerivative;
171
- },
172
-
173
- // wellsData follows syntax: {A1:{field1: val1, field2: val2}, A1:{field1: val1, field2: val2}}
174
- getWellsDifferences: function(wellsHash) {
175
- let wells = [];
176
- for (let wellId in wellsHash) {
177
- if (wellsHash.hasOwnProperty(wellId)) {
178
- wells.push(wellsHash[wellId]);
179
- }
180
- }
181
- let differentWellsVals = {};
182
- if (wells.length > 1) {
183
- let commonWell = this._getCommonWell(wells);
184
- let allFieldVal = {};
185
- for (let fieldIdx in wells[0]) {
186
- if (wells[0].hasOwnProperty(fieldIdx)) {
187
- allFieldVal[fieldIdx] = [];
188
- }
189
- }
190
- for (let address in wellsHash) {
191
- if (!wellsHash.hasOwnProperty(address)) {
192
- continue;
193
- }
194
- let diffWellVal = {};
195
- let curWellData = wellsHash[address];
196
- for (let fieldId in curWellData) {
197
- if (!curWellData.hasOwnProperty(fieldId)) {
198
- continue;
199
- }
200
- let commonVal = commonWell[fieldId];
201
- let curVal = curWellData[fieldId];
202
- if (commonVal === undefined) {
203
- commonVal = null;
204
- }
205
- if (curVal === undefined) {
206
- curVal = null;
207
- }
208
- let newVal = null;
209
- if (Array.isArray(curVal)) {
210
- commonVal = commonVal || [];
211
- // get uncommonVal
212
- newVal = [];
213
- for (let idx = 0; idx < curVal.length; idx++) {
214
- let curMultiVal = curVal[idx];
215
- // multiplex field
216
- if (curMultiVal && typeof (curMultiVal) === "object") {
217
- if (!this.containsObject(curMultiVal, commonVal)) {
218
- newVal.push(curMultiVal);
219
- if (!this.containsObject(curMultiVal, allFieldVal[fieldId])) {
220
- allFieldVal[fieldId].push(curMultiVal);
221
- }
222
- }
223
- } else {
224
- if (commonVal.indexOf(curMultiVal) < 0) {
225
- newVal.push(curMultiVal);
226
- if (!allFieldVal[fieldId].indexOf(curMultiVal) >= 0) {
227
- allFieldVal[fieldId].push(curMultiVal);
228
- }
229
- }
230
- }
231
- }
232
- } else if (curVal && typeof (curVal) === "object") {
233
- if (commonVal && typeof (commonVal) === "object") {
234
- if (!((curVal.value === commonVal.value) || (curVal.unit === commonVal.unit))) {
235
- newVal = curVal;
236
- if (!this.containsObject(curVal, allFieldVal[fieldId])) {
237
- allFieldVal[fieldId].push(curVal);
238
- }
239
- }
240
- } else {
241
- newVal = curVal;
242
- if (!this.containsObject(curVal, allFieldVal[fieldId])) {
243
- allFieldVal[fieldId].push(curVal);
244
- }
245
- }
246
- } else if (curVal !== commonVal) {
247
- newVal = curVal;
248
- if (!allFieldVal[fieldId].indexOf(curVal) >= 0) {
249
- allFieldVal[fieldId].push(curVal);
250
- }
251
- }
252
- diffWellVal[fieldId] = newVal;
253
- }
254
-
255
- differentWellsVals[address] = diffWellVal;
256
- }
257
-
258
- // clean up step for fields that are empty
259
- for (let fieldId in allFieldVal) {
260
- if (!allFieldVal.hasOwnProperty(fieldId)) {
261
- continue;
262
- }
263
- if (allFieldVal[fieldId].length === 0) {
264
- for (let address in differentWellsVals) {
265
- if (!differentWellsVals.hasOwnProperty(address)) {
266
- continue;
267
- }
268
- delete differentWellsVals[address][fieldId];
269
- }
270
- }
271
- }
272
-
273
- return differentWellsVals;
274
- } else if (wells.length > 0) {
275
- let differentWellsVals = {};
276
- for (let address in wellsHash) {
277
- if (!wellsHash.hasOwnProperty(address)) {
278
- continue;
279
- }
280
- let diffWellVal = {};
281
- let curWellData = wellsHash[address];
282
- for (let fieldId in curWellData) {
283
- if (!curWellData.hasOwnProperty(fieldId)) {
284
- continue;
285
- }
286
- let curVal = curWellData[fieldId];
287
- if (Array.isArray(curVal)) {
288
- if (curVal.length > 0) {
289
- diffWellVal[fieldId] = curVal
290
- }
291
- } else if (curVal) {
292
- diffWellVal[fieldId] = curVal;
293
- }
294
- }
295
- differentWellsVals[address] = diffWellVal;
296
- }
297
-
298
- return differentWellsVals;
299
- }
300
- },
301
-
302
- setFieldsDisabled: function(flag) {
303
- this.fieldList.forEach(function(field) {
304
- field.disabled(flag);
305
- });
306
- },
307
-
308
- isReadOnly: function(flag) {
309
- this.readOnly = !!flag;
310
- this.readOnlyHandler();
311
- },
312
-
313
- readOnlyHandler: function() {
314
- if (this.readOnly) {
315
- this.overLayButtonContainer.css("display", "none");
316
- $('.multiple-field-manage-delete-button').css("display", "none");
317
- this.setFieldsDisabled(true);
318
- } else {
319
- this.overLayButtonContainer.css("display", "flex");
320
- $('.multiple-field-manage-delete-button').css("display", "none");
321
- if (!this.disableAddDeleteWell) {
322
- this.setFieldsDisabled(false);
323
- }
324
- }
325
- },
326
-
327
- disableAddDeleteWell: null,
328
-
329
- // column_with_default_val will be used to determine empty wells, format: {field_name: default_val}
330
- isDisableAddDeleteWell: function(flag, emptyDefaultWell) {
331
- if (flag) {
332
- let emptyWellWithDefaultVal = $.extend(true, {}, this.defaultWell);
333
- if (emptyDefaultWell) {
334
- for (let field in emptyDefaultWell) {
335
- if (emptyDefaultWell.hasOwnProperty(field)) {
336
- if (field in emptyWellWithDefaultVal) {
337
- emptyWellWithDefaultVal[field] = emptyDefaultWell[field]
338
- } else {
339
- console.log("No field for key: " + key + ", please contact support");
340
- }
341
- }
342
- }
343
- }
344
- this.disableAddDeleteWell = true;
345
- this.addressAllowToEdit = this.getWellSetAddressWithData();
346
- // configure undo redo action
347
- this.actionPointer = 0;
348
- this.undoRedoArray = [this.createState()];
349
- this.emptyWellWithDefaultVal = emptyWellWithDefaultVal;
350
- } else {
351
- this.disableAddDeleteWell = false;
352
- this.emptyWellWithDefaultVal = null;
353
- }
354
- this.readOnlyHandler();
355
- },
356
-
357
- selectObjectInBottomTab: function() {
358
- let colors = [];
359
- let selectedIndices = this.selectedIndices;
360
- for (let i = 0; i < selectedIndices.length; i++) {
361
- let index = selectedIndices[i];
362
- let well = this.engine.derivative[index];
363
- if (well) {
364
- let color = this.engine.colorMap.get(index);
365
- if (colors.indexOf(color) < 0) {
366
- colors.push(color);
367
- }
368
- }
369
- }
370
- let trs = document.querySelectorAll('table.plate-setup-bottom-table tr');
371
- for (let i = 1; i < trs.length; i++) { // start at 1 to skip the table headers
372
- let tr = trs[i];
373
- let td = tr.children[0];
374
- let isSelected = colors.indexOf(Number(td.querySelector('button').innerHTML)) >= 0;
375
- tr.classList.toggle("selected", isSelected);
376
- }
377
- },
378
-
379
- getSelectedIndices: function() {
380
- return this.selectedIndices.slice();
381
- },
382
-
383
- getSelectedAddresses: function() {
384
- return this.selectedIndices.map(function(index) {
385
- return this.allTiles[index].address;
386
- }, this);
387
- },
388
-
389
- setSelectedAddresses: function(addresses, noUndoRedo) {
390
- let indices = this.sanitizeAddresses(addresses);
391
- this.setSelectedIndices(indices, noUndoRedo);
392
- },
393
-
394
- setSelectedIndices: function (indices, noUndoRedo) {
395
- if (!indices || indices.length === 0) {
396
- indices = [0];
397
- }
398
- // Indices should be sanitized
399
- this.setSelection(indices);
400
- //this._colorMixer();
401
- this.decideSelectedFields();
402
- this._trigger("selectedWells", null, {selectedAddress: this.getSelectedAddresses()});
403
- this.selectObjectInBottomTab();
404
- if (!noUndoRedo) {
405
- this.addToUndoRedo();
406
- }
407
- }
408
-
409
- });
package/src/js/preset.js DELETED
@@ -1,56 +0,0 @@
1
- var plateMapWidget = plateMapWidget || {};
2
-
3
- (function($) {
4
-
5
- plateMapWidget.preset = function() {
6
- // All the preset action goes here
7
- return {
8
-
9
- presets: [],
10
-
11
- _placePresetTabs: function() {
12
- let presets = this.options.attributes.presets;
13
-
14
- if (presets && presets.length) {
15
- this.wellAttrContainer = this._createElement("<div></div>").addClass("plate-setup-well-attr-container")
16
- .text("Checkbox presets");
17
- this.tabContainer.append(this.wellAttrContainer);
18
-
19
- this.presetTabContainer = this._createElement("<div></div>").addClass("plate-setup-preset-container");
20
- this.tabContainer.append(this.presetTabContainer);
21
-
22
- for (let i = 0; i < presets.length; i++) {
23
- let preset = presets[i];
24
- let divText = this._createElement("<div></div>").addClass("plate-setup-preset-tab-div")
25
- .text(preset.title);
26
-
27
- let presetButton = this._createElement("<div></div>").addClass("plate-setup-preset-tab")
28
- .data("preset", preset.fields).append(divText);
29
- this.presetTabContainer.append(presetButton);
30
-
31
- let that = this;
32
- presetButton.click(function() {
33
- let preset = $(this);
34
- that._selectPreset(preset);
35
- });
36
- this.presets.push(presetButton);
37
- }
38
- }
39
- },
40
-
41
- _clearPresetSelection: function() {
42
- for (let j = 0; j < this.presets.length; j++) {
43
- let p = this.presets[j];
44
- p.removeClass("plate-setup-preset-tab-selected")
45
- .addClass("plate-setup-preset-tab");
46
- }
47
- },
48
-
49
- _selectPreset: function(preset) {
50
- this.setCheckboxes(preset.data("preset"));
51
- preset.removeClass("plate-setup-preset-tab")
52
- .addClass("plate-setup-preset-tab-selected");
53
- },
54
- };
55
- }
56
- })(jQuery);
@@ -1,126 +0,0 @@
1
- var plateMapWidget = plateMapWidget || {};
2
-
3
- (function(SVG) {
4
-
5
- plateMapWidget.svgCreate = function() {
6
- //
7
- return {
8
-
9
- baseSizes: {
10
- spacing: 48,
11
- tile_radius: 22,
12
- center_radius_complete: 10,
13
- center_radius_incomplete: 14,
14
- label_size: 14,
15
- label_spacing: 24,
16
- text_size: 13,
17
- stroke: 0.5,
18
- gap: 2
19
- },
20
-
21
- allTiles: [],
22
-
23
- _createSvg: function() {
24
- this.svg = new SVG(this.canvasContainer[0]);
25
- this.svg.attr('preserveAspectRatio', 'xMidYMin meet');
26
- let ls = this.baseSizes.label_spacing;
27
-
28
- this.svg.viewbox(-ls, -ls, ls + this.dimensions.cols * this.baseSizes.spacing, ls + this.dimensions.rows * this.baseSizes.spacing);
29
-
30
- this.wellShadow = this.svg.gradient('radial', function (stop) {
31
- stop.at(0.8, 'rgba(0,0,0,0.1)');
32
- stop.at(1, 'rgba(0,0,0,0.2)');
33
- }).from("50%", "50%").to("50%", "55%").radius("50%").attr('id', 'wellShadow');
34
-
35
- this.wellColors = this.colorPairs.map(function (pair, i) {
36
- return this.svg.gradient('linear', function (stop) {
37
- stop.at(0, pair[0]);
38
- stop.at(1, pair[1]);
39
- }).from(0, 0).to(0, 1).id('wellColor' + i.toString());
40
- }, this);
41
-
42
- this._fixRowAndColumn();
43
- this._putCircles();
44
- this._svgEvents();
45
- },
46
-
47
- _fixRowAndColumn: function () {
48
- let cols = this.dimensions.cols;
49
- let rows = this.dimensions.rows;
50
-
51
- let rh = this.svg.nested().attr({'x': -this.baseSizes.label_spacing / 2.0}).addClass('rowHead');
52
- let ch = this.svg.nested().attr({'y': -this.baseSizes.label_spacing / 2.0}).addClass('colHead');
53
-
54
- for (let i = 0; i < rows; i++) {
55
- rh.plain(this._rowKey(i)).attr({y: this.baseSizes.spacing * (i + 0.5)});
56
- }
57
- for (let i = 0; i < cols; i++) {
58
- ch.plain(this._colKey(i)).attr({x: this.baseSizes.spacing * (i + 0.5)});
59
- }
60
- },
61
-
62
- _putCircles: function () {
63
- let cols = this.dimensions.cols;
64
- let rows = this.dimensions.rows;
65
- this.allTiles = Array(cols * rows);
66
-
67
- for (let row = 0; row < rows; row++) {
68
- for (let col = 0; col < cols; col++) {
69
- let tile = this._createTile(row, col);
70
- this.allTiles[tile.index] = tile;
71
- }
72
- }
73
- },
74
-
75
- _createTile: function (r, c) {
76
- let g = this.svg.nested().move(this.baseSizes.spacing * c, this.baseSizes.spacing * r).addClass('tile');
77
- let m = this.baseSizes.spacing / 2.0;
78
-
79
- let d = {"tile": g};
80
- d.r = r;
81
- d.c = c;
82
- d.index = this.locToIndex(d);
83
- d.address = this.locToAddress(d);
84
-
85
- g.rect(this.baseSizes.spacing, this.baseSizes.spacing).addClass('highlight');
86
- g.circle(this.baseSizes.tile_radius * 2).center(m, m).addClass('well').fill(this.wellShadow);
87
-
88
- let tf = g.group().addClass('fill');
89
- d["circle"] = tf.circle(this.baseSizes.tile_radius * 2).center(m, m).addClass('circle').fill(this.wellColors[0]);
90
- tf.circle(this.baseSizes.center_radius_complete * 2).center(m, m).addClass('center');
91
- tf.circle(this.baseSizes.center_radius_incomplete * 2).center(m, m).addClass('center_incomplete');
92
- d["label"] = tf.plain("0").attr({x: m, y: m}).addClass('label');
93
-
94
- return d;
95
- },
96
-
97
- setTileComplete: function (tile, complete) {
98
- if (complete) {
99
- tile.tile.removeClass('incomplete');
100
- } else {
101
- tile.tile.addClass('incomplete');
102
- }
103
- },
104
-
105
- setTileVisible: function (tile, visible) {
106
- if (visible) {
107
- tile.tile.removeClass('empty');
108
- } else {
109
- tile.tile.addClass('empty');
110
- }
111
- },
112
-
113
- setTileColor: function (tile, color) {
114
- this.setTileVisible(tile, true);
115
- tile.colorIndex = parseInt(color);
116
- tile.label.plain(String(tile.colorIndex));
117
-
118
- if (color > 0) {
119
- color = ((color - 1) % (this.wellColors.length - 1)) + 1;
120
- }
121
-
122
- tile.circle.fill(this.wellColors[color])
123
- }
124
- };
125
- }
126
- })(SVG);