@webviz/subsurface-viewer 1.15.6 → 1.15.8

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.
Files changed (37) hide show
  1. package/dist/SubsurfaceViewer.d.ts +10 -14
  2. package/dist/SubsurfaceViewer.js.map +1 -1
  3. package/dist/components/Map.js +1 -1
  4. package/dist/components/Map.js.map +1 -1
  5. package/dist/layers/BoxSelectionLayer/boxSelectionLayer.d.ts +2 -18
  6. package/dist/layers/BoxSelectionLayer/boxSelectionLayer.js +2 -2
  7. package/dist/layers/BoxSelectionLayer/boxSelectionLayer.js.map +1 -1
  8. package/dist/layers/types.d.ts +2 -2
  9. package/dist/layers/utils/layerTools.d.ts +9 -1
  10. package/dist/layers/utils/layerTools.js +15 -0
  11. package/dist/layers/utils/layerTools.js.map +1 -1
  12. package/dist/layers/wells/layers/logCurveLayer.d.ts +56 -0
  13. package/dist/layers/wells/layers/logCurveLayer.js +286 -0
  14. package/dist/layers/wells/layers/logCurveLayer.js.map +1 -0
  15. package/dist/layers/wells/types.d.ts +10 -7
  16. package/dist/layers/wells/utils/features.d.ts +21 -0
  17. package/dist/layers/wells/utils/features.js +52 -0
  18. package/dist/layers/wells/utils/features.js.map +1 -0
  19. package/dist/layers/wells/utils/log.d.ts +31 -0
  20. package/dist/layers/wells/utils/log.js +307 -0
  21. package/dist/layers/wells/utils/log.js.map +1 -0
  22. package/dist/layers/wells/utils/trajectory.d.ts +8 -6
  23. package/dist/layers/wells/utils/trajectory.js +115 -1
  24. package/dist/layers/wells/utils/trajectory.js.map +1 -1
  25. package/dist/layers/wells/utils/wells.d.ts +30 -0
  26. package/dist/layers/wells/utils/wells.js +55 -0
  27. package/dist/layers/wells/utils/wells.js.map +1 -0
  28. package/dist/layers/wells/wellsLayer.d.ts +10 -13
  29. package/dist/layers/wells/wellsLayer.js +71 -594
  30. package/dist/layers/wells/wellsLayer.js.map +1 -1
  31. package/dist/utils/arrays.d.ts +7 -0
  32. package/dist/utils/arrays.js +10 -0
  33. package/dist/utils/arrays.js.map +1 -0
  34. package/dist/utils/measurement.d.ts +16 -0
  35. package/dist/utils/measurement.js +37 -0
  36. package/dist/utils/measurement.js.map +1 -1
  37. package/package.json +2 -2
@@ -1,17 +1,20 @@
1
- import { interpolateNumberArray } from "d3";
2
1
  import _, { isEmpty, isEqual } from "lodash";
3
- import { distance, dot, subtract } from "mathjs";
4
2
  import { CompositeLayer } from "@deck.gl/core";
5
3
  import { PathStyleExtension } from "@deck.gl/extensions";
6
- import { GeoJsonLayer, PathLayer } from "@deck.gl/layers";
4
+ import { GeoJsonLayer } from "@deck.gl/layers";
7
5
  import { GL } from "@luma.gl/constants";
8
- import { getColors, rgbValues } from "@emerson-eps/color-tables/";
9
- import { createPropertyData, getLayersById, isDrawingEnabled, } from "../utils/layerTools";
6
+ import { createPropertyData, getFromAccessor, getLayersById, isDrawingEnabled, } from "../utils/layerTools";
10
7
  import { SectionViewport } from "../../viewports";
11
8
  import { WellLabelLayer } from "./layers/wellLabelLayer";
12
9
  import { abscissaTransform } from "./utils/abscissaTransform";
13
10
  import { GetBoundingBox, checkWells, coarsenWells, invertPath, splineRefine, } from "./utils/spline";
14
- import { getColor, getTrajectory } from "./utils/trajectory";
11
+ import { getColor, getMd, getTrajectory, getTvd } from "./utils/trajectory";
12
+ import { LogCurveLayer } from "./layers/logCurveLayer";
13
+ import { getWellMds, getWellObjectByName, getWellObjectsByName, } from "./utils/wells";
14
+ import { getLegendData, getLogProperty } from "./utils/log";
15
+ import { getSize, LINE, POINT, DEFAULT_LINE_WIDTH } from "./utils/features";
16
+ import { scaleArray } from "../../utils/arrays";
17
+ const DEFAULT_DASH = [5, 5];
15
18
  export var SubLayerId;
