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

Function drawMemGraph

packages/debug-plugin/src/graphs.js:105–150  ·  view source on GitHub ↗
(canvas, memHistory, historyIndex, peakEl)

Source from the content-addressed store, hash-verified

103 * @param {HTMLElement} peakEl - element to display peak value
104 */
105export function drawMemGraph(canvas, memHistory, historyIndex, peakEl) {
106 const g = prepareGraph(canvas);
107 if (g === null) {
108 return;
109 }
110 const { ctx, w, h, barW } = g;
111
112 let peak = 1;
113 for (let i = 0; i < GRAPH_SAMPLES; i++) {
114 if (memHistory[i] > peak) {
115 peak = memHistory[i];
116 }
117 }
118 peak = roundPeak(peak);
119 peakEl.textContent = `peak ${peak}MB`;
120
121 // filled area graph
122 ctx.fillStyle = "rgba(198,120,221,0.3)";
123 ctx.strokeStyle = "#c678dd";
124 ctx.lineWidth = 1;
125 ctx.beginPath();
126 ctx.moveTo(0, h);
127 for (let i = 0; i < GRAPH_SAMPLES; i++) {
128 const idx = (historyIndex + i) % GRAPH_SAMPLES;
129 const y = h - (memHistory[idx] / peak) * h;
130 const x = Math.round(i * barW);
131 ctx.lineTo(x, y);
132 }
133 ctx.lineTo(w, h);
134 ctx.closePath();
135 ctx.fill();
136
137 // stroke the top edge
138 ctx.beginPath();
139 for (let i = 0; i < GRAPH_SAMPLES; i++) {
140 const idx = (historyIndex + i) % GRAPH_SAMPLES;
141 const y = h - (memHistory[idx] / peak) * h;
142 const x = Math.round(i * barW);
143 if (i === 0) {
144 ctx.moveTo(x, y);
145 } else {
146 ctx.lineTo(x, y);
147 }
148 }
149 ctx.stroke();
150}

Callers 1

_updatePanelMethod · 0.90

Calls 8

prepareGraphFunction · 0.85
roundPeakFunction · 0.85
beginPathMethod · 0.45
moveToMethod · 0.45
lineToMethod · 0.45
closePathMethod · 0.45
fillMethod · 0.45
strokeMethod · 0.45

Tested by

no test coverage detected