plate-map 2.0.6 → 3.0.1

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,354 +0,0 @@
1
- var plateMapWidget = plateMapWidget || {};
2
-
3
- (function($) {
4
-
5
- plateMapWidget.svgEvents = function() {
6
- // This object contains Menu items and how it works;
7
- return {
8
- colorToIndex: {},
9
- selectedIndices: [],
10
-
11
- _svgEvents: function() {
12
- // Set up event handling.
13
- let that = this;
14
-
15
- function getMousePosition(evt) {
16
- let CTM = that.svg.node.getScreenCTM();
17
- return {
18
- x: (evt.clientX - CTM.e) / CTM.a,
19
- y: (evt.clientY - CTM.f) / CTM.d
20
- };
21
- }
22
-
23
- function dimCoord(v, max) {
24
- max = max - 1;
25
- if (v < 0) {
26
- return 0;
27
- } else if (v >= max) {
28
- return max;
29
- } else {
30
- return Math.trunc(v);
31
- }
32
- }
33
-
34
- function posToLoc(pos) {
35
- let s = that.baseSizes.spacing;
36
- let c = dimCoord(pos.x / s, that.dimensions.cols);
37
- let r = dimCoord(pos.y / s, that.dimensions.rows);
38
- return {r: r, c: c}
39
- }
40
-
41
- function selectionBoxPosition(pos0, pos1) {
42
- let d0 = posToLoc(pos0);
43
- let d1 = posToLoc(pos1);
44
- let s = that.baseSizes.spacing;
45
-
46
- let x0 = Math.min(d0.c, d1.c) * s;
47
- let y0 = Math.min(d0.r, d1.r) * s;
48
-
49
- if (pos0.x < 0) {
50
- d0.c = that.dimensions.cols - 1;
51
- }
52
- if (pos0.y < 0) {
53
- d0.r = that.dimensions.rows - 1;
54
- }
55
-
56
- let x1 = (Math.max(d0.c, d1.c) + 1) * s;
57
- let y1 = (Math.max(d0.r, d1.r) + 1) * s;
58
-
59
- return {
60
- x: x0,
61
- y: y0,
62
- width: x1 - x0,
63
- height: y1 - y0,
64
- };
65
- }
66
-
67
- function selectTiles(pos0, pos1, secondary) {
68
- let d0 = posToLoc(pos0);
69
- let d1 = posToLoc(pos1);
70
- let extending = true;
71
- if (secondary) {
72
- // if d0 is already selected, we are deselecting
73
- let startIdx = that.locToIndex(d0);
74
- extending = that.selectedIndices.indexOf(startIdx) < 0;
75
- }
76
- let c0 = Math.min(d0.c, d1.c);
77
- let r0 = Math.min(d0.r, d1.r);
78
-
79
- if (pos0.x < 0) {
80
- d0.c = that.dimensions.cols - 1;
81
- }
82
- if (pos0.y < 0) {
83
- d0.r = that.dimensions.rows - 1;
84
- }
85
-
86
- let c1 = Math.max(d0.c, d1.c);
87
- let r1 = Math.max(d0.r, d1.r);
88
-
89
- let indices = [];
90
-
91
- for (let r = r0; r <= r1; r++) {
92
- for (let c = c0; c <= c1; c++) {
93
- let index = that.locToIndex({'r': r, 'c': c});
94
- indices.push(index)
95
- }
96
- }
97
- if (secondary) {
98
- if (extending) {
99
- that.selectedIndices.forEach(function (index) {
100
- if (indices.indexOf(index) < 0) {
101
- indices.push(index);
102
- }
103
- });
104
- } else {
105
- indices = that.selectedIndices.filter(index => indices.indexOf(index) < 0);
106
- }
107
- }
108
-
109
- that.setSelectedIndices(indices.sort());
110
- }
111
-
112
- let selectionBox;
113
-
114
- function startDrag(evt) {
115
- if (selectionBox) {
116
- selectionBox.remove();
117
- }
118
- let pos = getMousePosition(evt);
119
- let attrs = selectionBoxPosition(pos, pos);
120
- selectionBox = that.svg.rect().attr(attrs).fill('rgba(0, 0, 1, 0.2)');
121
- selectionBox.data('origin', pos);
122
- }
123
-
124
- function drag(evt) {
125
- if (selectionBox) {
126
- let pos = getMousePosition(evt);
127
- let attrs = selectionBoxPosition(selectionBox.data('origin'), pos);
128
- selectionBox.attr(attrs);
129
- }
130
- }
131
-
132
- function endDrag(evt) {
133
- if (selectionBox) {
134
- let startPos = selectionBox.data('origin');
135
- let pos = getMousePosition(evt);
136
- selectTiles(startPos, pos, evt.shiftKey);
137
- selectionBox.remove();
138
- selectionBox = null;
139
- }
140
- }
141
-
142
- this.svg.node.addEventListener('mousedown', startDrag);
143
- this.svg.node.addEventListener('mousemove', drag);
144
- this.svg.node.addEventListener('mouseleave', endDrag);
145
- this.svg.node.addEventListener('mouseup', endDrag);
146
-
147
- $(that.target).on("loadPlate", function(evt, data) {
148
- // This method should be compatible to redo/undo.
149
- that.loadPlate(JSON.parse(data));
150
- });
151
- },
152
-
153
- setSelection: function(selectedIndices) {
154
- this.selectedIndices = selectedIndices;
155
- this._setSelectedTiles();
156
- document.activeElement.blur();
157
- },
158
-
159
- _setSelectedTiles: function() {
160
- // Update selected tile display only
161
- let selectedIndices = this.selectedIndices;
162
- this.allTiles.forEach(function(tile) {
163
- let selected = selectedIndices.indexOf(tile.index) >= 0;
164
- if (selected) {
165
- tile.tile.addClass('selected');
166
- } else {
167
- tile.tile.removeClass('selected');
168
- }
169
- })
170
- },
171
-
172
- _getSelectedWells: function() {
173
- return this.selectedIndices.map(function(index) {
174
- let well = this.engine.derivative[index];
175
- if (!well) {
176
- well = this.defaultWell;
177
- }
178
- return well;
179
- }, this);
180
- },
181
-
182
- containsObject: function(obj, list) {
183
- function deepEqual (x, y) {
184
- if (x === y) {
185
- return true;
186
- } else if ((typeof x == "object" && x != null) && (typeof y == "object" && y != null)) {
187
- if (Object.keys(x).length !== Object.keys(y).length) {
188
- return false;
189
- }
190
- for (let prop in x) {
191
- if (x.hasOwnProperty(prop)) {
192
- if (y.hasOwnProperty(prop)) {
193
- if (!deepEqual(x[prop], y[prop])) {
194
- return false;
195
- }
196
- } else {
197
- return false;
198
- }
199
- }
200
- }
201
- return true;
202
- } else {
203
- return false;
204
- }
205
- }
206
-
207
- if (list) {
208
- for (let i = 0; i < list.length; i++) {
209
- if (deepEqual(obj, list[i])) {
210
- return true;
211
- }
212
- }
213
- }
214
- return false;
215
- },
216
-
217
- _buildCommonData: function(commonData, obj, field) {
218
- let commonVal = commonData[field];
219
- if (commonVal === undefined) {
220
- commonVal = null;
221
- }
222
- let objVal = obj[field];
223
- if (objVal === undefined) {
224
- objVal = null;
225
- }
226
-
227
- if (Array.isArray(commonVal)) {
228
- let commonArr = [];
229
- for (let i = 0; i < commonVal.length; i++) {
230
- let v = commonVal[i];
231
- // for multiplex field
232
- if (v && typeof (v) === "object") {
233
- for (let j = 0; j < objVal.length; j++) {
234
- let v2 = objVal[j];
235
- if (v[field] == v2[field]) {
236
- v = $.extend(true, {}, v);
237
- for (let oField in v) {
238
- this._buildCommonData(v, v2, oField);
239
- }
240
- commonArr.push(v)
241
- }
242
- }
243
- // if (this.containsObject(v, objVal)) {
244
- // commonArr.push(v);
245
- // }
246
- } else {
247
- if ($.inArray(v, objVal) >= 0) {
248
- commonArr.push(v);
249
- }
250
- }
251
- }
252
- commonData[field] = commonArr;
253
- } else {
254
- if (objVal && typeof (objVal) === "object" && commonVal && typeof (commonVal) === "object") {
255
- if ((objVal.value !== commonVal.value) || (objVal.unit !== commonVal.unit)) {
256
- delete commonData[field];
257
- }
258
- } else if (commonVal !== objVal) {
259
- delete commonData[field];
260
- }
261
- }
262
- },
263
-
264
- _getCommonData: function(wells) {
265
- let commonData = null;
266
- for (let i = 0; i < wells.length; i++) {
267
- let well = wells[i];
268
- if (well == null) {
269
- continue;
270
- }
271
- if (commonData == null) {
272
- commonData = $.extend(true, {}, wells[0]);
273
- continue
274
- }
275
- for (let field in commonData) {
276
- if (!commonData.hasOwnProperty(field)) {
277
- continue;
278
- }
279
- this._buildCommonData(commonData, well, field);
280
- }
281
- }
282
- return commonData || this.defaultWell;
283
- },
284
-
285
- _getCommonWell: function (wells) {
286
- let commonData = this._getCommonData(wells);
287
- return this.sanitizeWell(commonData);
288
- },
289
-
290
- _getAllMultipleVal: function(wells) {
291
- let multipleFieldList = this.multipleFieldList;
292
- let that = this;
293
-
294
- multipleFieldList.forEach(function(multiplexField) {
295
- if (wells.length) {
296
- let curMultipleVal = {};
297
- let multiData = null;
298
- wells.forEach(function(well) {
299
- if (well == null) {
300
- return;
301
- }
302
- let id = multiplexField.id;
303
- let wellFieldVals = well[id];
304
- if (wellFieldVals && wellFieldVals.length) {
305
- wellFieldVals.forEach(function(multipleVal) {
306
- if (typeof (multipleVal) === 'object') {
307
- if (multiData == null) {
308
- multiData = $.extend(true, {}, multipleVal);
309
- } else {
310
- for (let oField in multiData) {
311
- that._buildCommonData(multiData, multipleVal, oField);
312
- }
313
- }
314
- if (multipleVal[id] in curMultipleVal) {
315
- curMultipleVal[multipleVal[id]]++;
316
- } else {
317
- curMultipleVal[multipleVal[id]] = 1;
318
- }
319
- } else {
320
- if (multipleVal in curMultipleVal) {
321
- curMultipleVal[multipleVal]++;
322
- } else {
323
- curMultipleVal[multipleVal] = 1;
324
- }
325
- }
326
- })
327
- }
328
- });
329
- multiplexField.allSelectedMultipleData = multiData || {};
330
- multiplexField.allSelectedMultipleVal = curMultipleVal;
331
- } else {
332
- multiplexField.allSelectedMultipleData = null;
333
- multiplexField.allSelectedMultipleVal = null
334
- }
335
- });
336
- },
337
-
338
- decideSelectedFields: function() {
339
- let wells = this._getSelectedWells();
340
- this._getAllMultipleVal(wells);
341
- this.applyFieldWarning(wells);
342
- let well = this._getCommonWell(wells);
343
- this._addDataToTabFields(well);
344
- },
345
-
346
- // get all wells that have data
347
- getWellSetAddressWithData: function() {
348
- let indices = Object.keys(this.engine.derivative).map(Number).sort();
349
- return indices.map(this.indexToAddress, this)
350
- }
351
-
352
- };
353
- }
354
- })(jQuery);
package/src/js/tabs.js DELETED
@@ -1,82 +0,0 @@
1
- var plateMapWidget = plateMapWidget || {};
2
-
3
- (function($) {
4
-
5
- plateMapWidget.tabs = function() {
6
- // Tabs create and manage tabs at the right side of widget.
7
- return {
8
-
9
- allTabs: [],
10
-
11
- defaultWell: {},
12
-
13
- allDataTabs: [], // To hold all the tab contents. this contains all the tabs and its elements and elements
14
- // Settings as a whole. its very useful, when we have units for a specific field.
15
- // it goes like tabs-> individual field-> units and checkbox
16
-
17
- _createTabAtRight: function() {
18
- this.tabContainer = this._createElement("<div></div>").addClass("plate-setup-tab-container");
19
- $(this.topRight).append(this.tabContainer);
20
- },
21
-
22
- _createTabs: function() {
23
- // this could be done using z-index. just imagine few cards stacked up.
24
- // Check if options has tab data.
25
- // Originally we will be pulling tab data from developer.
26
- // Now we are building upon dummy data.
27
- this.tabHead = this._createElement("<div></div>").addClass("plate-setup-tab-head");
28
- $(this.tabContainer).append(this.tabHead);
29
-
30
- let tabData = this.options.attributes.tabs;
31
- let that = this;
32
-
33
- tabData.forEach(function(tab, tabIndex) {
34
- that.allTabs[tabIndex] = that._createElement("<div></div>").addClass("plate-setup-tab");
35
- $(that.allTabs[tabIndex]).data("index", tabIndex)
36
- .text(tab.name);
37
-
38
- $(that.allTabs[tabIndex]).click(function() {
39
- that._tabClickHandler(this);
40
- });
41
-
42
- $(that.tabHead).append(that.allTabs[tabIndex]);
43
- });
44
-
45
- this.tabDataContainer = this._createElement("<div></div>").addClass("plate-setup-tab-data-container");
46
- $(this.tabContainer).append(this.tabDataContainer);
47
-
48
- this._addDataTabs(tabData);
49
-
50
- $(this.allTabs[0]).click();
51
-
52
- this._addTabData();
53
- },
54
-
55
- _tabClickHandler: function(clickedTab) {
56
-
57
- if (this.selectedTab) {
58
- $(this.selectedTab).removeClass("plate-setup-tab-selected")
59
- .addClass("plate-setup-tab");
60
-
61
- let previouslyClickedTabIndex = $(this.selectedTab).data("index");
62
- $(this.allDataTabs[previouslyClickedTabIndex]).css("z-index", 0);
63
- this.readOnlyHandler();
64
- }
65
-
66
- $(clickedTab).addClass("plate-setup-tab-selected");
67
-
68
- this.selectedTab = clickedTab;
69
-
70
- let clickedTabIndex = $(clickedTab).data("index");
71
- $(this.allDataTabs[clickedTabIndex]).css("z-index", 1000);
72
- },
73
-
74
- _addDataTabs: function(tabs) {
75
- this.allDataTabs = tabs.map(function () {
76
- return this._createElement("<div></div>").addClass("plate-setup-data-div").css("z-index", 0);
77
- }, this);
78
- $(this.tabDataContainer).append(this.allDataTabs);
79
- }
80
- };
81
- }
82
- })(jQuery);
@@ -1,76 +0,0 @@
1
- var plateMapWidget = plateMapWidget || {};
2
-
3
- (function($) {
4
-
5
- plateMapWidget.undoRedoManager = function() {
6
-
7
- return {
8
-
9
- undoRedoArray: [],
10
-
11
- actionPointer: null,
12
-
13
- addToUndoRedo: function() {
14
- let state = this.createState();
15
- if (this.actionPointer != null) {
16
- let i = this.actionPointer + 1;
17
- if (i < this.undoRedoArray.length) {
18
- this.undoRedoArray.splice(i, this.undoRedoArray.length - i);
19
- }
20
- }
21
- this.actionPointer = null;
22
- this.undoRedoArray.push(state);
23
- },
24
-
25
- _configureUndoRedoArray: function() {
26
-
27
- let data = {
28
- checkboxes: [],
29
- derivative: {},
30
- selectedIndices: [0]
31
- };
32
-
33
- this.undoRedoArray = [];
34
- this.actionPointer = null;
35
- this.undoRedoArray.push($.extend({}, data));
36
- },
37
-
38
- clearHistory: function () {
39
- this.undoRedoArray = this.undoRedoArray.slice(-1);
40
- this.actionPointer = null;
41
- },
42
-
43
- undo: function() {
44
- console.log("undo");
45
- return this.shiftUndoRedo(-1);
46
- },
47
-
48
- redo: function() {
49
- console.log("redo");
50
- return this.shiftUndoRedo(1);
51
- },
52
-
53
- shiftUndoRedo: function(pointerDiff) {
54
- let pointer = this.actionPointer;
55
- if (pointer == null) {
56
- pointer = this.undoRedoArray.length - 1;
57
- }
58
- pointer += pointerDiff;
59
- return this.setUndoRedo(pointer);
60
- },
61
-
62
- setUndoRedo: function(pointer) {
63
- if (pointer < 0) {
64
- return false;
65
- }
66
- if (pointer >= this.undoRedoArray.length) {
67
- return false;
68
- }
69
- this.actionPointer = pointer;
70
- this.setData(this.undoRedoArray[pointer], true);
71
- return true;
72
- }
73
- }
74
- };
75
-
76
- })(jQuery);