//#region src/charts/utils.ts
function e(e, t) {
	let [n, r] = e, [i, a] = t, o = r - n, s = a - i;
	return (e) => o === 0 ? i : i + (e - n) / o * s;
}
function t(e, t, n = 0) {
	let [r, i] = t, a = e.length, o = i - r, s = a > 0 ? n * (a + 1) : 0, c = a > 0 ? (o - s) / a : 0, l = Math.max(0, c), u = /* @__PURE__ */ new Map();
	for (let t = 0; t < e.length; t++) {
		let i = e[t];
		i !== void 0 && u.set(i, r + n + t * (l + n));
	}
	let d = ((e) => u.get(e) ?? r);
	return d.bandwidth = () => l, d.domain = () => [...e], d;
}
function n() {
	return [
		"#3b82f6",
		"#ef4444",
		"#22c55e",
		"#f59e0b",
		"#8b5cf6",
		"#06b6d4",
		"#ec4899",
		"#f97316",
		"#14b8a6",
		"#a855f7",
		"#84cc16",
		"#6366f1"
	];
}
function r(e, t) {
	let n = e.replace("#", ""), r = parseInt(n.substring(0, 2), 16), i = parseInt(n.substring(2, 4), 16), a = parseInt(n.substring(4, 6), 16);
	return `rgba(${String(r)}, ${String(i)}, ${String(a)}, ${String(t)})`;
}
function i(e, t, n) {
	return Math.min(Math.max(e, t), n);
}
function a(e) {
	let t = Math.abs(e);
	return t >= 1e9 ? `${(e / 1e9).toFixed(1)}B` : t >= 1e6 ? `${(e / 1e6).toFixed(1)}M` : t >= 1e3 ? `${(e / 1e3).toFixed(1)}K` : String(Number(e.toFixed(2)));
}
function o(e, t, n) {
	if (e === t) return {
		min: e - 1,
		max: t + 1,
		step: 1
	};
	let r = (t - e) / Math.max(1, n - 1), i = 10 ** Math.floor(Math.log10(r)), a = r / i, o;
	return o = a <= 1 ? 1 * i : a <= 2 ? 2 * i : a <= 5 ? 5 * i : 10 * i, {
		min: Math.floor(e / o) * o,
		max: Math.ceil(t / o) * o,
		step: o
	};
}
function s(e) {
	let t = e.replace("#", "");
	return [
		parseInt(t.substring(0, 2), 16),
		parseInt(t.substring(2, 4), 16),
		parseInt(t.substring(4, 6), 16)
	];
}
function c(e, t, n) {
	let [r, i, a] = s(e), [o, c, l] = s(t), u = Math.round(r + (o - r) * n), d = Math.round(i + (c - i) * n), f = Math.round(a + (l - a) * n), p = (e) => e.toString(16).padStart(2, "0");
	return `#${p(u)}${p(d)}${p(f)}`;
}
function l(e, t, n, r) {
	let i = (r - 90) * Math.PI / 180;
	return {
		x: e + n * Math.cos(i),
		y: t + n * Math.sin(i)
	};
}
function u(e, t, n, r, i, a) {
	let o = Math.min(a, r / 2, i / 2);
	e.beginPath(), e.moveTo(t + o, n), e.lineTo(t + r - o, n), e.quadraticCurveTo(t + r, n, t + r, n + o), e.lineTo(t + r, n + i - o), e.quadraticCurveTo(t + r, n + i, t + r - o, n + i), e.lineTo(t + o, n + i), e.quadraticCurveTo(t, n + i, t, n + i - o), e.lineTo(t, n + o), e.quadraticCurveTo(t, n, t + o, n), e.closePath();
}
function d(e, t, r) {
	if (t !== void 0 && t.length > 0) return t[e % t.length] ?? r ?? "#3b82f6";
	let i = n();
	return i[e % i.length] ?? r ?? "#3b82f6";
}
function f(e, t, n, i, a, o, s, c = !1) {
	e.beginPath();
	let l = Math.min(o, i / 2, a / 2);
	l > 0 ? (e.moveTo(t + l, n), e.lineTo(t + i - l, n), e.arcTo(t + i, n, t + i, n + l, l), e.lineTo(t + i, n + a - l), e.arcTo(t + i, n + a, t + i - l, n + a, l), e.lineTo(t + l, n + a), e.arcTo(t, n + a, t, n + a - l, l), e.lineTo(t, n + l), e.arcTo(t, n, t + l, n, l)) : e.rect(t, n, i, a), e.closePath(), e.fillStyle = c ? r(s, .75) : s, e.fill();
}
function p(e, t, n) {
	return e >= n.x && e <= n.x + n.width && t >= n.y && t <= n.y + n.height;
}
function m(e, t, n, r) {
	let i = null, a = Infinity;
	for (let r of n) {
		let n = Math.sqrt((e - r.px) ** 2 + (t - r.py) ** 2);
		n < a && (a = n, i = r);
	}
	return i !== null && a < r ? {
		point: i,
		dist: a
	} : null;
}
function h(e, t, n = .5) {
	for (let r = 0; r < t.length - 1; r++) {
		let i = t[Math.max(0, r - 1)], a = t[r], o = t[r + 1], s = t[Math.min(t.length - 1, r + 2)];
		if (i === void 0 || a === void 0 || o === void 0 || s === void 0) continue;
		let c = a.px + (o.px - i.px) * n / 3, l = a.py + (o.py - i.py) * n / 3, u = o.px - (s.px - a.px) * n / 3, d = o.py - (s.py - a.py) * n / 3;
		e.bezierCurveTo(c, l, u, d, o.px, o.py);
	}
}
//#endregion
export { i as clamp, n as defaultColors, f as drawFilledBar, h as drawSmoothPath, m as findClosestPoint, a as formatNumber, r as hexToRgba, p as hitTestRect, c as lerpColor, o as niceScale, l as polarToCartesian, d as resolveColor, u as roundRect, t as scaleBand, e as scaleLinear };

//# sourceMappingURL=utils.js.map