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

Function prepare

src/renderers/createPieRenderer.ts:236–379  ·  view source on GitHub ↗
(seriesConfig, gridArea)

Source from the content-addressed store, hash-verified

234 };
235
236 const prepare: PieRenderer['prepare'] = (seriesConfig, gridArea) => {
237 assertNotDisposed();
238
239 const dprRaw = gridArea.devicePixelRatio;
240 const dpr = dprRaw > 0 && Number.isFinite(dprRaw) ? dprRaw : 1;
241
242 lastCanvasWidth = gridArea.canvasWidth;
243 lastCanvasHeight = gridArea.canvasHeight;
244 writeVsUniforms(gridArea.canvasWidth, gridArea.canvasHeight);
245 lastScissor = computePlotScissorDevicePx(gridArea);
246
247 const canvasCssWidth = gridArea.canvasWidth / dpr;
248 const canvasCssHeight = gridArea.canvasHeight / dpr;
249 if (!(canvasCssWidth > 0) || !(canvasCssHeight > 0)) {
250 instanceCount = 0;
251 return;
252 }
253
254 const plotWidthCss = canvasCssWidth - gridArea.left - gridArea.right;
255 const plotHeightCss = canvasCssHeight - gridArea.top - gridArea.bottom;
256 if (!(plotWidthCss > 0) || !(plotHeightCss > 0)) {
257 instanceCount = 0;
258 return;
259 }
260
261 const maxRadiusCss = 0.5 * Math.min(plotWidthCss, plotHeightCss);
262 if (!(maxRadiusCss > 0)) {
263 instanceCount = 0;
264 return;
265 }
266
267 // Center specified in plot-local CSS px (or %), then shifted by GridArea CSS margins.
268 const centerPlotCss = resolveCenterPlotCss(seriesConfig.center, plotWidthCss, plotHeightCss);
269 const centerCanvasCssX = gridArea.left + centerPlotCss.x;
270 const centerCanvasCssY = gridArea.top + centerPlotCss.y;
271
272 // Instance center is in clip space; VS transform is identity.
273 const centerClipX = (centerCanvasCssX / canvasCssWidth) * 2 - 1;
274 const centerClipY = 1 - (centerCanvasCssY / canvasCssHeight) * 2;
275 if (!Number.isFinite(centerClipX) || !Number.isFinite(centerClipY)) {
276 instanceCount = 0;
277 return;
278 }
279
280 // Radii specified in CSS px (or % of max radius), converted to device px for the shader.
281 const radiiCss = resolveRadiiCss(seriesConfig.radius, maxRadiusCss);
282 const innerCss = Math.max(0, Math.min(radiiCss.inner, radiiCss.outer));
283 const outerCss = Math.max(innerCss, radiiCss.outer);
284 const innerPx = innerCss * dpr;
285 const outerPx = outerCss * dpr;
286 if (!(outerPx > 0)) {
287 instanceCount = 0;
288 return;
289 }
290
291 // Total positive value for angle allocation.
292 let total = 0;
293 let validCount = 0;

Callers

nothing calls this directly

Calls 10

resolveCenterPlotCssFunction · 0.85
resolveRadiiCssFunction · 0.85
parseColorFunction · 0.85
assertNotDisposedFunction · 0.70
writeVsUniformsFunction · 0.70
wrapToTauFunction · 0.70
nextPow2Function · 0.70
destroyMethod · 0.45

Tested by

no test coverage detected