Home / Function/ draw() — react Function Reference

draw() — react Function Reference

Architecture documentation for the draw() function in TimeAxisMarkersView.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  8fb2b889_7666_0d3e_cc95_b3ddad42b164["draw()"]
  1d9e04c1_cd02_d73d_2be2_f11bb12df958["TimeAxisMarkersView"]
  8fb2b889_7666_0d3e_cc95_b3ddad42b164 -->|defined in| 1d9e04c1_cd02_d73d_2be2_f11bb12df958
  cc142f82_2d4d_5ccf_45f4_c01e5d19059f["_getTimeTickInterval()"]
  8fb2b889_7666_0d3e_cc95_b3ddad42b164 -->|calls| cc142f82_2d4d_5ccf_45f4_c01e5d19059f
  6fe722ba_3051_6ecf_abe3_62a190c3ad25["positioningScaleFactor()"]
  8fb2b889_7666_0d3e_cc95_b3ddad42b164 -->|calls| 6fe722ba_3051_6ecf_abe3_62a190c3ad25
  a1e0fb75_d73e_2a52_2e38_23e1f70979f8["positionToTimestamp()"]
  8fb2b889_7666_0d3e_cc95_b3ddad42b164 -->|calls| a1e0fb75_d73e_2a52_2e38_23e1f70979f8
  83465e3e_5308_9ddc_a12b_a84d78f1c10a["timestampToPosition()"]
  8fb2b889_7666_0d3e_cc95_b3ddad42b164 -->|calls| 83465e3e_5308_9ddc_a12b_a84d78f1c10a
  style 8fb2b889_7666_0d3e_cc95_b3ddad42b164 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js lines 71–162

  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);

      context.fillStyle = COLORS.PRIORITY_BORDER;
      context.fillRect(
        x,
        drawableRect.origin.y + MARKER_HEIGHT - MARKER_TICK_HEIGHT,
        BORDER_SIZE,
        MARKER_TICK_HEIGHT,
      );

      context.fillStyle = COLORS.TIME_MARKER_LABEL;
      context.textAlign = 'right';
      context.textBaseline = 'middle';
      context.font = `${FONT_SIZE}px sans-serif`;
      context.fillText(
        `${markerLabel}ms`,
        x - MARKER_TEXT_PADDING,
        MARKER_HEIGHT / 2,
      );
    }

    // Render bottom border.
    // Propose border rect, check if intersects with `rect`, draw intersection.
    const borderFrame: Rect = {
      origin: {
        x: clippedFrame.origin.x,
        y: clippedFrame.origin.y + clippedFrame.size.height - BORDER_SIZE,
      },
      size: {
        width: clippedFrame.size.width,
        height: BORDER_SIZE,
      },
    };

Domain

Subdomains

Frequently Asked Questions

What does draw() do?
draw() is a function in the react codebase, defined in packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js.
Where is draw() defined?
draw() is defined in packages/react-devtools-timeline/src/content-views/TimeAxisMarkersView.js at line 71.
What does draw() call?
draw() calls 4 function(s): _getTimeTickInterval, positionToTimestamp, positioningScaleFactor, timestampToPosition.

Analyze Your Own Codebase

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

Try Supermodel Free