Home / Class/ TimeAxisMarkersView Class — react Architecture

TimeAxisMarkersView Class — react Architecture

Architecture documentation for the TimeAxisMarkersView class in TimeAxisMarkersView.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  1d9e04c1_cd02_d73d_2be2_f11bb12df958["TimeAxisMarkersView"]
  349c9f88_b0e3_7db5_ca62_e5f635fd40f2["TimeAxisMarkersView.js"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958 -->|defined in| 349c9f88_b0e3_7db5_ca62_e5f635fd40f2
  9fb1faba_36c4_d0f6_1d71_cc41b0a2abd2["constructor()"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958 -->|method| 9fb1faba_36c4_d0f6_1d71_cc41b0a2abd2
  a6c15c49_080e_fcf3_7bcb_79d20e82c126["desiredSize()"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958 -->|method| a6c15c49_080e_fcf3_7bcb_79d20e82c126
  cc142f82_2d4d_5ccf_45f4_c01e5d19059f["_getTimeTickInterval()"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958 -->|method| cc142f82_2d4d_5ccf_45f4_c01e5d19059f
  8fb2b889_7666_0d3e_cc95_b3ddad42b164["draw()"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958 -->|method| 8fb2b889_7666_0d3e_cc95_b3ddad42b164

Relationship Graph

Source Code

packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js lines 39–163

export class TimeAxisMarkersView extends View {
  _totalDuration: number;
  _intrinsicSize: Size;

  constructor(surface: Surface, frame: Rect, totalDuration: number) {
    super(surface, frame);
    this._totalDuration = totalDuration;
    this._intrinsicSize = {
      width: this._totalDuration,
      height: HEADER_HEIGHT_FIXED,
    };
  }

  desiredSize(): Size {
    return this._intrinsicSize;
  }

  // Time mark intervals vary based on the current zoom range and the time it represents.
  // In Chrome, these seem to range from 70-140 pixels wide.
  // Time wise, they represent intervals of e.g. 1s, 500ms, 200ms, 100ms, 50ms, 20ms.
  // Based on zoom, we should determine which amount to actually show.
  _getTimeTickInterval(scaleFactor: number): number {
    for (let i = 0; i < INTERVAL_TIMES.length; i++) {
      const currentInterval = INTERVAL_TIMES[i];
      const intervalWidth = durationToWidth(currentInterval, scaleFactor);
      if (intervalWidth > MIN_INTERVAL_SIZE_PX) {
        return currentInterval;
      }
    }
    return INTERVAL_TIMES[0];
  }

  draw(context: CanvasRenderingContext2D) {
    const {frame, _intrinsicSize, visibleArea} = this;
    const clippedFrame = {
      origin: frame.origin,
      size: {
        width: frame.size.width,
        height: _intrinsicSize.height,
      },
    };
    const drawableRect = intersectionOfRects(clippedFrame, visibleArea);

    // Clear background
    context.fillStyle = COLORS.BACKGROUND;
    context.fillRect(
      drawableRect.origin.x,
      drawableRect.origin.y,
      drawableRect.size.width,
      drawableRect.size.height,
    );

    const scaleFactor = positioningScaleFactor(
      _intrinsicSize.width,
      clippedFrame,
    );
    const interval = this._getTimeTickInterval(scaleFactor);
    const firstIntervalTimestamp =
      Math.ceil(
        positionToTimestamp(
          drawableRect.origin.x - LABEL_FIXED_WIDTH,
          scaleFactor,
          clippedFrame,
        ) / interval,
      ) * interval;

    for (
      let markerTimestamp = firstIntervalTimestamp;
      true;
      markerTimestamp += interval
    ) {
      if (markerTimestamp <= 0) {
        continue; // Timestamps < are probably a bug; markers at 0 are ugly.
      }

      const x = timestampToPosition(markerTimestamp, scaleFactor, clippedFrame);
      if (x > drawableRect.origin.x + drawableRect.size.width) {
        break; // Not in view
      }

      const markerLabel = Math.round(markerTimestamp);

Domain

Frequently Asked Questions

What is the TimeAxisMarkersView class?
TimeAxisMarkersView is a class in the react codebase, defined in packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js.
Where is TimeAxisMarkersView defined?
TimeAxisMarkersView is defined in packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js at line 39.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free