Home / File/ canvas.js — react Source File

canvas.js — react Source File

Architecture documentation for canvas.js, a javascript file in the react codebase. 5 imports, 2 dependents.

File javascript BabelCompiler Validation 5 imports 2 dependents 3 functions

Entity Profile

Dependency Diagram

graph LR
  2e686050_4065_de33_2d80_1361879d66c9["canvas.js"]
  c252378b_d680_96f7_afbe_5200374b78e8["index.js"]
  2e686050_4065_de33_2d80_1361879d66c9 --> c252378b_d680_96f7_afbe_5200374b78e8
  68d130b4_8767_c9b9_03b4_1510bf2fc934["utils.js"]
  2e686050_4065_de33_2d80_1361879d66c9 --> 68d130b4_8767_c9b9_03b4_1510bf2fc934
  0304bbc8_f110_6643_71c6_d26bddc58fde["types.js"]
  2e686050_4065_de33_2d80_1361879d66c9 --> 0304bbc8_f110_6643_71c6_d26bddc58fde
  e3778820_57ff_7221_e2fb_64072d11afcc["agent.js"]
  2e686050_4065_de33_2d80_1361879d66c9 --> e3778820_57ff_7221_e2fb_64072d11afcc
  80162ac2_4fc9_259b_04e9_4acc940af136["utils"]
  2e686050_4065_de33_2d80_1361879d66c9 --> 80162ac2_4fc9_259b_04e9_4acc940af136
  e3778820_57ff_7221_e2fb_64072d11afcc["agent.js"]
  e3778820_57ff_7221_e2fb_64072d11afcc --> 2e686050_4065_de33_2d80_1361879d66c9
  c252378b_d680_96f7_afbe_5200374b78e8["index.js"]
  c252378b_d680_96f7_afbe_5200374b78e8 --> 2e686050_4065_de33_2d80_1361879d66c9
  style 2e686050_4065_de33_2d80_1361879d66c9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import type {Data} from './index';
import type {Rect} from '../utils';
import type {HostInstance} from '../../types';
import type Agent from '../../agent';

import {isReactNativeEnvironment} from 'react-devtools-shared/src/backend/utils';

// Note these colors are in sync with DevTools Profiler chart colors.
const COLORS = [
  '#37afa9',
  '#63b19e',
  '#80b393',
  '#97b488',
  '#abb67d',
  '#beb771',
  '#cfb965',
  '#dfba57',
  '#efbb49',
  '#febc38',
];

let canvas: HTMLCanvasElement | null = null;

function drawNative(nodeToData: Map<HostInstance, Data>, agent: Agent) {
  const nodesToDraw = [];
  iterateNodes(nodeToData, ({color, node}) => {
    nodesToDraw.push({node, color});
  });

  agent.emit('drawTraceUpdates', nodesToDraw);

  const mergedNodes = groupAndSortNodes(nodeToData);
  agent.emit('drawGroupedTraceUpdatesWithNames', mergedNodes);
}

function drawWeb(nodeToData: Map<HostInstance, Data>) {
  if (canvas === null) {
    initialize();
  }

  const dpr = window.devicePixelRatio || 1;
  const canvasFlow: HTMLCanvasElement = ((canvas: any): HTMLCanvasElement);
  canvasFlow.width = window.innerWidth * dpr;
  canvasFlow.height = window.innerHeight * dpr;
  canvasFlow.style.width = `${window.innerWidth}px`;
  canvasFlow.style.height = `${window.innerHeight}px`;

  const context = canvasFlow.getContext('2d');
  context.scale(dpr, dpr);

  context.clearRect(0, 0, canvasFlow.width / dpr, canvasFlow.height / dpr);
// ... (194 more lines)

Domain

Subdomains

Frequently Asked Questions

What does canvas.js do?
canvas.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in canvas.js?
canvas.js defines 3 function(s): context, drawNative, drawWeb.
What does canvas.js depend on?
canvas.js imports 5 module(s): agent.js, index.js, types.js, utils, utils.js.
What files import canvas.js?
canvas.js is imported by 2 file(s): agent.js, index.js.
Where is canvas.js in the architecture?
canvas.js is located at packages/react-devtools-shared/src/backend/views/TraceUpdates/canvas.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/backend/views/TraceUpdates).

Analyze Your Own Codebase

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

Try Supermodel Free