clamp
Constrains a number to the range from min to max, inclusive.
Basic example
Section titled “Basic example”Values inside the range come back unchanged, and values past either end come back as that end. Charts use it to keep font sizes, radii, and pixel positions within their bounds.
import {clamp} from "@d3plus/math";
clamp(5, 0, 10);
clamp(-3, 0, 10);
clamp(42, 0, 10);
clamp(0.25, 0, 1);
Parameters
import {clamp} from "@d3plus/math";