import { f as e, r as t } from "./chunk-GEFDOKGD-bXEkwPrJ.js";
import { n, r } from "./src-hxErHTV1.js";
import { B as i, C as a, V as o, W as s, _ as c, a as l, b as u, c as d, d as f, v as p } from "./chunk-7R4GIKGN-DiZ1HYFd.js";
import { t as m } from "./ordinal-BKo-UFaW.js";
import { n as h } from "./path-Z-HG_8i_.js";
import { p as g } from "./math--xT1IZMK.js";
import { t as _ } from "./arc-DyfKNDOh.js";
import { t as v } from "./array-DPBIBG3p.js";
import { t as y } from "./chunk-HHEYEP7N-BdiTBCvb.js";
import { t as b } from "./chunk-4BX2VUAB-CL-dnlxR.js";
import { t as x } from "./mermaid-parser.core-Bd7Ghv5c.js";
//#region 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/d3-shape/src/identity.js
function C(e) {
	return e;
}
//#endregion
//#region node_modules/d3-shape/src/pie.js
function w() {
	var e = C, t = S, n = null, r = h(0), i = h(g), a = h(0);
	function o(o) {
		var s, c = (o = v(o)).length, l, u, d = 0, f = Array(c), p = Array(c), m = +r.apply(this, arguments), h = Math.min(g, Math.max(-g, i.apply(this, arguments) - m)), _, y = Math.min(Math.abs(h) / c, a.apply(this, arguments)), b = y * (h < 0 ? -1 : 1), x;
		for (s = 0; s < c; ++s) (x = p[f[s] = s] = +e(o[s], s, o)) > 0 && (d += x);
		for (t == null ? n != null && f.sort(function(e, t) {
			return n(o[e], o[t]);
		}) : f.sort(function(e, n) {
			return t(p[e], p[n]);
		}), s = 0, u = d ? (h - c * b) / d : 0; s < c; ++s, m = _) l = f[s], x = p[l], _ = m + (x > 0 ? x * u : 0) + b, p[l] = {
			data: o[l],
			index: s,
			value: x,
			startAngle: m,
			endAngle: _,
			padAngle: y
		};
		return p;
	}
	return o.value = function(t) {
		return arguments.length ? (e = typeof t == "function" ? t : h(+t), o) : e;
	}, o.sortValues = function(e) {
		return arguments.length ? (t = e, n = null, o) : t;
	}, o.sort = function(e) {
		return arguments.length ? (n = e, t = null, o) : n;
	}, o.startAngle = function(e) {
		return arguments.length ? (r = typeof e == "function" ? e : h(+e), o) : r;
	}, o.endAngle = function(e) {
		return arguments.length ? (i = typeof e == "function" ? e : h(+e), o) : i;
	}, o.padAngle = function(e) {
		return arguments.length ? (a = typeof e == "function" ? e : h(+e), o) : a;
	}, o;
}
//#endregion
//#region node_modules/mermaid/dist/chunks/mermaid.core/pieDiagram-SKSYHLDU.mjs
var T = f.pie, E = {
	sections: /* @__PURE__ */ new Map(),
	showData: !1,
	config: T
}, D = E.sections, O = E.showData, k = structuredClone(T), A = {
	getConfig: /* @__PURE__ */ n(() => structuredClone(k), "getConfig"),
	clear: /* @__PURE__ */ n(() => {
		D = /* @__PURE__ */ new Map(), O = E.showData, l();
	}, "clear"),
	setDiagramTitle: s,
	getDiagramTitle: a,
	setAccTitle: o,
	getAccTitle: p,
	setAccDescription: i,
	getAccDescription: c,
	addSection: /* @__PURE__ */ n(({ 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), r.debug(`added new section: ${e}, with value: ${t}`));
	}, "addSection"),
	getSections: /* @__PURE__ */ n(() => D, "getSections"),
	setShowData: /* @__PURE__ */ n((e) => {
		O = e;
	}, "setShowData"),
	getShowData: /* @__PURE__ */ n(() => O, "getShowData")
}, j = /* @__PURE__ */ n((e, t) => {
	b(e, t), t.setShowData(e.showData), e.sections.map(t.addSection);
}, "populateDb"), M = { parse: /* @__PURE__ */ n(async (e) => {
	let t = await x("pie", e);
	r.debug(t), j(t, A);
}, "parse") }, N = /* @__PURE__ */ n((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__ */ n((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).sort((e, t) => t.value - e.value);
	return w().value((e) => e.value)(n);
}, "createPieArcs"), F = {
	parser: M,
	db: A,
	renderer: { draw: /* @__PURE__ */ n((n, i, a, o) => {
		r.debug("rendering pie chart\n" + n);
		let s = o.db, c = u(), l = t(s.getConfig(), c.pie), f = y(i), p = f.append("g");
		p.attr("transform", "translate(225,225)");
		let { themeVariables: h } = c, [g] = e(h.pieOuterStrokeWidth);
		g ??= 2;
		let v = l.textPosition, b = _().innerRadius(0).outerRadius(185), x = _().innerRadius(185 * v).outerRadius(185 * v);
		p.append("circle").attr("cx", 0).attr("cy", 0).attr("r", 185 + g / 2).attr("class", "pieOuterCircle");
		let S = s.getSections(), C = P(S), w = [
			h.pie1,
			h.pie2,
			h.pie3,
			h.pie4,
			h.pie5,
			h.pie6,
			h.pie7,
			h.pie8,
			h.pie9,
			h.pie10,
			h.pie11,
			h.pie12
		], T = 0;
		S.forEach((e) => {
			T += e;
		});
		let E = C.filter((e) => (e.data.value / T * 100).toFixed(0) !== "0"), D = m(w);
		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"), p.append("text").text(s.getDiagramTitle()).attr("x", 0).attr("y", -400 / 2).attr("class", "pieTitleText");
		let O = [...S.entries()].map(([e, t]) => ({
			label: e,
			value: t
		})), k = p.selectAll(".legend").data(O).enter().append("g").attr("class", "legend").attr("transform", (e, t) => {
			let n = 22 * O.length / 2;
			return "translate(216," + (t * 22 - n) + ")";
		});
		k.append("rect").attr("width", 18).attr("height", 18).style("fill", (e) => D(e.label)).style("stroke", (e) => D(e.label)), k.append("text").attr("x", 22).attr("y", 14).text((e) => s.getShowData() ? `${e.label} [${e.value}]` : e.label);
		let A = 512 + Math.max(...k.selectAll("text").nodes().map((e) => e?.getBoundingClientRect().width ?? 0));
		f.attr("viewBox", `0 0 ${A} 450`), d(f, 450, A, l.useMaxWidth);
	}, "draw") },
	styles: N
};
//#endregion
export { F as diagram };

//# sourceMappingURL=pieDiagram-SKSYHLDU-BMrGgUAv.js.map