Home / Function/ draw() — react Function Reference

draw() — react Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a2777e3e_5de8_64fd_2831_e7d1431e9806["draw()"]
  1c41caa2_9be5_5d0b_7a2d_ee4e7e896fab["FlamechartStackLayerView"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|defined in| 1c41caa2_9be5_5d0b_7a2d_ee4e7e896fab
  6fe722ba_3051_6ecf_abe3_62a190c3ad25["positioningScaleFactor()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 6fe722ba_3051_6ecf_abe3_62a190c3ad25
  6743acc7_a552_31bd_d8df_67b4ec27ba6d["durationToWidth()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 6743acc7_a552_31bd_d8df_67b4ec27ba6d
  83465e3e_5308_9ddc_a12b_a84d78f1c10a["timestampToPosition()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 83465e3e_5308_9ddc_a12b_a84d78f1c10a
  4b8ff33d_f91f_6a04_31db_7d18423189ad["isInternalModule()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 4b8ff33d_f91f_6a04_31db_7d18423189ad
  6b09eb7a_abf1_f1ac_4ba4_390e5df5a286["hoverColorForStackFrame()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 6b09eb7a_abf1_f1ac_4ba4_390e5df5a286
  27ff608f_2e99_f3c6_cd4b_807b59dd9c00["defaultColorForStackFrame()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 27ff608f_2e99_f3c6_cd4b_807b59dd9c00
  1d4e7b93_85d0_def6_42c9_e20824e49731["drawText()"]
  a2777e3e_5de8_64fd_2831_e7d1431e9806 -->|calls| 1d4e7b93_85d0_def6_42c9_e20824e49731
  style a2777e3e_5de8_64fd_2831_e7d1431e9806 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-timeline/src/content-views/FlamechartView.js lines 128–217

  draw(context: CanvasRenderingContext2D) {
    const {
      frame,
      _stackLayer,
      _hoveredStackFrame,
      _intrinsicSize,
      visibleArea,
    } = this;

    context.fillStyle = COLORS.PRIORITY_BACKGROUND;
    context.fillRect(
      visibleArea.origin.x,
      visibleArea.origin.y,
      visibleArea.size.width,
      visibleArea.size.height,
    );

    const scaleFactor = positioningScaleFactor(_intrinsicSize.width, frame);

    for (let i = 0; i < _stackLayer.length; i++) {
      const stackFrame = _stackLayer[i];
      const {name, timestamp, duration} = stackFrame;

      const width = durationToWidth(duration, scaleFactor);
      if (width < 1) {
        continue; // Too small to render at this zoom level
      }

      const x = Math.floor(timestampToPosition(timestamp, scaleFactor, frame));
      const nodeRect: Rect = {
        origin: {x, y: frame.origin.y},
        size: {
          width: Math.floor(width - BORDER_SIZE),
          height: Math.floor(FLAMECHART_FRAME_HEIGHT - BORDER_SIZE),
        },
      };
      if (!rectIntersectsRect(nodeRect, visibleArea)) {
        continue; // Not in view
      }

      const showHoverHighlight = _hoveredStackFrame === _stackLayer[i];

      let textFillStyle;
      if (isInternalModule(this._internalModuleSourceToRanges, stackFrame)) {
        context.fillStyle = showHoverHighlight
          ? COLORS.INTERNAL_MODULE_FRAME_HOVER
          : COLORS.INTERNAL_MODULE_FRAME;
        textFillStyle = COLORS.INTERNAL_MODULE_FRAME_TEXT;
      } else {
        context.fillStyle = showHoverHighlight
          ? hoverColorForStackFrame(stackFrame)
          : defaultColorForStackFrame(stackFrame);
        textFillStyle = COLORS.TEXT_COLOR;
      }

      const drawableRect = intersectionOfRects(nodeRect, visibleArea);
      context.fillRect(
        drawableRect.origin.x,
        drawableRect.origin.y,
        drawableRect.size.width,
        drawableRect.size.height,
      );

      drawText(name, context, nodeRect, drawableRect, {
        fillStyle: textFillStyle,
      });
    }

    // Render bottom border.
    const borderFrame: Rect = {
      origin: {
        x: frame.origin.x,
        y: frame.origin.y + FLAMECHART_FRAME_HEIGHT - BORDER_SIZE,
      },
      size: {
        width: frame.size.width,
        height: BORDER_SIZE,
      },
    };
    if (rectIntersectsRect(borderFrame, visibleArea)) {
      const borderDrawableRect = intersectionOfRects(borderFrame, visibleArea);

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/FlamechartView.js.
Where is draw() defined?
draw() is defined in packages/react-devtools-timeline/src/content-views/FlamechartView.js at line 128.
What does draw() call?
draw() calls 7 function(s): defaultColorForStackFrame, drawText, durationToWidth, hoverColorForStackFrame, isInternalModule, positioningScaleFactor, timestampToPosition.

Analyze Your Own Codebase

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

Try Supermodel Free