MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / render

Method render

examples/worker-rendering/main.ts:93–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

91 }
92
93 private render(): void {
94 const { ctx, canvas, frameTimes } = this;
95 const width = canvas.width;
96 const height = canvas.height;
97
98 // Clear canvas
99 ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
100 ctx.fillRect(0, 0, width, height);
101
102 if (frameTimes.length === 0) return;
103
104 // Draw 60fps target line
105 const targetY = height - (EXPECTED_FRAME_TIME_MS / this.maxFrameTime) * height;
106 ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)';
107 ctx.lineWidth = 1;
108 ctx.setLineDash([4, 4]);
109 ctx.beginPath();
110 ctx.moveTo(0, targetY);
111 ctx.lineTo(width, targetY);
112 ctx.stroke();
113 ctx.setLineDash([]);
114
115 // Draw bars
116 const barWidth = width / FRAME_BUFFER_SIZE;
117 const startIndex = Math.max(0, frameTimes.length - FRAME_BUFFER_SIZE);
118
119 for (let i = 0; i < frameTimes.length; i++) {
120 const frameTime = frameTimes[i];
121 const x = i * barWidth;
122 const barHeight = Math.min(1, frameTime / this.maxFrameTime) * height;
123 const y = height - barHeight;
124
125 // Color based on frame time
126 let color: string;
127 if (frameTime <= EXPECTED_FRAME_TIME_MS) {
128 color = '#10b981'; // Green - good
129 } else if (frameTime <= FRAME_TIME_SLOW_THRESHOLD) {
130 color = '#f59e0b'; // Orange - slow
131 } else {
132 color = '#ef4444'; // Red - dropped
133 }
134
135 ctx.fillStyle = color;
136 ctx.fillRect(x, y, barWidth - 1, barHeight);
137 }
138 }
139
140 clear(): void {
141 this.frameTimes = [];

Callers 2

addFrameMethod · 0.95
clearMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected