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

Function parseNumberOrPercent

src/ChartGPU.ts:391–407  ·  view source on GitHub ↗
(value: number | string, basis: number)

Source from the content-addressed store, hash-verified

389type HitTestMatch = CartesianHitTestMatch | PieHitTestMatch | CandlestickHitTestMatch;
390
391const parseNumberOrPercent = (value: number | string, basis: number): number | null => {
392 if (typeof value === 'number') return Number.isFinite(value) ? value : null;
393 if (typeof value !== 'string') return null;
394
395 const s = value.trim();
396 if (s.length === 0) return null;
397
398 if (s.endsWith('%')) {
399 const pct = Number.parseFloat(s.slice(0, -1));
400 if (!Number.isFinite(pct)) return null;
401 return (pct / 100) * basis;
402 }
403
404 // Be permissive: allow numeric strings like "120" even though the public type primarily documents percent strings.
405 const n = Number.parseFloat(s);
406 return Number.isFinite(n) ? n : null;
407};
408
409const resolvePieCenterPlotCss = (
410 center: PieCenter | undefined,

Callers 2

resolvePieCenterPlotCssFunction · 0.70
resolvePieRadiiCssFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected