SnapshotsView Class — react Architecture
Architecture documentation for the SnapshotsView class in SnapshotsView.js from the react codebase.
Entity Profile
Dependency Diagram
graph TD 53ee49ee_1c59_049a_1585_9d0b7405c7ba["SnapshotsView"] 98eec88b_1341_df00_8e0c_999433bb2208["SnapshotsView.js"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|defined in| 98eec88b_1341_df00_8e0c_999433bb2208 c5c7be07_3452_b313_0817_115eb1acde23["constructor()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| c5c7be07_3452_b313_0817_115eb1acde23 16c3aa87_ed53_4405_3b50_1edd51977907["desiredSize()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| 16c3aa87_ed53_4405_3b50_1edd51977907 7d59bffd_3586_541c_fcb8_a26c92f83b87["draw()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| 7d59bffd_3586_541c_fcb8_a26c92f83b87 91cff66c_68c1_8d93_b2a8_e06c198da52f["handleInteraction()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| 91cff66c_68c1_8d93_b2a8_e06c198da52f 1f3fed70_ceaf_f113_9ee8_ecbde2035ae4["_drawSnapshotImage()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| 1f3fed70_ceaf_f113_9ee8_ecbde2035ae4 e6d14fd9_d8b6_c776_8d7d_e47624233a92["_findClosestSnapshot()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| e6d14fd9_d8b6_c776_8d7d_e47624233a92 13dda668_30c8_1a8d_4549_5ef6566f141c["_updateHover()"] 53ee49ee_1c59_049a_1585_9d0b7405c7ba -->|method| 13dda668_30c8_1a8d_4549_5ef6566f141c
Relationship Graph
Source Code
packages/react-devtools-timeline/src/content-views/SnapshotsView.js lines 31–260
export class SnapshotsView extends View {
_hoverLocation: Point | null = null;
_intrinsicSize: Size;
_profilerData: TimelineData;
onHover: OnHover | null = null;
constructor(surface: Surface, frame: Rect, profilerData: TimelineData) {
super(surface, frame);
this._intrinsicSize = {
width: profilerData.duration,
height: profilerData.snapshotHeight,
};
this._profilerData = profilerData;
}
desiredSize(): Size {
return this._intrinsicSize;
}
draw(context: CanvasRenderingContext2D) {
const snapshotHeight = this._profilerData.snapshotHeight;
const {visibleArea} = this;
context.fillStyle = COLORS.BACKGROUND;
context.fillRect(
visibleArea.origin.x,
visibleArea.origin.y,
visibleArea.size.width,
visibleArea.size.height,
);
const y = visibleArea.origin.y;
let x = visibleArea.origin.x;
// Rather than drawing each snapshot where it occurred,
// draw them at fixed intervals and just show the nearest one.
while (x < visibleArea.origin.x + visibleArea.size.width) {
const snapshot = this._findClosestSnapshot(x);
if (snapshot === null) {
// This shold never happen.
break;
}
const scaledHeight = snapshotHeight;
const scaledWidth = (snapshot.width * snapshotHeight) / snapshot.height;
const imageRect: Rect = {
origin: {
x,
y,
},
size: {width: scaledWidth, height: scaledHeight},
};
// Lazily create and cache Image objects as we render a snapsho for the first time.
if (snapshot.image === null) {
const img = (snapshot.image = new Image());
img.onload = () => {
this._drawSnapshotImage(context, snapshot, imageRect);
};
img.src = snapshot.imageSource;
} else {
this._drawSnapshotImage(context, snapshot, imageRect);
}
x += scaledWidth + BORDER_SIZE;
}
const hoverLocation = this._hoverLocation;
if (hoverLocation !== null) {
const scrubberWidth = SNAPSHOT_SCRUBBER_SIZE + BORDER_SIZE * 2;
const scrubberOffset = scrubberWidth / 2;
context.fillStyle = COLORS.SCRUBBER_BORDER;
context.fillRect(
hoverLocation.x - scrubberOffset,
visibleArea.origin.y,
scrubberWidth,
Domain
Source
Frequently Asked Questions
What is the SnapshotsView class?
SnapshotsView is a class in the react codebase, defined in packages/react-devtools-timeline/src/content-views/SnapshotsView.js.
Where is SnapshotsView defined?
SnapshotsView is defined in packages/react-devtools-timeline/src/content-views/SnapshotsView.js at line 31.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free