calculateMarkerRadius function
The radius of one marker, in logical pixels.
Ports calculateMarkerRadius (utilities.ts:2317-2360).
The cross-plan contract homes getScatterXDomainExtent and
getDomainPaddingForMarkers in axis/domain_range.dart but leaves this
function and getRangeForScatterMarkerSize unowned; ScatterChart, LineChart
and PolarChart all call both, so they live here rather than being written
three times.
pointMarkerSize is deliberately nullable AND checked for zero, because
upstream's if (!pointMarkerSize) (utilities.ts:2342) treats 0 as
absent.
Implementation
double calculateMarkerRadius({
double? pointMarkerSize,
required double minMarkerSize,
required double maxMarkerSize,
required double extraMaxPixels,
required bool isContinuousXY,
bool isActive = false,
// 3.5 and 5.5 are the destructured defaults at `utilities.ts:2324-2325`.
double defaultRadius = 3.5,
double activeRadius = 5.5,
// The visibility floor at `utilities.ts:2326`.
double minRadius = 4,
}) {
// parity: utilities.ts:2342 — JS falsiness means 0 and undefined behave alike.
if (pointMarkerSize == null || pointMarkerSize == 0) {
return isActive ? activeRadius : defaultRadius;
}
final double radius;
if (isContinuousXY && maxMarkerSize != 0) {
// utilities.ts:2349 — a marker table that already fits the pixel budget is
// used as written; otherwise the whole table is scaled down to fit.
radius = maxMarkerSize < extraMaxPixels
? pointMarkerSize
: (pointMarkerSize / maxMarkerSize) * extraMaxPixels;
} else if (!isContinuousXY && maxMarkerSize != minMarkerSize) {
// utilities.ts:2352 — a band scale has no spare domain to measure, so the
// sizes are normalised into a fixed pixel range instead.
radius =
kMarkerMinPixel +
((pointMarkerSize - minMarkerSize) / (maxMarkerSize - minMarkerSize)) *
(kMarkerMaxPixel - kMarkerMinPixel);
} else {
// utilities.ts:2353-2356.
return isActive ? activeRadius : defaultRadius;
}
// utilities.ts:2359. `math.max` rather than a comparison so that a NaN radius
// propagates exactly as `Math.max` lets it.
return math.max(radius, minRadius);
}