import { Z as J, wt as R, xt as K } from "./vendor/recharts.js";
import { f as Q, r as Y } from "./chunk-5PVQY5BW.js";
import { n as r, r as C } from "./chunk-AGHRB4JF.js";
import { B as tt, C as et, V as at, W as it, _ as rt, a as st, b as ot, c as nt, d as lt, v as ct } from "./chunk-ICPOFSXX.js";
import { t as dt } from "./chunk-426QAEUC.js";
import { t as pt } from "./chunk-4BX2VUAB.js";
import { t as gt } from "./mermaid-parser.core.js";
var G = lt.pie, D = {
  sections: /* @__PURE__ */ new Map(),
  showData: !1,
  config: G
}, u = D.sections, v = D.showData, ft = structuredClone(G), L = {
  getConfig: /* @__PURE__ */ r(() => structuredClone(ft), "getConfig"),
  clear: /* @__PURE__ */ r(() => {
    u = /* @__PURE__ */ new Map(), v = D.showData, st();
  }, "clear"),
  setDiagramTitle: it,
  getDiagramTitle: et,
  setAccTitle: at,
  getAccTitle: ct,
  setAccDescription: tt,
  getAccDescription: rt,
  addSection: /* @__PURE__ */ r(({ label: t, value: a }) => {
    if (a < 0) throw new Error(`"${t}" has invalid value: ${a}. Negative values are not allowed in pie charts. All slice values must be >= 0.`);
    u.has(t) || (u.set(t, a), C.debug(`added new section: ${t}, with value: ${a}`));
  }, "addSection"),
  getSections: /* @__PURE__ */ r(() => u, "getSections"),
  setShowData: /* @__PURE__ */ r((t) => {
    v = t;
  }, "setShowData"),
  getShowData: /* @__PURE__ */ r(() => v, "getShowData")
}, ut = /* @__PURE__ */ r((t, a) => {
  pt(t, a), a.setShowData(t.showData), t.sections.map(a.addSection);
}, "populateDb"), ht = { parse: /* @__PURE__ */ r(async (t) => {
  const a = await gt("pie", t);
  C.debug(a), ut(a, L);
}, "parse") }, mt = /* @__PURE__ */ r((t) => `
  .pieCircle{
    stroke: ${t.pieStrokeColor};
    stroke-width : ${t.pieStrokeWidth};
    opacity : ${t.pieOpacity};
  }
  .pieOuterCircle{
    stroke: ${t.pieOuterStrokeColor};
    stroke-width: ${t.pieOuterStrokeWidth};
    fill: none;
  }
  .pieTitleText {
    text-anchor: middle;
    font-size: ${t.pieTitleTextSize};
    fill: ${t.pieTitleTextColor};
    font-family: ${t.fontFamily};
  }
  .slice {
    font-family: ${t.fontFamily};
    fill: ${t.pieSectionTextColor};
    font-size:${t.pieSectionTextSize};
    // fill: white;
  }
  .legend text {
    fill: ${t.pieLegendTextColor};
    font-family: ${t.fontFamily};
    font-size: ${t.pieLegendTextSize};
  }
`, "getStyles"), xt = /* @__PURE__ */ r((t) => {
  const a = [...t.values()].reduce((s, o) => s + o, 0), $ = [...t.entries()].map(([s, o]) => ({
    label: s,
    value: o
  })).filter((s) => s.value / a * 100 >= 1);
  return K().value((s) => s.value).sort(null)($);
}, "createPieArcs"), Tt = {
  parser: ht,
  db: L,
  renderer: { draw: /* @__PURE__ */ r((t, a, $, s) => {
    C.debug(`rendering pie chart
` + t);
    const o = s.db, y = ot(), T = Y(o.getConfig(), y.pie), A = 40, n = 18, p = 4, l = 450, d = l, h = dt(a), c = h.append("g");
    c.attr("transform", "translate(" + d / 2 + "," + l / 2 + ")");
    const { themeVariables: i } = y;
    let [_] = Q(i.pieOuterStrokeWidth);
    _ ??= 2;
    const b = T.textPosition, g = Math.min(d, l) / 2 - A, O = R().innerRadius(0).outerRadius(g), P = R().innerRadius(g * b).outerRadius(g * b);
    c.append("circle").attr("cx", 0).attr("cy", 0).attr("r", g + _ / 2).attr("class", "pieOuterCircle");
    const f = o.getSections(), B = xt(f), I = [
      i.pie1,
      i.pie2,
      i.pie3,
      i.pie4,
      i.pie5,
      i.pie6,
      i.pie7,
      i.pie8,
      i.pie9,
      i.pie10,
      i.pie11,
      i.pie12
    ];
    let m = 0;
    f.forEach((e) => {
      m += e;
    });
    const E = B.filter((e) => (e.data.value / m * 100).toFixed(0) !== "0"), x = J(I).domain([...f.keys()]);
    c.selectAll("mySlices").data(E).enter().append("path").attr("d", O).attr("fill", (e) => x(e.data.label)).attr("class", "pieCircle"), c.selectAll("mySlices").data(E).enter().append("text").text((e) => (e.data.value / m * 100).toFixed(0) + "%").attr("transform", (e) => "translate(" + P.centroid(e) + ")").style("text-anchor", "middle").attr("class", "slice");
    const N = c.append("text").text(o.getDiagramTitle()).attr("x", 0).attr("y", -(l - 50) / 2).attr("class", "pieTitleText"), k = [...f.entries()].map(([e, w]) => ({
      label: e,
      value: w
    })), S = c.selectAll(".legend").data(k).enter().append("g").attr("class", "legend").attr("transform", (e, w) => {
      const M = n + p, j = M * k.length / 2, q = 12 * n, H = w * M - j;
      return "translate(" + q + "," + H + ")";
    });
    S.append("rect").attr("width", n).attr("height", n).style("fill", (e) => x(e.label)).style("stroke", (e) => x(e.label)), S.append("text").attr("x", n + p).attr("y", n - p).text((e) => o.getShowData() ? `${e.label} [${e.value}]` : e.label);
    const U = Math.max(...S.selectAll("text").nodes().map((e) => e?.getBoundingClientRect().width ?? 0)), V = d + A + n + p + U, W = N.node()?.getBoundingClientRect().width ?? 0, Z = d / 2 - W / 2, X = d / 2 + W / 2, z = Math.min(0, Z), F = Math.max(V, X) - z;
    h.attr("viewBox", `${z} 0 ${F} ${l}`), nt(h, l, F, T.useMaxWidth);
  }, "draw") },
  styles: mt
};
export {
  Tt as diagram
};

//# sourceMappingURL=pieDiagram-DEJITSTG.js.map