import { D as ge, x as Y, al as ve, q as $, J as ie, C as K, G as Q, L as U, T as j, m as ee, b as xe, e as k, b4 as ye, _ as te, a as ne, v as de } from "./am-chart.H2jnOzFc.js";
import "./index.DcjJFMlq.js";
class ce extends ge {
  setupDefaultRules() {
    super.setupDefaultRules();
    const e = this.rule.bind(this);
    e("Venn").setAll({
      legendLabelText: "{category}",
      legendValueText: "{value}",
      colors: ve.new(this._root, {}),
      width: Y,
      height: Y
    }), e("Label", ["venn"]).setAll({
      text: "{category}",
      populateText: !0,
      centerX: $,
      centerY: $
    });
  }
}
var re = 1e-10;
function W(n, e) {
  var s = pe(n), t = s.filter(function(R) {
    return me(R, n);
  }), i = 0, r = 0, a = [], o;
  if (t.length > 1) {
    var f = fe(t);
    for (o = 0; o < t.length; ++o) {
      var h = t[o];
      h.angle = Math.atan2(h.x - f.x, h.y - f.y);
    }
    t.sort(function(R, _) {
      return _.angle - R.angle;
    });
    var u = t[t.length - 1];
    for (o = 0; o < t.length; ++o) {
      var l = t[o];
      r += (u.x + l.x) * (l.y - u.y);
      for (var x = {
        x: (l.x + u.x) / 2,
        y: (l.y + u.y) / 2
      }, y = null, g = 0; g < l.parentIndex.length; ++g)
        if (u.parentIndex.indexOf(l.parentIndex[g]) > -1) {
          var v = n[l.parentIndex[g]], c = Math.atan2(l.x - v.x, l.y - v.y), p = Math.atan2(u.x - v.x, u.y - v.y), b = p - c;
          b < 0 && (b += 2 * Math.PI);
          var M = p - b / 2, m = z(x, {
            x: v.x + v.radius * Math.sin(M),
            y: v.y + v.radius * Math.cos(M)
          });
          m > v.radius * 2 && (m = v.radius * 2), (y === null || y.width > m) && (y = {
            circle: v,
            width: m,
            p1: l,
            p2: u
          });
        }
      y !== null && (a.push(y), i += q(y.circle.radius, y.width), u = l);
    }
  } else {
    var d = n[0];
    for (o = 1; o < n.length; ++o)
      n[o].radius < d.radius && (d = n[o]);
    var D = !1;
    for (o = 0; o < n.length; ++o)
      if (z(n[o], d) > Math.abs(d.radius - n[o].radius)) {
        D = !0;
        break;
      }
    D ? i = r = 0 : (i = d.radius * d.radius * Math.PI, a.push({
      circle: d,
      p1: { x: d.x, y: d.y + d.radius },
      p2: { x: d.x - re, y: d.y + d.radius },
      width: d.radius * 2
    }));
  }
  return r /= 2, e && (e.area = i + r, e.arcArea = i, e.polygonArea = r, e.arcs = a, e.innerPoints = t, e.intersectionPoints = s), i + r;
}
function me(n, e) {
  for (var s = 0; s < e.length; ++s)
    if (z(n, e[s]) > e[s].radius + re)
      return !1;
  return !0;
}
function pe(n) {
  for (var e = [], s = 0; s < n.length; ++s)
    for (var t = s + 1; t < n.length; ++t)
      for (var i = oe(
        n[s],
        n[t]
      ), r = 0; r < i.length; ++r) {
        var a = i[r];
        a.parentIndex = [s, t], e.push(a);
      }
  return e;
}
function q(n, e) {
  return n * n * Math.acos(1 - e / n) - (n - e) * Math.sqrt(e * (2 * n - e));
}
function z(n, e) {
  return Math.sqrt((n.x - e.x) * (n.x - e.x) + (n.y - e.y) * (n.y - e.y));
}
function ae(n, e, s) {
  if (s >= n + e)
    return 0;
  if (s <= Math.abs(n - e))
    return Math.PI * Math.min(n, e) * Math.min(n, e);
  var t = n - (s * s - e * e + n * n) / (2 * s), i = e - (s * s - n * n + e * e) / (2 * s);
  return q(n, t) + q(e, i);
}
function oe(n, e) {
  var s = z(n, e), t = n.radius, i = e.radius;
  if (s >= t + i || s <= Math.abs(t - i))
    return [];
  var r = (t * t - i * i + s * s) / (2 * s), a = Math.sqrt(t * t - r * r), o = n.x + r * (e.x - n.x) / s, f = n.y + r * (e.y - n.y) / s, h = -(e.y - n.y) * (a / s), u = -(e.x - n.x) * (a / s);
  return [
    { x: o + h, y: f - u },
    { x: o - h, y: f + u }
  ];
}
function fe(n) {
  for (var e = { x: 0, y: 0 }, s = 0; s < n.length; ++s)
    e.x += n[s].x, e.y += n[s].y;
  return e.x /= n.length, e.y /= n.length, e;
}
function Me(n, e, s, t) {
  t = t || {};
  var i = t.maxIterations || 100, r = t.tolerance || 1e-10, a = n(e), o = n(s), f = s - e;
  if (a * o > 0)
    throw "Initial bisect points must have opposite signs";
  if (a === 0) return e;
  if (o === 0) return s;
  for (var h = 0; h < i; ++h) {
    f /= 2;
    var u = e + f, l = n(u);
    if (l * a >= 0 && (e = u), Math.abs(f) < r || l === 0)
      return u;
  }
  return e + f;
}
function F(n) {
  for (var e = new Array(n), s = 0; s < n; ++s)
    e[s] = 0;
  return e;
}
function se(n, e) {
  return F(n).map(function() {
    return F(e);
  });
}
function T(n, e) {
  for (var s = 0, t = 0; t < n.length; ++t)
    s += n[t] * e[t];
  return s;
}
function G(n) {
  return Math.sqrt(T(n, n));
}
function H(n, e, s) {
  for (var t = 0; t < e.length; ++t)
    n[t] = e[t] * s;
}
function A(n, e, s, t, i) {
  for (var r = 0; r < n.length; ++r)
    n[r] = e * s[r] + t * i[r];
}
function he(n, e, s) {
  s = s || {};
  var t = s.maxIterations || e.length * 200, i = s.nonZeroDelta || 1.05, r = s.zeroDelta || 1e-3, a = s.minErrorDelta || 1e-6, o = s.minErrorDelta || 1e-5, f = s.rho !== void 0 ? s.rho : 1, h = s.chi !== void 0 ? s.chi : 2, u = s.psi !== void 0 ? s.psi : -0.5, l = s.sigma !== void 0 ? s.sigma : 0.5, x, y = e.length, g = new Array(y + 1);
  g[0] = e, g[0].fx = n(e), g[0].id = 0;
  for (var v = 0; v < y; ++v) {
    var c = e.slice();
    c[v] = c[v] ? c[v] * i : r, g[v + 1] = c, g[v + 1].fx = n(c), g[v + 1].id = v + 1;
  }
  function p(w) {
    for (var P = 0; P < w.length; P++)
      g[y][P] = w[P];
    g[y].fx = w.fx;
  }
  for (var b = function(w, P) {
    return w.fx - P.fx;
  }, M = e.slice(), m = e.slice(), d = e.slice(), D = e.slice(), R = 0; R < t; ++R) {
    if (g.sort(b), s.history) {
      var _ = g.map(function(w) {
        var P = w.slice();
        return P.fx = w.fx, P.id = w.id, P;
      });
      _.sort(function(w, P) {
        return w.id - P.id;
      }), s.history.push({
        x: g[0].slice(),
        fx: g[0].fx,
        simplex: _
      });
    }
    for (x = 0, v = 0; v < y; ++v)
      x = Math.max(x, Math.abs(g[0][v] - g[1][v]));
    if (Math.abs(g[0].fx - g[y].fx) < a && x < o)
      break;
    for (v = 0; v < y; ++v) {
      M[v] = 0;
      for (var L = 0; L < y; ++L)
        M[v] += g[L][v];
      M[v] /= y;
    }
    var C = g[y];
    if (A(m, 1 + f, M, -f, C), m.fx = n(m), m.fx < g[0].fx)
      A(D, 1 + h, M, -h, C), D.fx = n(D), D.fx < m.fx ? p(D) : p(m);
    else if (m.fx >= g[y - 1].fx) {
      var I = !1;
      if (m.fx > C.fx ? (A(d, 1 + u, M, -u, C), d.fx = n(d), d.fx < C.fx ? p(d) : I = !0) : (A(d, 1 - u * f, M, u * f, C), d.fx = n(d), d.fx < m.fx ? p(d) : I = !0), I) {
        if (l >= 1) break;
        for (v = 1; v < g.length; ++v)
          A(g[v], 1 - l, g[0], l, g[v]), g[v].fx = n(g[v]);
      }
    } else
      p(m);
  }
  return g.sort(b), {
    fx: g[0].fx,
    x: g[0]
  };
}
function be(n, e, s, t, i, r, a) {
  var o = s.fx, f = T(s.fxprime, e), h = o, u = o, l = f, x = 0;
  i = i || 1, r = r || 1e-6, a = a || 0.1;
  function y(v, c, p) {
    for (var b = 0; b < 16; ++b)
      if (i = (v + c) / 2, A(t.x, 1, s.x, i, e), h = t.fx = n(t.x, t.fxprime), l = T(t.fxprime, e), h > o + r * i * f || h >= p)
        c = i;
      else {
        if (Math.abs(l) <= -a * f)
          return i;
        l * (c - v) >= 0 && (c = v), v = i, p = h;
      }
    return 0;
  }
  for (var g = 0; g < 10; ++g) {
    if (A(t.x, 1, s.x, i, e), h = t.fx = n(t.x, t.fxprime), l = T(t.fxprime, e), h > o + r * i * f || g && h >= u)
      return y(x, i, u);
    if (Math.abs(l) <= -a * f)
      return i;
    if (l >= 0)
      return y(i, x, h);
    u = h, x = i, i *= 2;
  }
  return i;
}
function De(n, e, s) {
  var t = { x: e.slice(), fx: 0, fxprime: e.slice() }, i = { x: e.slice(), fx: 0, fxprime: e.slice() }, r = e.slice(), a, o, f = 1, h;
  s = s || {}, h = s.maxIterations || e.length * 20, t.fx = n(t.x, t.fxprime), a = t.fxprime.slice(), H(a, t.fxprime, -1);
  for (var u = 0; u < h; ++u) {
    if (f = be(n, a, t, i, f), s.history && s.history.push({
      x: t.x.slice(),
      fx: t.fx,
      fxprime: t.fxprime.slice(),
      alpha: f
    }), !f)
      H(a, t.fxprime, -1);
    else {
      A(r, 1, i.fxprime, -1, t.fxprime);
      var l = T(t.fxprime, t.fxprime), x = Math.max(0, T(r, i.fxprime) / l);
      A(a, x, a, -1, i.fxprime), o = t, t = i, i = o;
    }
    if (G(t.fxprime) <= 1e-5)
      break;
  }
  return s.history && s.history.push({
    x: t.x.slice(),
    fx: t.fx,
    fxprime: t.fxprime.slice(),
    alpha: f
  }), t;
}
function we(n, e) {
  e = e || {}, e.maxIterations = e.maxIterations || 500;
  var s = e.initialLayout || _e, t = e.lossFunction || Z;
  n = Pe(n);
  var i = s(n, e), r = [], a = [], o;
  for (o in i)
    i.hasOwnProperty(o) && (r.push(i[o].x), r.push(i[o].y), a.push(o));
  for (var f = he(
    function(l) {
      for (var x = {}, y = 0; y < a.length; ++y) {
        var g = a[y];
        x[g] = {
          x: l[2 * y],
          y: l[2 * y + 1],
          radius: i[g].radius
          // size : circles[setid].size
        };
      }
      return t(x, n);
    },
    r,
    e
  ), h = f.x, u = 0; u < a.length; ++u)
    o = a[u], i[o].x = h[2 * u], i[o].y = h[2 * u + 1];
  return i;
}
var ue = 1e-10;
function V(n, e, s) {
  return Math.min(n, e) * Math.min(n, e) * Math.PI <= s + ue ? Math.abs(n - e) : Me(function(t) {
    return ae(n, e, t) - s;
  }, 0, n + e);
}
function Pe(n) {
  n = n.slice();
  var e = [], s = {}, t, i, r, a;
  for (t = 0; t < n.length; ++t) {
    var o = n[t];
    o.sets.length == 1 ? e.push(o.sets[0]) : o.sets.length == 2 && (r = o.sets[0], a = o.sets[1], s[[r, a]] = !0, s[[a, r]] = !0);
  }
  for (e.sort(function(f, h) {
    return f > h;
  }), t = 0; t < e.length; ++t)
    for (r = e[t], i = t + 1; i < e.length; ++i)
      a = e[i], [r, a] in s || n.push({
        sets: [r, a],
        size: 0
      });
  return n;
}
function ze(n, e, s) {
  var t = se(e.length, e.length), i = se(e.length, e.length);
  return n.filter(function(r) {
    return r.sets.length == 2;
  }).map(function(r) {
    var a = s[r.sets[0]], o = s[r.sets[1]], f = Math.sqrt(e[a].size / Math.PI), h = Math.sqrt(e[o].size / Math.PI), u = V(f, h, r.size);
    t[a][o] = t[o][a] = u;
    var l = 0;
    r.size + 1e-10 >= Math.min(
      e[a].size,
      e[o].size
    ) ? l = 1 : r.size <= 1e-10 && (l = -1), i[a][o] = i[o][a] = l;
  }), { distances: t, constraints: i };
}
function Re(n, e, s, t) {
  var i = 0, r;
  for (r = 0; r < e.length; ++r)
    e[r] = 0;
  for (r = 0; r < s.length; ++r)
    for (var a = n[2 * r], o = n[2 * r + 1], f = r + 1; f < s.length; ++f) {
      var h = n[2 * f], u = n[2 * f + 1], l = s[r][f], x = t[r][f], y = (h - a) * (h - a) + (u - o) * (u - o), g = Math.sqrt(y), v = y - l * l;
      x > 0 && g <= l || x < 0 && g >= l || (i += 2 * v * v, e[2 * r] += 4 * v * (a - h), e[2 * r + 1] += 4 * v * (o - u), e[2 * f] += 4 * v * (h - a), e[2 * f + 1] += 4 * v * (u - o));
    }
  return i;
}
function _e(n, e) {
  var s = Ce(n, e), t = e.lossFunction || Z;
  if (n.length >= 8) {
    var i = Ae(n, e), r = t(i, n), a = t(s, n);
    r + 1e-8 < a && (s = i);
  }
  return s;
}
function Ae(n, e) {
  e = e || {};
  var s = e.restarts || 10, t = [], i = {}, r;
  for (r = 0; r < n.length; ++r) {
    var a = n[r];
    a.sets.length == 1 && (i[a.sets[0]] = t.length, t.push(a));
  }
  var o = ze(n, t, i), f = o.distances, h = o.constraints, u = G(f.map(G)) / f.length;
  f = f.map(function(b) {
    return b.map(function(M) {
      return M / u;
    });
  });
  var l = function(b, M) {
    return Re(b, M, f, h);
  }, x, y;
  for (r = 0; r < s; ++r) {
    var g = F(f.length * 2).map(Math.random);
    y = De(l, g, e), (!x || y.fx < x.fx) && (x = y);
  }
  var v = x.x, c = {};
  for (r = 0; r < t.length; ++r) {
    var p = t[r];
    c[p.sets[0]] = {
      x: v[2 * r] * u,
      y: v[2 * r + 1] * u,
      radius: Math.sqrt(p.size / Math.PI)
    };
  }
  if (e.history)
    for (r = 0; r < e.history.length; ++r)
      H(e.history[r].x, u);
  return c;
}
function Ce(n, e) {
  for (var s = e && e.lossFunction ? e.lossFunction : Z, t = {}, i = {}, r, a = 0; a < n.length; ++a) {
    var o = n[a];
    o.sets.length == 1 && (r = o.sets[0], t[r] = {
      x: 1e10,
      y: 1e10,
      rowid: t.length,
      size: o.size,
      radius: Math.sqrt(o.size / Math.PI)
    }, i[r] = []);
  }
  for (n = n.filter(function(O) {
    return O.sets.length == 2;
  }), a = 0; a < n.length; ++a) {
    var f = n[a], h = f.hasOwnProperty("weight") ? f.weight : 1, u = f.sets[0], l = f.sets[1];
    f.size + ue >= Math.min(
      t[u].size,
      t[l].size
    ) && (h = 0), i[u].push({ set: l, size: f.size, weight: h }), i[l].push({ set: u, size: f.size, weight: h });
  }
  var x = [];
  for (r in i)
    if (i.hasOwnProperty(r)) {
      var y = 0;
      for (a = 0; a < i[r].length; ++a)
        y += i[r][a].size * i[r][a].weight;
      x.push({ set: r, size: y });
    }
  function g(O, S) {
    return S.size - O.size;
  }
  x.sort(g);
  var v = {};
  function c(O) {
    return O.set in v;
  }
  function p(O, S) {
    t[S].x = O.x, t[S].y = O.y, v[S] = !0;
  }
  for (p({ x: 0, y: 0 }, x[0].set), a = 1; a < x.length; ++a) {
    var b = x[a].set, M = i[b].filter(c);
    if (r = t[b], M.sort(g), M.length === 0)
      throw "ERROR: missing pairwise overlap information";
    for (var m = [], d = 0; d < M.length; ++d) {
      var D = t[M[d].set], R = V(
        r.radius,
        D.radius,
        M[d].size
      );
      m.push({ x: D.x + R, y: D.y }), m.push({ x: D.x - R, y: D.y }), m.push({ y: D.y + R, x: D.x }), m.push({ y: D.y - R, x: D.x });
      for (var _ = d + 1; _ < M.length; ++_)
        for (var L = t[M[_].set], C = V(
          r.radius,
          L.radius,
          M[_].size
        ), I = oe(
          { x: D.x, y: D.y, radius: R },
          { x: L.x, y: L.y, radius: C }
        ), w = 0; w < I.length; ++w)
          m.push(I[w]);
    }
    var P = 1e50, J = m[0];
    for (d = 0; d < m.length; ++d) {
      t[b].x = m[d].x, t[b].y = m[d].y;
      var X = s(t, n);
      X < P && (P = X, J = m[d]);
    }
    p(J, b);
  }
  return t;
}
function Z(n, e) {
  var s = 0;
  function t(u) {
    return u.map(function(l) {
      return n[l];
    });
  }
  for (var i = 0; i < e.length; ++i) {
    var r = e[i], a;
    if (r.sets.length != 1) {
      if (r.sets.length == 2) {
        var o = n[r.sets[0]], f = n[r.sets[1]];
        a = ae(
          o.radius,
          f.radius,
          z(o, f)
        );
      } else
        a = W(t(r.sets));
      var h = r.hasOwnProperty("weight") ? r.weight : 1;
      s += h * (a - r.size) * (a - r.size);
    }
  }
  return s;
}
function Oe(n, e, s) {
  n.sort(function(v, c) {
    return c.radius - v.radius;
  });
  var t;
  if (n.length > 0) {
    var i = n[0].x, r = n[0].y;
    for (t = 0; t < n.length; ++t)
      n[t].x -= i, n[t].y -= r;
  }
  if (n.length == 2) {
    var a = z(n[0], n[1]);
    a < Math.abs(n[1].radius - n[0].radius) && (n[1].x = n[0].x + n[0].radius - n[1].radius - 1e-10, n[1].y = n[0].y);
  }
  if (n.length > 1) {
    var o = Math.atan2(n[1].x, n[1].y) - e, f = Math.cos(o), h = Math.sin(o), u, l;
    for (t = 0; t < n.length; ++t)
      u = n[t].x, l = n[t].y, n[t].x = f * u - h * l, n[t].y = h * u + f * l;
  }
  if (n.length > 2) {
    for (var x = Math.atan2(n[2].x, n[2].y) - e; x < 0; )
      x += 2 * Math.PI;
    for (; x > 2 * Math.PI; )
      x -= 2 * Math.PI;
    if (x > Math.PI) {
      var y = n[1].y / (1e-10 + n[1].x);
      for (t = 0; t < n.length; ++t) {
        var g = (n[t].x + y * n[t].y) / (1 + y * y);
        n[t].x = 2 * g - n[t].x, n[t].y = 2 * g * y - n[t].y;
      }
    }
  }
}
function Le(n) {
  n.map(function(h) {
    h.parent = h;
  });
  function e(h) {
    return h.parent !== h && (h.parent = e(h.parent)), h.parent;
  }
  function s(h, u) {
    var l = e(h), x = e(u);
    l.parent = x;
  }
  for (var t = 0; t < n.length; ++t)
    for (var i = t + 1; i < n.length; ++i) {
      var r = n[t].radius + n[i].radius;
      z(n[t], n[i]) + 1e-10 < r && s(n[i], n[t]);
    }
  var a = {}, o;
  for (t = 0; t < n.length; ++t)
    o = e(n[t]).parent.setid, o in a || (a[o] = []), a[o].push(n[t]);
  n.map(function(h) {
    delete h.parent;
  });
  var f = [];
  for (o in a)
    a.hasOwnProperty(o) && f.push(a[o]);
  return f;
}
function B(n) {
  var e = function(s) {
    var t = Math.max.apply(null, n.map(
      function(r) {
        return r[s] + r.radius;
      }
    )), i = Math.min.apply(null, n.map(
      function(r) {
        return r[s] - r.radius;
      }
    ));
    return { max: t, min: i };
  };
  return { xRange: e("x"), yRange: e("y") };
}
function ke(n, e, s) {
  e === null && (e = Math.PI / 2);
  var t = [], i, r;
  for (r in n)
    if (n.hasOwnProperty(r)) {
      var a = n[r];
      t.push({
        x: a.x,
        y: a.y,
        radius: a.radius,
        setid: r
      });
    }
  var o = Le(t);
  for (i = 0; i < o.length; ++i) {
    Oe(o[i], e);
    var f = B(o[i]);
    o[i].size = (f.xRange.max - f.xRange.min) * (f.yRange.max - f.yRange.min), o[i].bounds = f;
  }
  o.sort(function(g, v) {
    return v.size - g.size;
  }), t = o[0];
  var h = t.bounds, u = (h.xRange.max - h.xRange.min) / 50;
  function l(g, v, c) {
    if (g) {
      var p = g.bounds, b, M, m;
      v ? b = h.xRange.max - p.xRange.min + u : (b = h.xRange.max - p.xRange.max, m = (p.xRange.max - p.xRange.min) / 2 - (h.xRange.max - h.xRange.min) / 2, m < 0 && (b += m)), c ? M = h.yRange.max - p.yRange.min + u : (M = h.yRange.max - p.yRange.max, m = (p.yRange.max - p.yRange.min) / 2 - (h.yRange.max - h.yRange.min) / 2, m < 0 && (M += m));
      for (var d = 0; d < g.length; ++d)
        g[d].x += b, g[d].y += M, t.push(g[d]);
    }
  }
  for (var x = 1; x < o.length; )
    l(o[x], !0, !1), l(o[x + 1], !1, !0), l(o[x + 2], !0, !0), x += 3, h = B(t);
  var y = {};
  for (i = 0; i < t.length; ++i)
    y[t[i].setid] = t[i];
  return y;
}
function Ie(n, e, s, t) {
  var i = [], r = [];
  for (var a in n)
    n.hasOwnProperty(a) && (r.push(a), i.push(n[a]));
  e -= 2 * t, s -= 2 * t;
  var o = B(i), f = o.xRange, h = o.yRange;
  if (f.max == f.min || h.max == h.min)
    return console.log("not scaling solution: zero size detected"), n;
  for (var u = e / (f.max - f.min), l = s / (h.max - h.min), x = Math.min(l, u), y = (e - (f.max - f.min) * x) / 2, g = (s - (h.max - h.min) * x) / 2, v = {}, c = 0; c < i.length; ++c) {
    var p = i[c];
    v[r[c]] = {
      radius: x * p.radius,
      x: t + y + (p.x - f.min) * x,
      y: t + g + (p.y - h.min) * x
    };
  }
  return v;
}
function N(n, e, s) {
  var t = e[0].radius - z(e[0], n), i, r;
  for (i = 1; i < e.length; ++i)
    r = e[i].radius - z(e[i], n), r <= t && (t = r);
  for (i = 0; i < s.length; ++i)
    r = z(s[i], n) - s[i].radius, r <= t && (t = r);
  return t;
}
function le(n, e) {
  var s = [], t;
  for (t = 0; t < n.length; ++t) {
    var i = n[t];
    s.push({ x: i.x, y: i.y }), s.push({ x: i.x + i.radius / 2, y: i.y }), s.push({ x: i.x - i.radius / 2, y: i.y }), s.push({ x: i.x, y: i.y + i.radius / 2 }), s.push({ x: i.x, y: i.y - i.radius / 2 });
  }
  var r = s[0], a = N(s[0], n, e);
  for (t = 1; t < s.length; ++t) {
    var o = N(s[t], n, e);
    o >= a && (r = s[t], a = o);
  }
  var f = he(
    function(x) {
      return -1 * N({ x: x[0], y: x[1] }, n, e);
    },
    [r.x, r.y],
    { maxIterations: 500, minErrorDelta: 1e-10 }
  ).x, h = { x: f[0], y: f[1] }, u = !0;
  for (t = 0; t < n.length; ++t)
    if (z(h, n[t]) > n[t].radius) {
      u = !1;
      break;
    }
  for (t = 0; t < e.length; ++t)
    if (z(h, e[t]) < e[t].radius) {
      u = !1;
      break;
    }
  if (!u)
    if (n.length == 1)
      h = { x: n[0].x, y: n[0].y };
    else {
      var l = {};
      W(n, l), l.arcs.length === 0 ? h = { x: 0, y: -1e3, disjoint: !0 } : l.arcs.length == 1 ? h = {
        x: l.arcs[0].circle.x,
        y: l.arcs[0].circle.y
      } : e.length ? h = le(n, []) : h = fe(l.arcs.map(function(x) {
        return x.p1;
      }));
    }
  return h;
}
function Te(n) {
  var e = {}, s = [];
  for (var t in n)
    s.push(t), e[t] = [];
  for (var i = 0; i < s.length; i++)
    for (var r = n[s[i]], a = i + 1; a < s.length; ++a) {
      var o = n[s[a]], f = z(r, o);
      f + o.radius <= r.radius + 1e-10 ? e[s[a]].push(s[i]) : f + r.radius <= o.radius + 1e-10 && e[s[i]].push(s[a]);
    }
  return e;
}
function Se(n, e) {
  for (var s = {}, t = Te(n), i = 0; i < e.length; ++i) {
    for (var r = e[i].sets, a = {}, o = {}, f = 0; f < r.length; ++f) {
      a[r[f]] = !0;
      for (var h = t[r[f]], u = 0; u < h.length; ++u)
        o[h[u]] = !0;
    }
    var l = [], x = [];
    for (var y in n)
      y in a ? l.push(n[y]) : y in o || x.push(n[y]);
    var g = le(l, x);
    s[r] = g, g.disjoint && e[i].size > 0 && console.log("WARNING: area " + r + " not represented on screen");
  }
  return s;
}
function Ne(n, e, s) {
  var t = [];
  return t.push(`
M`, n, e), t.push(`
m`, -s, 0), t.push(`
a`, s, s, 0, 1, 0, s * 2, 0), t.push(`
a`, s, s, 0, 1, 0, -s * 2, 0), t.join(" ");
}
function qe(n) {
  var e = {};
  W(n, e);
  var s = e.arcs;
  if (s.length === 0)
    return "M 0 0";
  if (s.length == 1) {
    var t = s[0].circle;
    return Ne(t.x, t.y, t.radius);
  } else {
    for (var i = [`
M`, s[0].p2.x, s[0].p2.y], r = 0; r < s.length; ++r) {
      var a = s[r], o = a.circle.radius, f = a.width > o;
      i.push(
        `
A`,
        o,
        o,
        0,
        f ? 1 : 0,
        1,
        a.p1.x,
        a.p1.y
      );
    }
    return i.join(" ");
  }
}
class E extends ie {
  constructor() {
    super(...arguments), this._sets = "", this.slicesContainer = this.children.push(K.new(this._root, {})), this.labelsContainer = this.children.push(K.new(this._root, {})), this.hoverGraphics = this.slicesContainer.children.push(Q.new(this._root, { position: "absolute", isMeasured: !1 })), this.slices = this.addDisposer(this._makeSlices()), this.labels = this.addDisposer(this._makeLabels());
  }
  _applyThemes(e = !1) {
    const s = this.get("colors");
    return s && s.reset(), super._applyThemes(e);
  }
  _afterNew() {
    this._defaultThemes.push(ce.new(this._root)), this.fields.push("intersections", "category", "fill"), super._afterNew();
  }
  /**
   * @ignore
   */
  makeSlice(e) {
    const s = this.slicesContainer.children.push(this.slices.make());
    return s.events.on("pointerover", (t) => {
      this._hovered = t.target, this._updateHover();
    }), s.events.on("pointerout", () => {
      this._hovered = void 0, this.hoverGraphics.hide();
    }), s.on("fill", () => {
      this.updateLegendMarker(e);
    }), s.on("fillPattern", () => {
      this.updateLegendMarker(e);
    }), s.on("stroke", () => {
      this.updateLegendMarker(e);
    }), s._setDataItem(e), e.set("slice", s), this.slices.push(s), s;
  }
  _updateHover() {
    if (this._hovered) {
      const e = this.hoverGraphics;
      e.set("svgPath", this._hovered.get("svgPath")), e.show(), e.toFront();
    }
  }
  /**
   * @ignore
   */
  makeLabel(e) {
    const s = this.labelsContainer.children.push(this.labels.make());
    return s._setDataItem(e), e.set("label", s), this.labels.push(s), s;
  }
  _makeSlices() {
    return new U(j.new({}), () => Q._new(this._root, {
      themeTags: ee(this.slices.template.get("themeTags", []), ["venn", "series"])
    }, [this.slices.template]));
  }
  _makeLabels() {
    return new U(j.new({}), () => xe._new(this._root, {
      themeTags: ee(this.labels.template.get("themeTags", []), ["venn", "series"])
    }, [this.labels.template]));
  }
  processDataItem(e) {
    if (super.processDataItem(e), e.get("fill") == null) {
      let s = this.get("colors");
      s && e.setRaw("fill", s.next());
    }
    if (e.get("fillPattern") == null) {
      let s = this.get("patterns");
      s && e.setRaw("fillPattern", s.next());
    }
    this.makeSlice(e), this.makeLabel(e);
  }
  _prepareChildren() {
    if (super._prepareChildren(), this._valuesDirty || this._sizeDirty) {
      const e = [];
      k(this.dataItems, (t) => {
        const i = {}, r = t.get("intersections");
        r ? i.sets = r : i.sets = [t.get("category")], i.size = t.get("valueWorking"), e.push(i);
        const a = t.get("label"), o = t.get("slice");
        let f = !0;
        t.get("value") == 0 && (f = !1, o && o.setAll({
          x: this.width() / 2,
          y: this.height() / 2
        })), a && a.setPrivate("visible", f);
      });
      const s = e.toString();
      if (this._sets = s, e.length > 0) {
        let t = we(e);
        t = ke(t, null), t = Ie(t, this.innerWidth(), this.innerHeight(), 0);
        const i = {};
        for (let a in t) {
          let o = t[a], f = o.radius;
          const h = this.getDataItemByCategory(a);
          if (h) {
            const u = h.get("slice"), l = h.get("fill");
            u._setDefault("fill", l);
            const x = h.get("fillPattern");
            u._setDefault("fillPattern", x), u._setDefault("stroke", l), this.updateLegendMarker(h), u.set("svgPath", "M" + o.x + "," + o.y + " m -" + f + ", 0 a " + f + "," + f + " 0 1,1 " + f * 2 + ",0 a " + f + "," + f + " 0 1,1 -" + f * 2 + ",0"), i[a] = o;
          }
        }
        let r = Se(i, e);
        k(this.dataItems, (a) => {
          let o = a.get("category"), f = r[o];
          const h = a.get("intersections");
          if (h && (o = h.toString(), f = r[o], f)) {
            let u = h, l = [];
            for (let c = 0; c < u.length; c++)
              l.push(i[u[c]]);
            let x = qe(l), y = a.get("slice");
            const g = a.get("fill");
            y._setDefault("fill", g), y._setDefault("stroke", g);
            const v = a.get("fillPattern");
            y._setDefault("fillPattern", v), y.setAll({ svgPath: x });
          }
          f && a.get("label").setAll({ x: f.x, y: f.y }), this.updateLegendValue(a);
        });
      }
      this._updateHover();
    }
  }
  /**
   * Looks up and returns a data item by its category.
   *
   * @param   category  Category
   * @return      Data item
   */
  getDataItemByCategory(e) {
    return ye(this.dataItems, (s) => s.get("category") == e);
  }
  /**
   * Shows series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  showDataItem(e, s) {
    const t = Object.create(null, {
      showDataItem: { get: () => super.showDataItem }
    });
    return te(this, void 0, void 0, function* () {
      const i = [t.showDataItem.call(this, e, s)];
      ne(s) || (s = this.get("stateAnimationDuration", 0));
      const r = this.get("stateAnimationEasing");
      let a = e.get("value");
      const o = e.animate({ key: "valueWorking", to: a, duration: s, easing: r });
      o && i.push(o.waitForStop());
      const f = e.get("label");
      f && i.push(f.show(s));
      const h = e.get("slice");
      h && i.push(h.show(s));
      const u = e.get("intersections");
      if (u && k(u, (l) => {
        const x = this.getDataItemByCategory(l);
        x && x.isHidden() && this.showDataItem(x, s);
      }), !u) {
        const l = e.get("category");
        k(this.dataItems, (x) => {
          const y = x.get("intersections");
          if (x != e && y) {
            let g = !0;
            k(y, (v) => {
              const c = this.getDataItemByCategory(v);
              c && c.isHidden() && (g = !1);
            }), g && y.indexOf(l) != -1 && x.isHidden() && this.showDataItem(x, s);
          }
        });
      }
      yield Promise.all(i);
    });
  }
  /**
   * Hides series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  hideDataItem(e, s) {
    const t = Object.create(null, {
      hideDataItem: { get: () => super.hideDataItem }
    });
    return te(this, void 0, void 0, function* () {
      const i = [t.hideDataItem.call(this, e, s)], r = this.states.create("hidden", {});
      ne(s) || (s = r.get("stateAnimationDuration", this.get("stateAnimationDuration", 0)));
      const a = r.get("stateAnimationEasing", this.get("stateAnimationEasing")), o = e.animate({ key: "valueWorking", to: 0, duration: s, easing: a });
      o && i.push(o.waitForStop());
      const f = e.get("label");
      f && i.push(f.hide(s));
      const h = e.get("slice");
      h && (i.push(h.hide(s)), h.hideTooltip()), e.get("intersections") || k(this.dataItems, (u) => {
        const l = u.get("intersections");
        u != e && l && l.indexOf(e.get("category")) != -1 && this.hideDataItem(u, s);
      }), yield Promise.all(i);
    });
  }
  /**
   * @ignore
   */
  disposeDataItem(e) {
    super.disposeDataItem(e);
    let s = e.get("label");
    s && (this.labels.removeValue(s), s.dispose());
    let t = e.get("slice");
    t && (this.slices.removeValue(t), t.dispose());
  }
  /**
   * @ignore
   */
  updateLegendMarker(e) {
    const s = e.get("slice");
    if (s) {
      const t = e.get("legendDataItem");
      if (t) {
        const i = t.get("markerRectangle");
        e.isHidden() || k(de, (r) => {
          i.set(r, s.get(r));
        });
      }
    }
  }
  /**
   * Triggers hover on a series data item.
   *
   * @since 5.0.7
   * @param  dataItem  Target data item
   */
  hoverDataItem(e) {
    const s = e.get("slice");
    s && !s.isHidden() && s.hover();
  }
  /**
   * Triggers un-hover on a series data item.
   *
   * @since 5.0.7
   * @param  dataItem  Target data item
   */
  unhoverDataItem(e) {
    const s = e.get("slice");
    s && s.unhover();
  }
}
E.className = "Venn";
E.classNames = ie.classNames.concat([E.className]);
export {
  ce as DefaultTheme,
  E as Venn
};
