import { __name as e, log as t } from "./chunk-AGHRB4JF.js";
import { clear as n, configureSvgSize as r, defaultConfig_default as i, getAccDescription as a, getAccTitle as o, getConfig2 as s, getDiagramTitle as c, setAccDescription as l, setAccTitle as u, setDiagramTitle as d } from "./chunk-ICPOFSXX.js";
import f from "../../../../d3-scale/src/ordinal.js";
import p from "../../../../d3-shape/src/arc.js";
import m from "../../../../d3-shape/src/pie.js";
import "../../../../d3/src/index.js";
import { selectSvgElement as h } from "./chunk-426QAEUC.js";
import { cleanAndMerge as g, parseFontSize as _ } from "./chunk-5PVQY5BW.js";
import { populateCommonDb as v } from "./chunk-4BX2VUAB.js";
import { parse as y } from "../../../../@mermaid-js/parser/dist/mermaid-parser.core.js";
//#region ../../node_modules/mermaid/dist/chunks/mermaid.core/pieDiagram-DEJITSTG.mjs
var b = i.pie, x = {
	sections: /* @__PURE__ */ new Map(),
	showData: !1,
	config: b
}, S = x.sections, C = x.showData, w = structuredClone(b), T = {
	getConfig: /* @__PURE__ */ e(() => structuredClone(w), "getConfig"),
	clear: /* @__PURE__ */ e(() => {
		S = /* @__PURE__ */ new Map(), C = x.showData, n();
	}, "clear"),
	setDiagramTitle: d,
	getDiagramTitle: c,
	setAccTitle: u,
	getAccTitle: o,
	setAccDescription: l,
	getAccDescription: a,
	addSection: /* @__PURE__ */ e(({ label: e, value: n }) => {
		if (n < 0) throw Error(`"${e}" has invalid value: ${n}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);
		S.has(e) || (S.set(e, n), t.debug(`added new section: ${e}, with value: ${n}`));
	}, "addSection"),
	getSections: /* @__PURE__ */ e(() => S, "getSections"),
	setShowData: /* @__PURE__ */ e((e) => {
		C = e;
	}, "setShowData"),
	getShowData: /* @__PURE__ */ e(() => C, "getShowData")
}, E = /* @__PURE__ */ e((e, t) => {
	v(e, t), t.setShowData(e.showData), e.sections.map(t.addSection);
}, "populateDb"), D = { parse: /* @__PURE__ */ e(async (e) => {
	let n = await y("pie", e);
	t.debug(n), E(n, T);
}, "parse") }, O = /* @__PURE__ */ e((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"), k = /* @__PURE__ */ e((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 m().value((e) => e.value).sort(null)(n);
}, "createPieArcs"), A = {
	parser: D,
	db: T,
	renderer: { draw: /* @__PURE__ */ e((e, n, i, a) => {
		t.debug("rendering pie chart\n" + e);
		let o = a.db, c = s(), l = g(o.getConfig(), c.pie), u = h(n), d = u.append("g");
		d.attr("transform", "translate(225,225)");
		let { themeVariables: m } = c, [v] = _(m.pieOuterStrokeWidth);
		v ??= 2;
		let y = l.textPosition, b = p().innerRadius(0).outerRadius(185), x = p().innerRadius(185 * y).outerRadius(185 * y);
		d.append("circle").attr("cx", 0).attr("cy", 0).attr("r", 185 + v / 2).attr("class", "pieOuterCircle");
		let S = o.getSections(), C = k(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 = f(w).domain([...S.keys()]);
		d.selectAll("mySlices").data(E).enter().append("path").attr("d", b).attr("fill", (e) => D(e.data.label)).attr("class", "pieCircle"), d.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 = d.append("text").text(o.getDiagramTitle()).attr("x", 0).attr("y", -400 / 2).attr("class", "pieTitleText"), A = [...S.entries()].map(([e, t]) => ({
			label: e,
			value: t
		})), j = d.selectAll(".legend").data(A).enter().append("g").attr("class", "legend").attr("transform", (e, t) => {
			let n = 22 * A.length / 2;
			return "translate(216," + (t * 22 - n) + ")";
		});
		j.append("rect").attr("width", 18).attr("height", 18).style("fill", (e) => D(e.label)).style("stroke", (e) => D(e.label)), j.append("text").attr("x", 22).attr("y", 14).text((e) => o.getShowData() ? `${e.label} [${e.value}]` : e.label);
		let M = 512 + Math.max(...j.selectAll("text").nodes().map((e) => e?.getBoundingClientRect().width ?? 0)), N = O.node()?.getBoundingClientRect().width ?? 0, P = 450 / 2 - N / 2, F = 450 / 2 + N / 2, I = Math.min(0, P), L = Math.max(M, F) - I;
		u.attr("viewBox", `${I} 0 ${L} 450`), r(u, 450, L, l.useMaxWidth);
	}, "draw") },
	styles: O
};
//#endregion
export { A as diagram };
