Depth and Time Axis

In this WellLog Depth and Time tutorial, create two axes in WellLog Widget. One displays time and other displays depth.

# Create Depth and Time Axis

The following code shows how to create depth axis and related time axes based on DateTimeTickGenerator from WellLog, which uses LogDrillingSectionContainer. LogDrillingSectionContainer keeps relation between depth intervals and time intervals for each section. This object is used by tick genrator to generate adaptive time ticks and labels.

import { LogCurve } from "@int/geotoolkit/welllog/LogCurve.ts";
import { Plot } from "@int/geotoolkit/plot/Plot.ts";
import { TrackType } from "@int/geotoolkit/welllog/TrackType.ts";
import { HeaderType, LogAxisVisualHeader } from "@int/geotoolkit/welllog/header/LogAxisVisualHeader.ts";
import { LogData } from "@int/geotoolkit/welllog/data/LogData.ts";
import { TrackFactory } from "@int/geotoolkit/welllog/TrackFactory.ts";
import { BorderStrategy } from "@int/geotoolkit/welllog/BorderStrategy.ts";
import { LogAxis } from "@int/geotoolkit/welllog/LogAxis.ts";
import { DateTimeTickGenerator } from "@int/geotoolkit/welllog/axis/DateTimeTickGenerator.ts";
import { LogDrillingSectionContainer } from "@int/geotoolkit/welllog/data/LogDrillingSectionContainer.ts";
import { LogDrillingSection } from "@int/geotoolkit/welllog/data/LogDrillingSection.ts";
import { AlignmentStyle, BaseLineStyle } from "@int/geotoolkit/attributes/TextStyle.ts";
import { curveData } from "/src/code/WellLog/utils/curveData.ts";
import { createWellLogWidget } from "/src/code/WellLog/utils/common.ts";
function createCurve(from, step, curveMnemonic, color) {
  const values = curveData[curveMnemonic];
  const depths = values.map((v, i) => from + i * step);
  const data = new LogData(depths, values);
  return new LogCurve(data).setName(curveMnemonic).setLineStyle(color);
}
function createTime(fromDepth, toDepth, depthStep, fromTime, timeStep) {
  const depths = [];
  const time = [];
  let i = 0;
  for (let depth = fromDepth; depth < toDepth; depth += depthStep, i++) {
    depths[i] = depth;
    time[i] = fromTime + timeStep * i;
  }
  return { time, depths };
}
function prepareTimeIntervals(depthAndTime, majorDepth) {
  const container = new LogDrillingSectionContainer();
  const depths = depthAndTime.depths;
  const time = depthAndTime.time;
  let startDepth = depthAndTime.depths[0];
  let startTime = depthAndTime.time[0];
  let currentDepth = startDepth;
  let currentTime = startTime;
  for (let i = 0; i < depths.length; ++i) {
    currentDepth = depths[i];
    currentTime = time[i];
    if (currentDepth - startDepth >= majorDepth) {
      container.addSection(new LogDrillingSection(startDepth, currentDepth, {
        "break": false,
        "date": new Date(startTime)
      }, {
        "break": false,
        "date": new Date(currentTime)
      }, null));
      startTime = currentTime;
      startDepth = currentDepth;
    }
  }
  return container;
}
function createTimeAxis(widget, depthAndTime, majorDepthStep) {
  const track = TrackFactory.getInstance().createTrack(TrackType.AnnotationTrack, {
    "width": 50,
    "name": "Time",
    "indextype": "time",
    "borderstrategy": BorderStrategy.BorderOnTop,
    "border": {
      "color": "#DFE0E3",
      "visible": true
    }
  });
  const tickGenerator = new DateTimeTickGenerator({
    "dttrajectory": prepareTimeIntervals(depthAndTime, majorDepthStep),
    "major": {
      "labelstyle": {
        "color": "#9e9e9e",
        "baseline": BaseLineStyle.Middle,
        "alignment": AlignmentStyle.Center,
        "font": "12px Roboto"
      },
      "labelangle": -Math.PI / 2,
      "tickstyle": {
        "color": "#9e9e9e",
        "width": 3
      },
      "ticksize": 5
    },
    "sections": {
      "labelstyle": {
        "color": "#9e9e9e",
        "baseline": BaseLineStyle.Middle,
        "alignment": AlignmentStyle.Center,
        "font": "12px Roboto"
      },
      "labelangle": -Math.PI / 2,
      "tickstyle": {
        "color": "#9e9e9e",
        "width": 3
      },
      "ticksize": 5
    }
  });
  const axis = new LogAxis(tickGenerator);
  track.addChild(axis);
  const provider = widget.getHeaderContainer().getHeaderProvider();
  const header = new LogAxisVisualHeader(axis);
  header.setHeaderType(HeaderType.Custom);
  header.setDisplayString("Time");
  provider.registerHeader(axis, header);
  return track;
}
function createScene(canvas) {
  const twoHours = 2 * 60 * 60 * 1e3;
  const widget = createWellLogWidget().setAxisHeaderType(HeaderType.Simple).scale(0.5);
  const depthAndTime = createTime(4500, 1e4, 10, new Date(2010, 11, 17).valueOf(), twoHours);
  widget.addTrack(TrackType.IndexTrack);
  widget.addTrack(TrackType.LinearTrack).addChild(createCurve(4500, 10, "GR", "#7cb342"));
  widget.addTrack(createTimeAxis(widget, depthAndTime, 200));
  return new Plot({
    "canvaselement": canvas,
    "root": widget
  });
}
export { createScene };

createScene(document.querySelector('[ref="plot"]'));