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

Function getMaxScatterRadiusCssPx

src/interaction/findNearestPoint.ts:110–149  ·  view source on GitHub ↗
(seriesCfg: ResolvedScatterSeriesConfig)

Source from the content-addressed store, hash-verified

108};
109
110const getMaxScatterRadiusCssPx = (seriesCfg: ResolvedScatterSeriesConfig): number => {
111 const cached = scatterMaxRadiusCache.get(seriesCfg);
112 if (cached !== undefined) return cached;
113
114 const data = seriesCfg.data;
115 const seriesSymbolSize = seriesCfg.symbolSize;
116
117 let maxRadius = 0;
118
119 // Fast path: numeric (or missing) series size means max is just max(point.size, series/default).
120 if (typeof seriesSymbolSize !== 'function') {
121 const seriesFallback =
122 typeof seriesSymbolSize === 'number' && Number.isFinite(seriesSymbolSize)
123 ? Math.max(0, seriesSymbolSize)
124 : DEFAULT_SCATTER_RADIUS_CSS_PX;
125
126 let maxPerPoint = 0;
127 let anyPointWithoutSize = false;
128 for (let i = 0; i < data.length; i++) {
129 const pSize = getPointSizeCssPx(data[i]);
130 if (pSize == null) {
131 anyPointWithoutSize = true;
132 } else {
133 const r = Math.max(0, pSize);
134 if (r > maxPerPoint) maxPerPoint = r;
135 }
136 }
137 maxRadius = anyPointWithoutSize ? Math.max(maxPerPoint, seriesFallback) : maxPerPoint;
138 } else {
139 // Slow path: symbolSize function can vary per point, so compute true max once and cache it.
140 for (let i = 0; i < data.length; i++) {
141 const r = getScatterRadiusCssPx(seriesCfg, data[i]);
142 if (r > maxRadius) maxRadius = r;
143 }
144 }
145
146 maxRadius = Number.isFinite(maxRadius) ? Math.max(0, maxRadius) : DEFAULT_SCATTER_RADIUS_CSS_PX;
147 scatterMaxRadiusCache.set(seriesCfg, maxRadius);
148 return maxRadius;
149};
150
151// Note: we intentionally do NOT compute “nearest bar by distance”.
152// Bars are only considered a match when the cursor is inside their rect bounds.

Callers 1

findNearestPointFunction · 0.85

Calls 2

getScatterRadiusCssPxFunction · 0.85
getPointSizeCssPxFunction · 0.70

Tested by

no test coverage detected