import { n as e } from "./path-1VDXycOe.js";
import { p as t } from "./math-CxsXa5xk.js";
import { t as n } from "./arc-C0R_jeiw.js";
import { t as r } from "./array-C9r3j2_Z.js";
import { f as i, r as a } from "./chunk-5PVQY5BW-De02jDY6.js";
import { n as o } from "./ordinal-BRozZu5j.js";
import { i as s, r as c } from "./src-CiYEh6Gu.js";
import "./chunk-K5T4RW27-CzBtr0Ks.js";
import "./chunk-7N4EOEYR-BbPw2hS_.js";
import "./chunk-67CJDMHE-PGSmTm_M.js";
import "./chunk-KGLVRYIC-CbMfGKJX.js";
import "./chunk-FOC6F5B3-DpuZaDQS.js";
import "./chunk-AA7GKIK3-CKwz6-T8.js";
import "./chunk-2KRD3SAO-DKnKXPSd.js";
import "./chunk-ORNJ4GCN-CKmTk0BP.js";
import "./chunk-LIHQZDEY-C7OIL7L5.js";
import "./chunk-CIAEETIT-O0r6nuB9.js";
import { B as l, C as u, V as d, W as f, _ as p, a as m, b as h, c as g, d as _, v } from "./chunk-ICPOFSXX-BGDNDwyb.js";
import { t as y } from "./chunk-426QAEUC-Bz08yDpF.js";
import "./dist-6KEP7Sv7.js";
import { t as b } from "./chunk-4BX2VUAB-YOQntefC.js";
import { t as x } from "./mermaid-parser.core-BHMInq3c.js";
//#region ../../node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/descending.js
function S(e, t) {
	return t < e ? -1 : t > e ? 1 : t >= e ? 0 : NaN;
}
//#endregion
//#region ../../node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/identity.js
function C(e) {
	return e;
}
//#endregion
//#region ../../node_modules/.pnpm/d3-shape@3.2.0/node_modules/d3-shape/src/pie.js
function w() {
	var n = C, i = S, a = null, o = e(0), s = e(t), c = e(0);
	function l(e) {
		var l, u = (e = r(e)).length, d, f, p = 0, m = Array(u), h = Array(u), g = +o.apply(this, arguments), _ = Math.min(t, Math.max(-t, s.apply(this, arguments) - g)), v, y = Math.min(Math.abs(_) / u, c.apply(this, arguments)), b = y * (_ < 0 ? -1 : 1), x;
		for (l = 0; l < u; ++l) (x = h[m[l] = l] = +n(e[l], l, e)) > 0 && (p += x);
		for (i == null ? a != null && m.sort(function(t, n) {
			return a(e[t], e[n]);
		}) : m.sort(function(e, t) {
			return i(h[e], h[t]);
		}), l = 0, f = p ? (_ - u * b) / p : 0; l < u; ++l, g = v) d = m[l], x = h[d], v = g + (x > 0 ? x * f : 0) + b, h[d] = {
			data: e[d],
			index: l,
			value: x,
			startAngle: g,
			endAngle: v,
			padAngle: y
		};
		return h;
	}
	return l.value = function(t) {
		return arguments.length ? (n = typeof t == "function" ? t : e(+t), l) : n;
	}, l.sortValues = function(e) {
		return arguments.length ? (i = e, a = null, l) : i;
	}, l.sort = function(e) {
		return arguments.length ? (a = e, i = null, l) : a;
	}, l.startAngle = function(t) {
		return arguments.length ? (o = typeof t == "function" ? t : e(+t), l) : o;
	}, l.endAngle = function(t) {
		return arguments.length ? (s = typeof t == "function" ? t : e(+t), l) : s;
	}, l.padAngle = function(t) {
		return arguments.length ? (c = typeof t == "function" ? t : e(+t), l) : c;
	}, l;
}
//#endregion
//#region ../../node_modules/.pnpm/mermaid@11.14.0/node_modules/mermaid/dist/chunks/mermaid.core/pieDiagram-DEJITSTG.mjs
var T = _.pie, E = {
	sections: /* @__PURE__ */ new Map(),
	showData: !1,
	config: T
}, D = E.sections, O = E.showData, k = structuredClone(T), A = {
	getConfig: /* @__PURE__ */ c(() => structuredClone(k), "getConfig"),
	clear: /* @__PURE__ */ c(() => {
		D = /* @__PURE__ */ new Map(), O = E.showData, m();
	}, "clear"),
	setDiagramTitle: f,
	getDiagramTitle: u,
	setAccTitle: d,
	getAccTitle: v,
	setAccDescription: l,
	getAccDescription: p,
	addSection: /* @__PURE__ */ c(({ label: e, value: t }) => {
		if (t < 0) throw Error(`"${e}" has invalid value: ${t}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);
		D.has(e) || (D.set(e, t), s.debug(`added new section: ${e}, with value: ${t}`));
	}, "addSection"),
	getSections: /* @__PURE__ */ c(() => D, "getSections"),
	setShowData: /* @__PURE__ */ c((e) => {
		O = e;
	}, "setShowData"),
	getShowData: /* @__PURE__ */ c(() => O, "getShowData")
}, j = /* @__PURE__ */ c((e, t) => {
	b(e, t), t.setShowData(e.showData), e.sections.map(t.addSection);
}, "populateDb"), M = { parse: /* @__PURE__ */ c(async (e) => {
	let t = await x("pie", e);
	s.debug(t), j(t, A);
}, "parse") }, N = /* @__PURE__ */ c((e) => `
  .pieCircle{
    stroke: ${e.pieStrokeColor};
    stroke-width : ${e.pieStrokeWidth};
    opacity : ${e.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${e.pieOuterStrokeColor};
    stroke-width: ${e.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${e.pieTitleTextSize};
    fill: ${e.pieTitleTextColor};
    font-family: ${e.fontFamily};
  }
  .slice {
    font-family: ${e.fontFamily};
    fill: ${e.pieSectionTextColor};
    font-size:${e.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${e.pieLegendTextColor};
    font-family: ${e.fontFamily};
    font-size: ${e.pieLegendTextSize};
  }
`, "getStyles"), P = /* @__PURE__ */ c((e) => {
	let t = [...e.values()].reduce((e, t) => e + t, 0), n = [...e.entries()].map(([e, t]) => ({
		label: e,
		value: t
	})).filter((e) => e.value / t * 100 >= 1);
	return w().value((e) => e.value).sort(null)(n);
}, "createPieArcs"), F = {
	parser: M,
	db: A,
	renderer: { draw: /* @__PURE__ */ c((e, t, r, c) => {
		s.debug("rendering pie chart\n" + e);
		let l = c.db, u = h(), d = a(l.getConfig(), u.pie), f = y(t), p = f.append("g");
		p.attr("transform", "translate(225,225)");
		let { themeVariables: m } = u, [_] = i(m.pieOuterStrokeWidth);
		_ ??= 2;
		let v = d.textPosition, b = n().innerRadius(0).outerRadius(185), x = n().innerRadius(185 * v).outerRadius(185 * v);
		p.append("circle").attr("cx", 0).attr("cy", 0).attr("r", 185 + _ / 2).attr("class", "pieOuterCircle");
		let S = l.getSections(), C = P(S), w = [
			m.pie1,
			m.pie2,
			m.pie3,
			m.pie4,
			m.pie5,
			m.pie6,
			m.pie7,
			m.pie8,
			m.pie9,
			m.pie10,
			m.pie11,
			m.pie12
		], T = 0;
		S.forEach((e) => {
			T += e;
		});
		let E = C.filter((e) => (e.data.value / T * 100).toFixed(0) !== "0"), D = o(w).domain([...S.keys()]);
		p.selectAll("mySlices").data(E).enter().append("path").attr("d", b).attr("fill", (e) => D(e.data.label)).attr("class", "pieCircle"), p.selectAll("mySlices").data(E).enter().append("text").text((e) => (e.data.value / T * 100).toFixed(0) + "%").attr("transform", (e) => "translate(" + x.centroid(e) + ")").style("text-anchor", "middle").attr("class", "slice");
		let O = p.append("text").text(l.getDiagramTitle()).attr("x", 0).attr("y", -400 / 2).attr("class", "pieTitleText"), k = [...S.entries()].map(([e, t]) => ({
			label: e,
			value: t
		})), A = p.selectAll(".legend").data(k).enter().append("g").attr("class", "legend").attr("transform", (e, t) => {
			let n = 22 * k.length / 2;
			return "translate(216," + (t * 22 - n) + ")";
		});
		A.append("rect").attr("width", 18).attr("height", 18).style("fill", (e) => D(e.label)).style("stroke", (e) => D(e.label)), A.append("text").attr("x", 22).attr("y", 14).text((e) => l.getShowData() ? `${e.label} [${e.value}]` : e.label);
		let j = 512 + Math.max(...A.selectAll("text").nodes().map((e) => e?.getBoundingClientRect().width ?? 0)), M = O.node()?.getBoundingClientRect().width ?? 0, N = 450 / 2 - M / 2, F = 450 / 2 + M / 2, I = Math.min(0, N), L = Math.max(j, F) - I;
		f.attr("viewBox", `${I} 0 ${L} 450`), g(f, 450, L, d.useMaxWidth);
	}, "draw") },
	styles: N
};
//#endregion
export { F as diagram };
