import { tickStep } from "../../d3-array/src/ticks.js";
import formatSpecifier from "../../d3-format/src/formatSpecifier.js";
import { format, formatPrefix } from "../../d3-format/src/defaultLocale.js";
import precisionFixed_default from "../../d3-format/src/precisionFixed.js";
import precisionPrefix_default from "../../d3-format/src/precisionPrefix.js";
import precisionRound_default from "../../d3-format/src/precisionRound.js";
function tickFormat(s, c, l, u) {
	var d = tickStep(s, c, l), f;
	switch (u = formatSpecifier(u ?? ",f"), u.type) {
		case "s":
			var p = Math.max(Math.abs(s), Math.abs(c));
			return u.precision == null && !isNaN(f = precisionPrefix_default(d, p)) && (u.precision = f), formatPrefix(u, p);
		case "":
		case "e":
		case "g":
		case "p":
		case "r":
			u.precision == null && !isNaN(f = precisionRound_default(d, Math.max(Math.abs(s), Math.abs(c)))) && (u.precision = f - (u.type === "e"));
			break;
		case "f":
		case "%":
			u.precision == null && !isNaN(f = precisionFixed_default(d)) && (u.precision = f - (u.type === "%") * 2);
			break;
	}
	return format(u);
}
export { tickFormat as default };