16
19
  (function (SubLayerId) {
17
20
  SubLayerId["COLORS"] = "colors";
@@ -47,27 +50,6 @@ const defaultProps = {
47
50
  wellNameColor: [0, 0, 0, 255],
48
51
  wellNameSize: 10,
49
52
  };
50
- const LINE = "line";
51
- const POINT = "point";
52
- const DEFAULT_POINT_SIZE = 8;
53
- const DEFAULT_LINE_WIDTH = 5;
54
- const DEFAULT_DASH = [5, 5];
55
- export function getSize(type, accessor, offset = 0) {
56
- if (typeof accessor == "function") {
57
- return (object) => {
58
- return (accessor(object) + offset);
59
- };
60
- }
61
- if (accessor == 0)
62
- return 0;
63
- if (accessor > 0)
64
- return accessor + offset;
65
- if (type == LINE)
66
- return DEFAULT_LINE_WIDTH + offset;
67
- if (type == POINT)
68
- return DEFAULT_POINT_SIZE + offset;
69
- return 0;
70
- }
71
53
  export default class WellsLayer extends CompositeLayer {
72
54
  recomputeDataState() {
73
55
  const { data, refine, ZIncreasingDownwards, section } = this.props;
@@ -117,23 +99,28 @@ export default class WellsLayer extends CompositeLayer {
117
99
  }
118
100
  }
119
101
  onClick(info) {
120
- var _a;
121
102
  // Make selection only when drawing is disabled
122
103
  if (isDrawingEnabled(this.context.layerManager)) {
123
104
  return false;
124
105
  }
125
106
  else {
126
107
  this.context.userData.setEditedData({
127
- selectedWell: (_a = info.object) === null || _a === void 0 ? void 0 : _a.properties.name,
108
+ selectedWell: info.wellName,
128
109
  });
129
110
  return false; // do not return true to allow DeckGL props.onClick to be called
130
111
  }
131
112
  }
132
- setSelection(well, _selection) {
133
- if (this.internalState) {
113
+ setSelection(well, selection) {
114
+ if (!this.internalState)
115
+ return;
116
+ if (!well || !selection) {
117
+ this.setState({
118
+ logDomainSelection: undefined,
119
+ });
120
+ }
121
+ else {
134
122
  this.setState({
135
- well: well,
136
- selection: _selection,
123
+ logDomainSelection: { well, selection },
137
124
  });
138
125
  }
139
126
  }
@@ -151,6 +138,7 @@ export default class WellsLayer extends CompositeLayer {
151
138
  }
152
139
  return data;
153
140
  }
141
+ // ? Unused ?
154
142
  getLegendData(value) {
155
143
  return getLegendData(value, "", this.props.logName, this.props.logColor);
156
144
  }
@@ -160,20 +148,19 @@ export default class WellsLayer extends CompositeLayer {
160
148
  });
161
149
  }
162
150
  getLogLayer() {
163
- var _a;
151
+ var _a, _b;
164
152
  const sub_layers = (_a = this.internalState) === null || _a === void 0 ? void 0 : _a.subLayers;
165
- const log_layer = getLayersById(sub_layers, "wells-layer-log_curve");
166
- return log_layer === null || log_layer === void 0 ? void 0 : log_layer[0];
153
+ const log_layers = getLayersById(sub_layers, "wells-layer-log_curve");
154
+ return (_b = log_layers === null || log_layers === void 0 ? void 0 : log_layers[0]) === null || _b === void 0 ? void 0 : _b.getCurveLayer();
167
155
  }
168
156
  getSelectionLayer() {
169
- var _a;
157
+ var _a, _b;
170
158
  const sub_layers = (_a = this.internalState) === null || _a === void 0 ? void 0 : _a.subLayers;
171
- const log_layer = getLayersById(sub_layers, "wells-layer-selection");
172
- return log_layer === null || log_layer === void 0 ? void 0 : log_layer[0];
159
+ const log_layer = getLayersById(sub_layers, "wells-layer-log_curve");
160
+ return (_b = log_layer === null || log_layer === void 0 ? void 0 : log_layer[0]) === null || _b === void 0 ? void 0 : _b.getSelectionLayer();
173
161
  }
174
162
  getLogCurveData() {
175
- const log_layer = this.getLogLayer();
176
- return log_layer === null || log_layer === void 0 ? void 0 : log_layer.props.data;
163
+ return this.state.logData;
177
164
  }
178
165
  setupLegend() {
179
166
  const data = this.getLogCurveData();
@@ -264,92 +251,45 @@ export default class WellsLayer extends CompositeLayer {
264
251
  const highlightLayer = new GeoJsonLayer(highlightLayerProps);
265
252
  // Highlight the multi selected wells.
266
253
  const highlightMultiWellsLayer = new GeoJsonLayer(highlightMultiWellsLayerProps);
267
- const logLayer = new PathLayer(this.getSubLayerProps({
254
+ const logLayer = new LogCurveLayer(Object.assign({}, this.getSubLayerProps({
268
255
  id: SubLayerId.LOG_CURVE,
269
- data: this.props.logData,
270
- positionFormat,
256
+ visible: this.props.logCurves && !fastDrawing,
271
257
  pickable: true,
272
- widthScale: 10,
273
- widthMinPixels: 1,
274
- miterLimit: 100,
275
- getPath: (d) => {
276
- var _a;
277
- return getLogPath(data.features, d, this.props.logrunName, (_a = this.props.lineStyle) === null || _a === void 0 ? void 0 : _a.color);
278
- },
279
- getColor: (d) => getLogColor(d, this.props.logrunName, this.props.logName, this.props.logColor, this.context.userData
280
- .colorTables, this.props.colorMappingFunction, this.props.isLog),
281
- getWidth: (d) => this.props.logRadius ||
282
- getLogWidth(d, this.props.logrunName, this.props.logName),
283
- updateTriggers: {
284
- getColor: [
285
- this.props.logrunName,
286
- this.props.logName,
287
- this.props.logColor,
288
- this.context.userData
289
- .colorTables,
290
- this.props.isLog,
291
- ],
292
- getWidth: [
293
- this.props.logrunName,
294
- this.props.logName,
295
- this.props.logRadius,
296
- ],
297
- getPath: [positionFormat],
298
- },
299
- onDataLoad: (value) => {
300
- this.setLegend(value);
301
- },
302
258
  parameters,
303
- visible: this.props.logCurves && !fastDrawing,
304
- }));
305
- const selectionLayer = new PathLayer(this.getSubLayerProps({
306
- id: SubLayerId.SELECTION,
307
- data: this.props.logData,
308
259
  positionFormat,
309
- pickable: false,
310
- widthScale: 10,
311
- widthMinPixels: 1,
312
- miterLimit: 100,
313
- getPath: (d) => {
314
- var _a;
315
- return getLogPath1(data.features, d, this.state.well, this.state.selection, this.props.logrunName, (_a = this.props.lineStyle) === null || _a === void 0 ? void 0 : _a.color);
260
+ data: this.props.logData,
261
+ trajectoryData: data,
262
+ domainSelection: this.state.logDomainSelection,
263
+ logWidth: this.props.logRadius || "value",
264
+ activeLog: {
265
+ logRun: this.props.logrunName,
266
+ curveName: this.props.logName,
316
267
  },
317
- getColor: (d) => getLogColor1(data.features, d, this.state.well, this.state.selection, this.props.logrunName),
318
- getWidth: (d) => this.props.logRadius * 1.5 ||
319
- getLogWidth(d, this.props.logrunName, this.props.logName),
320
- updateTriggers: {
321
- getColor: [
322
- this.props.logrunName,
323
- this.state.well,
324
- this.state.selection,
325
- ],
326
- getWidth: [
327
- this.props.logrunName,
328
- this.props.logName,
329
- this.props.logRadius,
330
- ],
331
- getPath: [
332
- positionFormat,
333
- this.props.logrunName,
334
- this.state.well,
335
- this.state.selection,
336
- ],
268
+ colorScale: {
269
+ name: this.props.logColor,
270
+ isLogarithmic: this.props.isLog,
271
+ colorTables: this.context.userData
272
+ .colorTables,
273
+ mappingFunction: this.props.colorMappingFunction,
337
274
  },
338
- onDataLoad: (value) => {
275
+ getWellMds: getWellMds,
276
+ getTrajectoryPath: (d) => { var _a; return getTrajectory(d, (_a = this.props.lineStyle) === null || _a === void 0 ? void 0 : _a.color); },
277
+ onLogDataComputed: (value) => {
278
+ this.setState({ logData: value });
339
279
  this.setLegend(value);
340
280
  },
341
- parameters,
342
- visible: this.props.logCurves && !fastDrawing,
343
- }));
281
+ updateTriggers: {
282
+ getTrajectoryPath: [this.props.lineStyle],
283
+ },
284
+ })));
344
285
  const namesLayer = this.createWellLabelLayer(data.features);
345
286
  const layers = [
346
287
  outlineLayer,
347
- logLayer,
348
288
  colorsLayer,
349
289
  highlightLayer,
350
290
  highlightMultiWellsLayer,
351
- selectionLayer,
352
291
  namesLayer,
292
+ logLayer,
353
293
  ];
354
294
  if (fastDrawing) {
355
295
  layers.push(fastLayer);
@@ -357,7 +297,7 @@ export default class WellsLayer extends CompositeLayer {
357
297
  return layers;
358
298
  }
359
299
  getPickingInfo({ info }) {
360
- var _a, _b, _c, _d, _e, _f;
300
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
361
301
  const noLog = {
362
302
  properties: [],
363
303
  logName: "",
@@ -371,6 +311,7 @@ export default class WellsLayer extends CompositeLayer {
371
311
  if (typeof coordinate[2] !== "undefined") {
372
312
  coordinate[2] /= Math.max(0.001, zScale);
373
313
  }
314
+ let wellName = undefined;
374
315
  let md_property = null;
375
316
  let tvd_property = null;
376
317
  let log_property = null;
@@ -378,6 +319,7 @@ export default class WellsLayer extends CompositeLayer {
378
319
  if (((_d = info.sourceLayer) === null || _d === void 0 ? void 0 : _d.id) === `${this.props.id}-${SubLayerId.LOG_CURVE}`) {
379
320
  // The user is hovering a well log entry
380
321
  const logPick = info;
322
+ wellName = (_f = (_e = logPick.object) === null || _e === void 0 ? void 0 : _e.header) === null || _f === void 0 ? void 0 : _f.well;
381
323
  md_property = getLogProperty(coordinate, features, logPick.object, this.props.logrunName, "MD");
382
324
  tvd_property = getLogProperty(coordinate, features, logPick.object, this.props.logrunName, "TVD");
383
325
  log_property = getLogProperty(coordinate, features, info.object, this.props.logrunName, this.props.logName);
@@ -385,8 +327,9 @@ export default class WellsLayer extends CompositeLayer {
385
327
  else {
386
328
  // User is hovering a wellbore path
387
329
  const wellpickInfo = info;
388
- md_property = getMdProperty(coordinate, wellpickInfo.object, (_e = this.props.lineStyle) === null || _e === void 0 ? void 0 : _e.color, info.featureType);
389
- tvd_property = getTvdProperty(coordinate, info.object, (_f = this.props.lineStyle) === null || _f === void 0 ? void 0 : _f.color, info.featureType);
330
+ wellName = (_h = (_g = wellpickInfo.object) === null || _g === void 0 ? void 0 : _g.properties) === null || _h === void 0 ? void 0 : _h.name;
331
+ md_property = getMdProperty(coordinate, wellpickInfo.object, (_j = this.props.lineStyle) === null || _j === void 0 ? void 0 : _j.color, info.featureType);
332
+ tvd_property = getTvdProperty(coordinate, info.object, (_k = this.props.lineStyle) === null || _k === void 0 ? void 0 : _k.color, info.featureType);
390
333
  }
391
334
  // Patch for inverting tvd readout to fix issue #830,
392
335
  // should make proper fix when handling z increase direction - issue #842
@@ -398,7 +341,7 @@ export default class WellsLayer extends CompositeLayer {
398
341
  layer_properties.push(inverted_tvd_property);
399
342
  if (log_property)
400
343
  layer_properties.push(log_property);
401
- return Object.assign(Object.assign({}, info), { properties: layer_properties, logName: (log_property === null || log_property === void 0 ? void 0 : log_property.name) || "" });
344
+ return Object.assign(Object.assign({}, info), { properties: layer_properties, logName: log_property === null || log_property === void 0 ? void 0 : log_property.name, wellName: wellName });
402
345
  }
403
346
  }
404
347
  WellsLayer.layerName = "WellsLayer";
@@ -410,392 +353,27 @@ function onDataLoad(data, context) {
410
353
  context.layer.props.reportBoundingBox({ layerBoundingBox: bbox });
411
354
  }
412
355
  }
413
- function multiply(pair, factor) {
414
- return [pair[0] * factor, pair[1] * factor];
415
- }
416
- function getDashFactor(accessor, width_accessor, offset = 0) {
417
- return (object, objectInfo) => {
418
- let width = DEFAULT_LINE_WIDTH;
419
- if (typeof width_accessor == "function") {
420
- width = width_accessor(object);
421
- }
422
- else if (width_accessor) {
423
- width = width_accessor;
424
- }
356
+ // Create a dash accessor function that scales
357
+ function getDashFactor(accessor, widthAccessor, offset = 0) {
358
+ return (object, ctx) => {
359
+ var _a;
360
+ const dashValue = getFromAccessor(accessor, object, ctx);
361
+ const width = (_a = getFromAccessor(widthAccessor, object, ctx)) !== null && _a !== void 0 ? _a : DEFAULT_LINE_WIDTH;
425
362
  const factor = width / (width + offset);
426
- let dash = [0, 0];
427
- if (typeof accessor == "function") {
428
- dash = accessor(object, objectInfo);
363
+ let dashArray = [0, 0];
364
+ if (dashValue && Array.isArray(dashValue)) {
365
+ dashArray = dashValue;
429
366
  }
430
- else if (accessor)
431
- dash = accessor;
432
- else if (accessor)
433
- dash = DEFAULT_DASH;
434
- if (dash.length == 2) {
435
- return multiply(dash, factor);
436
- }
437
- else {
438
- return multiply(DEFAULT_DASH, factor);
367
+ else if (dashValue) {
368
+ dashArray = DEFAULT_DASH;
439
369
  }
370
+ return scaleArray(dashArray, factor);
440
371
  };
441
372
  }
442
373
  function dataIsReady(layerData) {
443
374
  // Deck.gl always shows prop.data as `[]` while external data is being loaded
444
375
  return !!layerData && !isEmpty(layerData);
445
376
  }
446
- function getColumn(data, col) {
447
- const column = [];
448
- for (let i = 0; i < data.length; i++) {
449
- column.push(data[i][col]);
450
- }
451
- return column;
452
- }
453
- function getLogMd(d, logrun_name) {
454
- if (!isSelectedLogRun(d, logrun_name))
455
- return [];
456
- const names_md = ["DEPTH", "DEPT", "MD", "TDEP", "MD_RKB"]; // aliases for MD
457
- const log_id = getLogIndexByNames(d, names_md);
458
- return log_id >= 0 ? getColumn(d.data, log_id) : [];
459
- }
460
- export function getLogValues(d, logrun_name, log_name) {
461
- if (!isSelectedLogRun(d, logrun_name))
462
- return [];
463
- const log_id = getLogIndexByName(d, log_name);
464
- return log_id >= 0 ? getColumn(d.data, log_id) : [];
465
- }
466
- export function getLogInfo(d, logrun_name, log_name) {
467
- if (!isSelectedLogRun(d, logrun_name))
468
- return undefined;
469
- const log_id = getLogIndexByName(d, log_name);
470
- return d.curves[log_id];
471
- }
472
- function getDiscreteLogMetadata(d, log_name) {
473
- return d === null || d === void 0 ? void 0 : d.metadata_discrete[log_name];
474
- }
475
- function isSelectedLogRun(d, logrun_name) {
476
- return d.header.name.toLowerCase() === logrun_name.toLowerCase();
477
- }
478
- function getWellObjectByName(wells_data, name) {
479
- return wells_data === null || wells_data === void 0 ? void 0 : wells_data.find((item) => { var _a, _b; return ((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === (name === null || name === void 0 ? void 0 : name.toLowerCase()); });
480
- }
481
- function getWellObjectsByName(wells_data, name) {
482
- const res = [];
483
- for (let i = 0; i < (name === null || name === void 0 ? void 0 : name.length); i++) {
484
- wells_data === null || wells_data === void 0 ? void 0 : wells_data.find((item) => {
485
- var _a, _b, _c;
486
- if (((_b = (_a = item.properties) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === ((_c = name[i]) === null || _c === void 0 ? void 0 : _c.toLowerCase()))
487
- res.push(item);
488
- });
489
- }
490
- return res;
491
- }
492
- function getPointGeometry(well_object) {
493
- const geometries = well_object.geometry.geometries;
494
- return geometries.find((item) => item.type === "Point");
495
- }
496
- // Return well head position from Point Geometry
497
- function getWellHeadPosition(well_object) {
498
- var _a, _b;
499
- return (_b = (_a = getPointGeometry(well_object)) === null || _a === void 0 ? void 0 : _a.coordinates) !== null && _b !== void 0 ? _b : [-1, -1, -1];
500
- }
501
- function getWellMds(well_object) {
502
- return well_object.properties.md[0];
503
- }
504
- function getNeighboringMdIndices(mds, md) {
505
- const idx = mds.findIndex((x) => x >= md);
506
- return idx === 0 ? [idx, idx + 1] : [idx - 1, idx];
507
- }
508
- function getPositionByMD(well_xyz, well_mds, md) {
509
- const [l_idx, h_idx] = getNeighboringMdIndices(well_mds, md);
510
- const md_low = well_mds[l_idx];
511
- const md_normalized = (md - md_low) / (well_mds[h_idx] - md_low);
512
- return interpolateNumberArray(well_xyz[l_idx], well_xyz[h_idx])(md_normalized);
513
- }
514
- function getLogPath(wells_data, d, logrun_name, trajectory_line_color) {
515
- const well_object = getWellObjectByName(wells_data, d.header.well);
516
- if (!well_object)
517
- return [];
518
- const well_xyz = getTrajectory(well_object, trajectory_line_color);
519
- const well_mds = getWellMds(well_object);
520
- if (well_xyz == undefined ||
521
- well_mds == undefined ||
522
- well_xyz.length == 0 ||
523
- well_mds.length == 0)
524
- return [];
525
- const log_xyz = [];
526
- const log_mds = getLogMd(d, logrun_name);
527
- log_mds.forEach((md) => {
528
- const xyz = getPositionByMD(well_xyz, well_mds, md);
529
- log_xyz.push(xyz);
530
- });
531
- return log_xyz;
532
- }
533
- function getLogIndexByName(d, log_name) {
534
- const name = log_name.toLowerCase();
535
- return d.curves.findIndex((item) => item.name.toLowerCase() === name);
536
- }
537
- function getLogIndexByNames(d, names) {
538
- for (const name of names) {
539
- const index = getLogIndexByName(d, name);
540
- if (index >= 0)
541
- return index;
542
- }
543
- return -1;
544
- }
545
- function getLogColor(d, logrun_name, log_name, logColor, colorTables, colorMappingFunction, isLog) {
546
- var _a;
547
- const log_data = getLogValues(d, logrun_name, log_name);
548
- const log_info = getLogInfo(d, logrun_name, log_name);
549
- if (log_data.length == 0 || log_info == undefined)
550
- return [];
551
- const log_color = [];
552
- if (log_info.description == "continuous") {
553
- const min = Math.min(...log_data);
554
- const max = Math.max(...log_data);
555
- const max_delta = max - min;
556
- log_data.forEach((value) => {
557
- const adjustedVal = (value - min) / max_delta;
558
- const rgb = colorMappingFunction
559
- ? colorMappingFunction(adjustedVal)
560
- : rgbValues(adjustedVal, logColor, colorTables, isLog);
561
- if (rgb) {
562
- log_color.push([rgb[0], rgb[1], rgb[2]]);
563
- }
564
- else {
565
- log_color.push([0, 0, 0, 0]); // push transparent for null/undefined log values
566
- }
567
- });
568
- }
569
- else {
570
- // well log data set for ex : H1: Array(2)0: (4) [255, 26, 202, 255] 1: 13
571
- const log_attributes = (_a = getDiscreteLogMetadata(d, log_name)) === null || _a === void 0 ? void 0 : _a.objects;
572
- const logLength = Object.keys(log_attributes).length;
573
- const attributesObject = {};
574
- const categorical = true;
575
- Object.keys(log_attributes).forEach((key) => {
576
- // get the point from log_attributes
577
- const point = log_attributes[key][1];
578
- const categoricalMin = 0;
579
- const categoricalMax = logLength - 1;
580
- let rgb;
581
- if (colorMappingFunction) {
582
- rgb = colorMappingFunction(point, categorical, categoricalMin, categoricalMax);
583
- }
584
- else {
585
- // if color-map function is not defined
586
- const arrayOfColors = getColors(logColor, colorTables, point);
587
- if (!arrayOfColors.length)
588
- console.error(`Empty or missed '${logColor}' color table`);
589
- else {
590
- rgb = arrayOfColors;
591
- }
592
- }
593
- if (rgb) {
594
- if (rgb.length === 3) {
595
- attributesObject[key] = [[rgb[0], rgb[1], rgb[2]], point];
596
- }
597
- else {
598
- // ? What is the point of this? Why do we offset the index in this case, isn't the fourth value the opacity?
599
- // (@anders2303)
600
- attributesObject[key] = [[rgb[1], rgb[2], rgb[3]], point];
601
- }
602
- }
603
- });
604
- log_data.forEach((log_value) => {
605
- var _a;
606
- const dl_attrs = (_a = Object.entries(attributesObject).find(([, value]) => value[1] == log_value)) === null || _a === void 0 ? void 0 : _a[1];
607
- if (dl_attrs)
608
- log_color.push(dl_attrs[0]);
609
- else
610
- log_color.push([0, 0, 0, 0]); // use transparent for undefined/null log values
611
- });
612
- }
613
- return log_color;
614
- }
615
- function getLogPath1(wells_data, d, selectedWell, selection, logrun_name, trajectory_line_color) {
616
- if (!selection || selectedWell !== d.header.well)
617
- return [];
618
- const well_object = getWellObjectByName(wells_data, d.header.well);
619
- if (!well_object)
620
- return [];
621
- const well_xyz = getTrajectory(well_object, trajectory_line_color);
622
- const well_mds = getWellMds(well_object);
623
- if (well_xyz == undefined ||
624
- well_mds == undefined ||
625
- well_xyz.length == 0 ||
626
- well_mds.length == 0)
627
- return [];
628
- const log_mds = getLogMd(d, logrun_name);
629
- if (!log_mds)
630
- return [];
631
- const log_xyz = [];
632
- let md0 = selection[0];
633
- if (md0 !== undefined) {
634
- let md1 = selection[1];
635
- if (md1 == md0)
636
- md1 = undefined;
637
- const mdFirst = well_mds[0];
638
- const mdLast = well_mds[well_mds.length - 1];
639
- if (md1 !== undefined) {
640
- if (md0 > md1) {
641
- const tmp = md0;
642
- md0 = md1;
643
- md1 = tmp;
644
- }
645
- }
646
- const delta = 2;
647
- if (md0 - delta > mdFirst) {
648
- let xyz = getPositionByMD(well_xyz, well_mds, md0 - delta);
649
- log_xyz.push(xyz);
650
- xyz = getPositionByMD(well_xyz, well_mds, md0);
651
- log_xyz.push(xyz);
652
- }
653
- if (md1 !== undefined) {
654
- const _md1 = md1;
655
- let index = 0;
656
- well_mds.forEach((md) => {
657
- if (md0 <= md && md <= _md1) {
658
- const xyz = well_xyz[index];
659
- log_xyz.push(xyz);
660
- }
661
- index++;
662
- });
663
- if (_md1 + delta < mdLast) {
664
- let xyz = getPositionByMD(well_xyz, well_mds, _md1);
665
- log_xyz.push(xyz);
666
- xyz = getPositionByMD(well_xyz, well_mds, _md1 + delta);
667
- log_xyz.push(xyz);
668
- }
669
- }
670
- }
671
- return log_xyz;
672
- }
673
- function getLogColor1(wells_data, d, selectedWell, selection, logrun_name) {
674
- if (!selection || selectedWell !== d.header.well)
675
- return [];
676
- const well_object = getWellObjectByName(wells_data, d.header.well);
677
- if (!well_object)
678
- return [];
679
- const well_mds = getWellMds(well_object);
680
- const log_mds = getLogMd(d, logrun_name);
681
- if (!log_mds || log_mds.length === 0)
682
- return [];
683
- const log_color = [];
684
- let md0 = selection[0];
685
- if (md0 !== undefined) {
686
- const mdFirst = well_mds[0];
687
- const mdLast = well_mds[well_mds.length - 1];
688
- let md1 = selection[1];
689
- if (md1 == md0)
690
- md1 = undefined;
691
- let swap = false;
692
- if (md1 !== undefined) {
693
- if (md0 > md1) {
694
- const tmp = md0;
695
- md0 = md1;
696
- md1 = tmp;
697
- swap = true;
698
- }
699
- }
700
- const delta = 2;
701
- if (md0 - delta > mdFirst)
702
- log_color.push(swap ? [0, 255, 0, 128] : [255, 0, 0, 128]);
703
- if (md1 !== undefined) {
704
- const _md1 = md1;
705
- log_color.push([128, 128, 128, 128]);
706
- well_mds.forEach((md) => {
707
- if (md0 <= md && md <= _md1) {
708
- log_color.push([128, 128, 128, 128]);
709
- }
710
- });
711
- if (_md1 + delta < mdLast)
712
- log_color.push(swap ? [255, 0, 0, 128] : [0, 255, 0, 128]);
713
- }
714
- }
715
- return log_color;
716
- }
717
- function getLogWidth(d, logrun_name, log_name) {
718
- return getLogValues(d, logrun_name, log_name);
719
- }
720
- function squared_distance(a, b) {
721
- const dx = a[0] - b[0];
722
- const dy = a[1] - b[1];
723
- return dx * dx + dy * dy;
724
- }
725
- // Return distance between line segment vw and point p
726
- function distToSegmentSquared(v, w, p) {
727
- const l2 = squared_distance(v, w);
728
- if (l2 == 0)
729
- return squared_distance(p, v);
730
- let t = ((p[0] - v[0]) * (w[0] - v[0]) + (p[1] - v[1]) * (w[1] - v[1])) / l2;
731
- t = Math.max(0, Math.min(1, t));
732
- return squared_distance(p, [
733
- v[0] + t * (w[0] - v[0]),
734
- v[1] + t * (w[1] - v[1]),
735
- ]);
736
- }
737
- function isPointAwayFromLineEnd(point, line) {
738
- const ab = subtract(line[1], line[0]);
739
- const cb = subtract(line[1], point);
740
- const dotProduct = dot(ab, cb);
741
- // If the dot product is negative, the point has moved past the end of the line
742
- return dotProduct < 0;
743
- }
744
- // Interpolates point closest to the coords on trajectory
745
- function interpolateDataOnTrajectory(coord, data, trajectory) {
746
- // if number of data points in less than 1 or
747
- // length of data and trajectory are different we cannot interpolate.
748
- if (data.length <= 1 || data.length != trajectory.length)
749
- return -1;
750
- // Identify closest well path leg to coord.
751
- const segment_index = getSegmentIndex(coord, trajectory);
752
- const index0 = segment_index;
753
- const index1 = index0 + 1;
754
- // Get the nearest data.
755
- const data0 = data[index0];
756
- const data1 = data[index1];
757
- // Get the nearest survey points.
758
- const survey0 = trajectory[index0];
759
- const survey1 = trajectory[index1];
760
- // To avoid interpolating longer than the actual wellbore path we ignore the coordinate if it's moved beyond the last line
761
- if (index1 === trajectory.length - 1 &&
762
- isPointAwayFromLineEnd(coord, [survey0, survey1])) {
763
- coord = survey1;
764
- }
765
- const dv = distance(survey0, survey1);
766
- if (dv === 0) {
767
- return -1;
768
- }
769
- // Calculate the scalar projection onto segment.
770
- const v0 = subtract(coord, survey0);
771
- const v1 = subtract(survey1, survey0);
772
- // scalar_projection in interval [0,1]
773
- const scalar_projection = dot(v0, v1) / (dv * dv);
774
- // Interpolate data.
775
- return data0 * (1.0 - scalar_projection) + data1 * scalar_projection;
776
- }
777
- function getMd(coord, feature, accessor) {
778
- var _a, _b;
779
- if (!((_b = (_a = feature.properties) === null || _a === void 0 ? void 0 : _a["md"]) === null || _b === void 0 ? void 0 : _b[0]) || !feature.geometry)
780
- return null;
781
- const measured_depths = feature.properties.md[0];
782
- const trajectory3D = getTrajectory(feature, accessor);
783
- if (trajectory3D == undefined)
784
- return null;
785
- let trajectory;
786
- // In 2D view coord is of type Point2D and in 3D view it is Point3D,
787
- // so use appropriate trajectory for interpolation
788
- if (coord.length == 2) {
789
- const trajectory2D = trajectory3D.map((v) => {
790
- return v.slice(0, 2);
791
- });
792
- trajectory = trajectory2D;
793
- }
794
- else {
795
- trajectory = trajectory3D;
796
- }
797
- return interpolateDataOnTrajectory(coord, measured_depths, trajectory);
798
- }
799
377
  function getMdProperty(coord, feature, accessor, featureType) {
800
378
  var _a, _b;
801
379
  if (featureType === "points") {
@@ -808,31 +386,6 @@ function getMdProperty(coord, feature, accessor, featureType) {
808
386
  }
809
387
  return null;
810
388
  }
811
- function getTvd(coord, feature, accessor) {
812
- var _a;
813
- const trajectory3D = getTrajectory(feature, accessor);
814
- // if trajectory is not found or if it has a data single point then get tvd from well head
815
- if (trajectory3D == undefined || (trajectory3D === null || trajectory3D === void 0 ? void 0 : trajectory3D.length) <= 1) {
816
- const wellhead_xyz = getWellHeadPosition(feature);
817
- return (_a = wellhead_xyz === null || wellhead_xyz === void 0 ? void 0 : wellhead_xyz[2]) !== null && _a !== void 0 ? _a : null;
818
- }
819
- let trajectory;
820
- // For 2D view coord is Point2D and for 3D view it is Point3D
821
- if (coord.length == 2) {
822
- const trajectory2D = trajectory3D === null || trajectory3D === void 0 ? void 0 : trajectory3D.map((v) => {
823
- return v.slice(0, 2);
824
- });
825
- trajectory = trajectory2D;
826
- }
827
- else {
828
- trajectory = trajectory3D;
829
- }
830
- const tvds = trajectory3D.map((v) => {
831
- return v[2];
832
- });
833
- // TVD goes downwards, so it's reversed
834
- return interpolateDataOnTrajectory(coord, tvds, trajectory);
835
- }
836
389
  function getTvdProperty(coord, feature, accessor, featureType) {
837
390
  var _a, _b;
838
391
  if (featureType === "points") {
@@ -845,80 +398,4 @@ function getTvdProperty(coord, feature, accessor, featureType) {
845
398
  }
846
399
  return null;
847
400
  }
848
- // Identify closest path leg to coord.
849
- function getSegmentIndex(coord, path) {
850
- let min_d = Number.MAX_VALUE;
851
- let segment_index = 0;
852
- for (let i = 0; i < (path === null || path === void 0 ? void 0 : path.length) - 1; i++) {
853
- const d = distToSegmentSquared(path[i], path[i + 1], coord);
854
- if (d > min_d)
855
- continue;
856
- segment_index = i;
857
- min_d = d;
858
- }
859
- return segment_index;
860
- }
861
- // Returns segment index of discrete logs
862
- function getLogSegmentIndex(coord, wells_data, log_data, logrun_name) {
863
- const trajectory = getLogPath(wells_data, log_data, logrun_name);
864
- return getSegmentIndex(coord, trajectory);
865
- }
866
- function getLogProperty(coord, wells_data, log_data, logrun_name, log_name) {
867
- var _a, _b, _c;
868
- if (!log_data.data)
869
- return null;
870
- const segment_index = getLogSegmentIndex(coord, wells_data, log_data, logrun_name);
871
- let log_value = getLogValues(log_data, logrun_name, log_name)[segment_index];
872
- let dl_attrs = undefined;
873
- const dl_metadata = (_a = getDiscreteLogMetadata(log_data, log_name)) === null || _a === void 0 ? void 0 : _a.objects;
874
- if (dl_metadata) {
875
- dl_attrs = Object.entries(dl_metadata).find(([, value]) => value[1] == log_value);
876
- }
877
- const log = (_b = getLogInfo(log_data, logrun_name, log_name)) === null || _b === void 0 ? void 0 : _b.name;
878
- const prop_name = log + " " + log_data.header.well;
879
- log_value = dl_attrs ? dl_attrs[0] + " (" + log_value + ")" : log_value;
880
- if (log_value) {
881
- const well_object = getWellObjectByName(wells_data, log_data.header.well);
882
- return createPropertyData(prop_name, log_value, (_c = well_object === null || well_object === void 0 ? void 0 : well_object.properties) === null || _c === void 0 ? void 0 : _c["color"]);
883
- }
884
- else
885
- return null;
886
- }
887
- // Return data required to build well layer legend
888
- function getLegendData(logs, wellName, logName, logColor) {
889
- if (!logs)
890
- return null;
891
- const log = wellName
892
- ? logs.find((log) => log.header.well == wellName)
893
- : logs[0];
894
- const logInfo = !log
895
- ? undefined
896
- : getLogInfo(log, log.header.name, logName);
897
- const title = "Wells / " + logName;
898
- if (log && (logInfo === null || logInfo === void 0 ? void 0 : logInfo.description) == "discrete") {
899
- const meta = log["metadata_discrete"];
900
- const metadataDiscrete = meta[logName].objects;
901
- return {
902
- title: title,
903
- colorName: logColor,
904
- discrete: true,
905
- metadata: metadataDiscrete,
906
- };
907
- }
908
- else {
909
- const minArray = [];
910
- const maxArray = [];
911
- logs.forEach(function (log) {
912
- const logValues = getLogValues(log, log.header.name, logName);
913
- minArray.push(Math.min(...logValues));
914
- maxArray.push(Math.max(...logValues));
915
- });
916
- return {
917
- title: title,
918
- colorName: logColor,
919
- discrete: false,
920
- valueRange: [Math.min(...minArray), Math.max(...maxArray)],
921
- };
922
- }
923
- }
924
401
  //# sourceMappingURL=wellsLayer.js.map