MCPcopy Create free account
hub / github.com/melonjs/melonJS / prepareGraph

Function prepareGraph

packages/debug-plugin/src/graphs.js:11–23  ·  view source on GitHub ↗

* Resize a canvas backing store to match its CSS layout width, clear it, * and return a draw context. Returns `null` if the canvas has no layout * width yet (e.g. panel hidden, first frame). * @param {HTMLCanvasElement} canvas * @returns {{ ctx: CanvasRenderingContext2D, w: number, h: number, ba

(canvas)

Source from the content-addressed store, hash-verified

9 * @returns {{ ctx: CanvasRenderingContext2D, w: number, h: number, barW: number } | null}
10 */
11function prepareGraph(canvas) {
12 const w = canvas.clientWidth;
13 if (w === 0) {
14 return null;
15 }
16 if (canvas.width !== w) {
17 canvas.width = w;
18 }
19 const ctx = canvas.getContext("2d");
20 const h = GRAPH_HEIGHT;
21 ctx.clearRect(0, 0, w, h);
22 return { ctx, w, h, barW: w / GRAPH_SAMPLES };
23}
24
25/**
26 * Round a peak value up to the nearest multiple of 4, with a floor of 4.

Callers 2

drawFrameGraphFunction · 0.85
drawMemGraphFunction · 0.85

Calls 2

getContextMethod · 0.45
clearRectMethod · 0.45

Tested by

no test coverage detected