import { D as at, x as z, al as lt, e as N, am as he, q as I, H as ct, F as ht, I as gt, J as ve, C as Ge, a as $, _ as oe, b7 as ut, L as O, T as B, b as Qe, aj as re, j as G, h as M, G as Ze, P as dt, b8 as ft, b9 as De, m as le, o as ge, r as Ae, b5 as Fe, R as pt, aZ as K, b3 as Oe, ba as kt, bb as mt } from "./am-chart.H2jnOzFc.js";
import { L as Be } from "./LinearGradient.B1z9AGUt.js";
import "./index.DcjJFMlq.js";
import "./transform.BuqENXeT.js";
import { S as yt } from "./Slice.DiEswWa6.js";
import { R as _t } from "./RadialLabel.DyVOf2K8.js";
import { c as We, a as ze } from "./MonotoneXTension.CJMEHHj3.js";
import { C as wt } from "./Circle.DBa5Ok8V.js";
class xt extends at {
  setupDefaultRules() {
    super.setupDefaultRules();
    const t = this._root.interfaceColors, e = this.rule.bind(this);
    e("Flow").setAll({
      width: z,
      height: z,
      paddingLeft: 10,
      paddingRight: 10,
      paddingTop: 10,
      paddingBottom: 10,
      hiddenSize: 0.05,
      minSize: 0,
      minHiddenValue: 0
    }), e("FlowNodes").setAll({
      colors: lt.new(this._root, {}),
      legendLabelText: "{name}",
      legendValueText: "{sumOutgoing.formatNumber('#.#')}"
    }), e("FlowNode").setAll({
      setStateOnChildren: !0,
      cursorOverStyle: "pointer",
      toggleKey: "disabled"
    }), e("FlowNode").states.create("disabled", {}), e("FlowNode", ["unknown"]).setAll({
      draggable: !1,
      opacity: 0
    }), e("Label", ["flow"]).states.create("disabled", {
      fill: t.get("disabled")
    }), e("RadialLabel", ["flow", "node"]).setAll({
      text: "{name}",
      populateText: !0
    }), e("FlowLink").setAll({
      fillStyle: "gradient",
      strokeStyle: "gradient"
    }), e("FlowLink", ["source", "unknown"]).setAll({}), e("FlowLink", ["target", "unknown"]).setAll({}), e("FlowNode").events.on("pointerover", (s) => {
      const n = s.target.dataItem;
      if (n) {
        const a = n.get("outgoingLinks");
        a && N(a, (o) => {
          const l = o.get("link");
          l.hover(), l.hideTooltip();
        });
        const r = n.get("incomingLinks");
        r && N(r, (o) => {
          const l = o.get("link");
          l.hover(), l.hideTooltip();
        });
      }
      let i = n.get("slice") || n.get("rectangle");
      i && i.get("tooltipText") && i.showTooltip();
    }), e("FlowNode").events.on("pointerout", (s) => {
      const n = s.target.dataItem;
      if (n) {
        const i = n.get("outgoingLinks");
        i && N(i, (r) => {
          r.get("link").unhover();
        });
        const a = n.get("incomingLinks");
        a && N(a, (r) => {
          r.get("link").unhover();
        });
      }
    }), e("Sankey").setAll({
      orientation: "horizontal",
      nodeAlign: "justify",
      linkTension: 0.5,
      nodePadding: 10,
      nodeWidth: 10
    }), e("RoundedRectangle", ["sankey", "node", "shape"]).setAll({
      cornerRadiusTL: 0,
      cornerRadiusBL: 0,
      cornerRadiusTR: 0,
      cornerRadiusBR: 0
    }), e("RoundedRectangle", ["shape"]).states.create("disabled", {
      fill: t.get("disabled")
    }), e("SankeyLink").setAll({
      controlPointDistance: 0.2
    }), e("FlowNode", ["sankey"]).setAll({
      draggable: !0
    });
    {
      const s = e("Graphics", ["sankey", "link"]);
      s.setAll({
        fillOpacity: 0.2,
        strokeOpacity: 0,
        interactive: !0,
        tooltipText: "{sourceId} - {targetId}: {value}"
      }), he(s, "fill", t, "grid");
    }
    e("Graphics", ["sankey", "link"]).states.create("hover", { fillOpacity: 0.5 }), e("Label", ["sankey", "node"]).setAll({
      text: "{name}",
      populateText: !0
    }), e("Label", ["sankey", "horizontal"]).setAll({
      y: I,
      centerY: I,
      paddingLeft: 15
    }), e("Label", ["sankey", "vertical"]).setAll({
      x: I,
      centerX: I,
      paddingTop: 15
    }), e("Chord").setAll({
      radius: ct(90),
      nodeWidth: 10,
      padAngle: 1,
      startAngle: 0,
      sort: "none"
    }), e("ChordDirected").setAll({
      linkHeadRadius: 10
    }), e("ChordNodes").setAll({
      x: I,
      y: I
    }), e("FlowNode", ["chord"]).setAll({
      draggable: !0
    }), e("ChordLink").setAll({
      sourceRadius: z,
      targetRadius: z,
      fillStyle: "solid",
      strokeStyle: "solid",
      tooltipText: "{sourceId} - {targetId}: {value}"
    }), e("Slice", ["chord", "node", "shape"]).setAll({
      cornerRadius: 0
    }), e("Slice", ["shape"]).states.create("disabled", {
      fill: t.get("disabled")
    }), e("RadialLabel", ["chord", "node"]).setAll({
      radius: 5,
      textType: "circular"
    }), e("ChordLinkDirected").setAll({
      headRadius: 10
    });
    {
      const s = e("Graphics", ["chord", "link", "shape"]);
      s.setAll({
        fillOpacity: 0.2,
        strokeOpacity: 0,
        interactive: !0
      }), he(s, "fill", t, "grid"), he(s, "stroke", t, "grid");
    }
    e("Graphics", ["chord", "link", "shape"]).states.create("hover", { fillOpacity: 0.5 }), e("ChordNonRibbon").setAll({
      linkType: "curve"
      // "line" | "curve"
    }), e("ChordLink", ["basic"]).setAll({
      fillStyle: "none",
      strokeStyle: "source"
    }), e("Graphics", ["chord", "link", "shape", "basic"]).setAll({
      strokeOpacity: 0.4
    }), e("Graphics", ["chord", "link", "shape", "basic"]).states.create("hover", { strokeWidth: 2, strokeOpacity: 1 }), e("ArcDiagram").setAll({
      orientation: "horizontal",
      nodePadding: 5,
      minRadius: 5,
      radiusKey: "sum",
      animationEasing: ht(gt)
    }), e("ArcDiagramNodes", ["horizontal"]).setAll({
      y: z,
      centerY: z
    }), e("ArcDiagramNodes", ["vertical"]).setAll({
      centerX: 0
    }), e("Circle", ["arcdiagram", "node", "shape"]).setAll({
      tooltipText: "{name}: {sum}"
    }), e("Circle", ["arcdiagram", "node", "shape"]).states.create("disabled", {
      fill: t.get("disabled")
    });
    {
      const s = e("ArcDiagramLink", ["link", "shape"]);
      s.setAll({
        strokeOpacity: 0.15,
        strokeStyle: "solid",
        fillStyle: "none",
        isMeasured: !1
      }), he(s, "stroke", t, "grid");
    }
    e("ArcDiagramLink", ["link", "shape"]).states.create("hover", {
      strokeOpacity: 1
    }), e("Label", ["arcdiagram", "node"]).setAll({
      text: "{name}",
      populateText: !0
    }), e("Label", ["arcdiagram", "horizontal"]).setAll({
      y: 0,
      centerY: I,
      centerX: z,
      rotation: -90
    }), e("Label", ["arcdiagram", "vertical"]).setAll({
      centerY: I,
      centerX: z,
      paddingRight: 15
    });
  }
}
class H extends ve {
  constructor() {
    super(...arguments), this.linksContainer = this.children.push(Ge.new(this._root, {})), this._nodesData = [], this._linksData = [], this._index = 0, this._nodesDataSet = !1, this._linksByIndex = {};
  }
  _afterNew() {
    this._defaultThemes.push(xt.new(this._root)), this.fields.push("disabled", "sourceId", "targetId"), this.nodes && (this.nodes.flow = this), super._afterNew(), this.children.push(this.bulletsContainer);
  }
  processDataItem(t) {
    super.processDataItem(t);
    const e = this.nodes;
    if (e) {
      let s = !1, n = t.get("sourceId"), i = e.getDataItemById(n);
      i || (n == null && (n = "undefined" + this._index, this._index++, s = !0), e.data.push({ id: n, unknown: s }), i = e.getDataItemById(n), s || i.set("name", n)), s = !1;
      let a = t.get("targetId"), r = e.getDataItemById(a);
      r || (a == null && (a = "undefined" + this._index, this._index++, s = !0), e.data.push({ id: a, unknown: s }), r = e.getDataItemById(a), s || r.set("name", a)), i && (t.set("source", i), e.addOutgoingLink(i, t)), r && (t.set("target", r), e.addincomingLink(r, t)), t.set("link", this.makeLink(t));
      const o = this.nodes.dataItems.indexOf(i), l = this.nodes.dataItems.indexOf(r);
      this._linksByIndex[o + "_" + l] = t, i.get("unknown") && (r && i.set("fill", r.get("fill")), t.get("link").set("fillStyle", "gradient")), r.get("unknown") && (i && r.set("fill", i.get("fill")), t.get("link").set("fillStyle", "gradient")), this._updateLinkColor(t);
    }
  }
  _onDataClear() {
    this.nodes._userDataSet || (this.nodes.data.setAll([]), this.nodes._userDataSet = !1);
  }
  _prepareChildren() {
    super._prepareChildren();
    let t = 1 / 0, e = -1 / 0, s = 0;
    if (this._valuesDirty) {
      this._nodesData = [];
      const n = this.nodes;
      n && N(n.dataItems, (i) => {
        const a = i.get("d3SankeyNode");
        this._nodesData.push(a);
        const r = i.get("incomingLinks");
        let o = 0, l = 0;
        r && N(r, (_) => {
          const p = _.get("value"), x = _.get("valueWorking");
          o += p, l += x;
        }), i.set("sumIncoming", o), i.set("sumIncomingWorking", l);
        const g = i.get("outgoingLinks");
        let f = 0, D = 0;
        g && N(g, (_) => {
          const p = _.get("value"), x = _.get("valueWorking");
          f += p, D += x;
        }), i.set("sumOutgoing", f), i.set("sumOutgoingWorking", D), i.set("sum", o + f), i.set("sumWorking", l + D), n.updateLegendValue(i);
      }), this._linksData = [], N(this.dataItems, (i) => {
        let a = i.get("value");
        $(a) && (a < t && (t = a), a > e && (e = a), s += a);
      }), N(this.dataItems, (i) => {
        let a = i.get("value");
        if ($(a)) {
          let r = i.get("valueWorking"), o = this.get("minSize", 0);
          o > 0 && r < o * s && (r = o * s);
          let l = { source: i.get("source").get("d3SankeyNode"), target: i.get("target").get("d3SankeyNode"), value: r };
          i.setRaw("d3SankeyLink", l), this._linksData.push(l), this.updateLegendValue(i);
        }
      }), this.setPrivateRaw("valueHigh", e), this.setPrivateRaw("valueLow", t), this.setPrivateRaw("valueSum", s);
    }
  }
  _updateLinkColor(t) {
    const e = t.get("link"), s = e.get("fillStyle"), n = e.get("strokeStyle"), i = t.get("source"), a = t.get("target"), r = i.get("fill"), o = a.get("fill");
    switch (e.remove("fillGradient"), e.remove("strokeGradient"), s) {
      case "solid":
        e._applyTemplates();
        break;
      case "source":
        e.set("fill", r);
        break;
      case "target":
        e.set("fill", o);
        break;
      case "gradient":
        let l = e._fillGradient;
        l || (l = Be.new(this._root, {}));
        const g = { color: r };
        i.get("unknown") && (g.opacity = 0);
        const f = { color: o };
        a.get("unknown") && (f.opacity = 0), l.set("stops", [g, f]), e._fillGradient = l, e.set("fillGradient", l);
        break;
      case "none":
        e.set("fill", void 0);
        break;
    }
    switch (n) {
      case "solid":
        e._applyTemplates();
        break;
      case "source":
        e.set("stroke", r);
        break;
      case "target":
        e.set("stroke", o);
        break;
      case "gradient":
        let l = e._strokeGradient;
        if (!l) {
          l = Be.new(this._root, {});
          const g = { color: r };
          i.get("unknown") && (g.opacity = 0);
          const f = { color: o };
          a.get("unknown") && (f.opacity = 0), l.set("stops", [g, f]), e._strokeGradient = l;
        }
        e.set("strokeGradient", l);
        break;
      case "none":
        e.remove("stroke");
        break;
    }
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    let e = t.get("link");
    e && (this.links.removeValue(e), e.dispose());
  }
  /**
   * Shows diagram's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  hideDataItem(t, e) {
    const s = Object.create(null, {
      hideDataItem: { get: () => super.hideDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.hideDataItem.call(this, t, e)], i = this.states.create("hidden", {}), a = "stateAnimationDuration", r = "stateAnimationEasing";
      $(e) || (e = i.get(a, this.get(a, 0)));
      const o = i.get(r, this.get(r));
      n.push(t.animate({
        key: "valueWorking",
        to: Math.max(this.get("minHiddenValue", 0), this.get("hiddenSize", 0) * t.get("value")),
        duration: e,
        easing: o
      }).waitForStop()), t.get("link").hide(), yield Promise.all(n);
    });
  }
  /**
   * Shows diagram's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  showDataItem(t, e) {
    const s = Object.create(null, {
      showDataItem: { get: () => super.showDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.showDataItem.call(this, t, e)];
      $(e) || (e = this.get("stateAnimationDuration", 0));
      const i = this.get("stateAnimationEasing");
      n.push(t.animate({ key: "valueWorking", to: t.get("value"), duration: e, easing: i }).waitForStop()), t.get("link").show(), yield Promise.all(n);
    });
  }
  _positionBullet(t) {
    const e = t.get("sprite");
    if (e) {
      const s = e.dataItem;
      if (s) {
        const n = s.get("link"), i = t.get("sprite");
        if (i) {
          const a = n.getPoint(this._getBulletLocation(t));
          i.setAll({ x: a.x, y: a.y }), t.get("autoRotate") && i.set("rotation", a.angle + t.get("autoRotateAngle", 0));
        }
      }
    }
  }
  _getBulletLocation(t) {
    return t.get("locationY", 0);
  }
}
H.className = "Flow";
H.classNames = ve.classNames.concat([H.className]);
var Ve = Math.abs, ne = Math.cos, ie = Math.sin, Ue = Math.PI, ue = Ue / 2, je = Ue * 2, Ee = Math.max, be = 1e-12;
function Ne(c, t) {
  return Array.from({ length: t - c }, (e, s) => c + s);
}
function vt(c) {
  return function(t, e) {
    return c(
      t.source.value + t.target.value,
      e.source.value + e.target.value
    );
  };
}
function Dt() {
  return et(!1);
}
function At() {
  return et(!0);
}
function et(c, t) {
  var e = 0, s = null, n = null, i = null;
  function a(r) {
    var o = r.length, l = new Array(o), g = Ne(0, o), f = new Array(o * o), D = new Array(o), _ = 0, p;
    r = Float64Array.from({ length: o * o }, (x, u) => r[u / o | 0][u % o]);
    for (let x = 0; x < o; ++x) {
      let u = 0;
      for (let b = 0; b < o; ++b) u += r[x * o + b] + c * r[b * o + x];
      _ += l[x] = u;
    }
    _ = Ee(0, je - e * o) / _, p = _ ? e : je / o;
    {
      let x = 0;
      s && g.sort((u, b) => s(l[u], l[b]));
      for (const u of g) {
        const b = x;
        if (c) {
          const S = Ne(~o + 1, o).filter((y) => y < 0 ? r[~y * o + u] : r[u * o + y]);
          n && S.sort((y, v) => n(y < 0 ? -r[~y * o + u] : r[u * o + y], v < 0 ? -r[~v * o + u] : r[u * o + v]));
          for (const y of S)
            if (y < 0) {
              const v = f[~y * o + u] || (f[~y * o + u] = { source: null, target: null });
              v.target = { index: u, startAngle: x, endAngle: x += r[~y * o + u] * _, value: r[~y * o + u] };
            } else {
              const v = f[u * o + y] || (f[u * o + y] = { source: null, target: null });
              v.source = { index: u, startAngle: x, endAngle: x += r[u * o + y] * _, value: r[u * o + y] };
            }
          D[u] = { index: u, startAngle: b, endAngle: x, value: l[u] };
        } else {
          const S = Ne(0, o).filter((y) => r[u * o + y] || r[y * o + u]);
          n && S.sort((y, v) => n(r[u * o + y], r[u * o + v]));
          for (const y of S) {
            let v;
            if (u < y ? (v = f[u * o + y] || (f[u * o + y] = { source: null, target: null }), v.source = { index: u, startAngle: x, endAngle: x += r[u * o + y] * _, value: r[u * o + y] }) : (v = f[y * o + u] || (f[y * o + u] = { source: null, target: null }), v.target = { index: u, startAngle: x, endAngle: x += r[u * o + y] * _, value: r[u * o + y] }, u === y && (v.source = v.target)), v.source && v.target && v.source.value < v.target.value) {
              const C = v.source;
              v.source = v.target, v.target = C;
            }
          }
          D[u] = { index: u, startAngle: b, endAngle: x, value: l[u] };
        }
        x += p;
      }
    }
    return f = Object.values(f), f.groups = D, i ? f.sort(i) : f;
  }
  return a.padAngle = function(r) {
    return arguments.length ? (e = Ee(0, r), a) : e;
  }, a.sortGroups = function(r) {
    return arguments.length ? (s = r, a) : s;
  }, a.sortSubgroups = function(r) {
    return arguments.length ? (n = r, a) : n;
  }, a.sortChords = function(r) {
    return arguments.length ? (r == null ? i = null : (i = vt(r))._ = r, a) : i && i._;
  }, a;
}
var bt = Array.prototype.slice;
function te(c) {
  return function() {
    return c;
  };
}
function Nt(c) {
  return c.source;
}
function Lt(c) {
  return c.target;
}
function He(c) {
  return c.radius;
}
function St(c) {
  return c.startAngle;
}
function Tt(c) {
  return c.endAngle;
}
function Ct() {
  return 0;
}
function Pt() {
  return 10;
}
function tt(c) {
  var t = Nt, e = Lt, s = He, n = He, i = St, a = Tt, r = Ct, o = null;
  function l() {
    var g, f = t.apply(this, arguments), D = e.apply(this, arguments), _ = r.apply(this, arguments) / 2, p = bt.call(arguments), x = +s.apply(this, (p[0] = f, p)), u = i.apply(this, p) - ue, b = a.apply(this, p) - ue, S = +n.apply(this, (p[0] = D, p)), y = i.apply(this, p) - ue, v = a.apply(this, p) - ue;
    if (o || (o = g = ut()), _ > be && (Ve(b - u) > _ * 2 + be ? b > u ? (u += _, b -= _) : (u -= _, b += _) : u = b = (u + b) / 2, Ve(v - y) > _ * 2 + be ? v > y ? (y += _, v -= _) : (y -= _, v += _) : y = v = (y + v) / 2), o.moveTo(x * ne(u), x * ie(u)), o.arc(0, 0, x, u, b), u !== y || b !== v)
      if (c) {
        var C = +c.apply(this, arguments), R = S - C, q = (y + v) / 2;
        o.quadraticCurveTo(0, 0, R * ne(y), R * ie(y)), o.lineTo(S * ne(q), S * ie(q)), o.lineTo(R * ne(v), R * ie(v));
      } else
        o.quadraticCurveTo(0, 0, S * ne(y), S * ie(y)), o.arc(0, 0, S, y, v);
    if (o.quadraticCurveTo(0, 0, x * ne(u), x * ie(u)), o.closePath(), g) return o = null, g + "" || null;
  }
  return c && (l.headRadius = function(g) {
    return arguments.length ? (c = typeof g == "function" ? g : te(+g), l) : c;
  }), l.radius = function(g) {
    return arguments.length ? (s = n = typeof g == "function" ? g : te(+g), l) : s;
  }, l.sourceRadius = function(g) {
    return arguments.length ? (s = typeof g == "function" ? g : te(+g), l) : s;
  }, l.targetRadius = function(g) {
    return arguments.length ? (n = typeof g == "function" ? g : te(+g), l) : n;
  }, l.startAngle = function(g) {
    return arguments.length ? (i = typeof g == "function" ? g : te(+g), l) : i;
  }, l.endAngle = function(g) {
    return arguments.length ? (a = typeof g == "function" ? g : te(+g), l) : a;
  }, l.padAngle = function(g) {
    return arguments.length ? (r = typeof g == "function" ? g : te(+g), l) : r;
  }, l.source = function(g) {
    return arguments.length ? (t = g, l) : t;
  }, l.target = function(g) {
    return arguments.length ? (e = g, l) : e;
  }, l.context = function(g) {
    return arguments.length ? (o = g ?? null, l) : o;
  }, l;
}
function st() {
  return tt();
}
function Ye() {
  return tt(Pt);
}
function Rt(c, t) {
  return c == null || t == null ? NaN : c < t ? -1 : c > t ? 1 : c >= t ? 0 : NaN;
}
function Gt(c, t) {
  return c == null || t == null ? NaN : t < c ? -1 : t > c ? 1 : t >= c ? 0 : NaN;
}
class fe extends Ge {
}
fe.className = "FlowNode";
fe.classNames = Ge.classNames.concat([fe.className]);
class Y extends ve {
  constructor() {
    super(...arguments), this.labels = this.addDisposer(new O(B.new({}), () => Qe._new(this._root, { themeTags: ["flow"] }, [this.labels.template]))), this.nodes = this.addDisposer(new O(B.new({}), () => fe._new(this._root, { themeTags: ["node"] }, [this.nodes.template]))), this._userDataSet = !1;
  }
  _applyThemes(t = !1) {
    const e = this.get("colors");
    return e && e.reset(), super._applyThemes(t);
  }
  _afterNew() {
    this.fields.push("unknown", "name", "fill"), this.set("idField", "id"), this.set("nameField", "id"), this.set("fillField", "fill"), this.set("unknownField", "unknown"), this.children.push(this.bulletsContainer), super._afterNew();
  }
  _onDataClear() {
    const t = this.get("colors");
    t && t.reset();
    const e = this.get("patterns");
    e && e.reset(), this._userDataSet = !0;
  }
  processDataItem(t) {
    if (super.processDataItem(t), t.setRaw("d3SankeyNode", { name: t.get("id"), dataItem: t }), t.get("fill") == null) {
      let n = this.get("colors");
      n && t.setRaw("fill", n.next());
    }
    if (t.get("fillPattern") == null) {
      let n = this.get("patterns");
      n && t.setRaw("fillPattern", n.next());
    }
    const e = this.makeNode(t);
    t.setRaw("node", e);
    const s = this.get("disabledField");
    if (s) {
      const n = t.dataContext;
      n && n[s] && this.root.events.once("frameended", () => {
        this.disableDataItem(t, 0);
      });
    }
  }
  /**
   * @ignore
   */
  makeNode(t, e) {
    const s = this.nodes.make();
    return this.nodes.push(s), e && s.addTag(e), t.get("unknown") && s.addTag("unknown"), this.children.push(s), s._setDataItem(t), s.series = this, s.events.on("click", (n) => {
      const i = n.target;
      if (i.get("toggleKey") == "disabled") {
        const a = i.dataItem;
        a && (a.isHidden() ? this.enableDataItem(a) : this.disableDataItem(a));
      }
    }), t.on("fill", () => {
      this._updateNodeColor(t);
    }), t.on("fillPattern", () => {
      this._updateNodeColor(t);
    }), t.set("node", s), s;
  }
  _updateNodeColor(t) {
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    let e = t.get("node");
    e && (this.nodes.removeValue(e), e.dispose());
    let s = t.get("label");
    s && (this.labels.removeValue(s), s.dispose());
  }
  /**
   * @ignore
   */
  addincomingLink(t, e) {
    let s = t.get("incomingLinks");
    s || (s = [], t.set("incomingLinks", s)), s.push(e);
  }
  /**
   * @ignore
   */
  addOutgoingLink(t, e) {
    let s = t.get("outgoingLinks");
    s || (s = [], t.set("outgoingLinks", s)), s.push(e);
  }
  /**
   * Shows node's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  showDataItem(t, e) {
    const s = Object.create(null, {
      showDataItem: { get: () => super.showDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.showDataItem.call(this, t, e)], i = this.flow;
      if (i) {
        const a = t.get("node");
        a && a.show();
        let r = t.get("label");
        r && r.show(e);
        let o = t.get("outgoingLinks");
        o && N(o, (l) => {
          i.showDataItem(l, e);
        }), o = t.get("incomingLinks"), o && N(o, (l) => {
          i.showDataItem(l, e);
        });
      }
      yield n;
    });
  }
  /**
   * Hides series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  hideDataItem(t, e) {
    const s = Object.create(null, {
      hideDataItem: { get: () => super.hideDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.hideDataItem.call(this, t, e)], i = this.flow;
      if (i) {
        const a = t.get("node");
        a && a.hide();
        let r = t.get("label");
        r && r.hide(e);
        let o = t.get("outgoingLinks");
        o && N(o, (l) => {
          i.hideDataItem(l, e);
        }), o = t.get("incomingLinks"), o && N(o, (l) => {
          i.hideDataItem(l, e);
        });
      }
      yield n;
    });
  }
  /**
   * Shows node's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  enableDataItem(t, e) {
    const s = Object.create(null, {
      showDataItem: { get: () => super.showDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.showDataItem.call(this, t, e)], i = this.flow;
      if (i) {
        const a = t.get("node");
        a && this.root.events.once("frameended", () => {
          a.set("disabled", !1);
        });
        let r = t.get("label");
        r && r.set("disabled", !1);
        let o = t.get("outgoingLinks");
        o && N(o, (l) => {
          i.showDataItem(l, e);
        }), o = t.get("incomingLinks"), o && N(o, (l) => {
          i.showDataItem(l, e);
        });
      }
      yield n;
    });
  }
  /**
   * Hides series's data item.
   *
   * @param   dataItem  Data item
   * @param   duration  Animation duration in milliseconds
   * @return            Promise
   */
  disableDataItem(t, e) {
    const s = Object.create(null, {
      hideDataItem: { get: () => super.hideDataItem }
    });
    return oe(this, void 0, void 0, function* () {
      const n = [s.hideDataItem.call(this, t, e)], i = this.flow;
      if (i) {
        const a = t.get("node");
        a && this.root.events.once("frameended", () => {
          a.set("disabled", !0);
        });
        let r = t.get("label");
        r && r.set("disabled", !0);
        let o = t.get("outgoingLinks");
        o && N(o, (l) => {
          i.hideDataItem(l, e);
        }), o = t.get("incomingLinks"), o && N(o, (l) => {
          i.hideDataItem(l, e);
        });
      }
      yield n;
    });
  }
}
Y.className = "FlowNodes";
Y.classNames = ve.classNames.concat([Y.className]);
class pe extends Y {
  constructor() {
    super(...arguments), this.labels = this.addDisposer(new O(B.new({}), () => _t._new(this._root, {}, [this.labels.template]))), this._dAngle = 0, this.slices = this.addDisposer(new O(B.new({}), () => yt._new(this._root, { themeTags: ["shape"] }, [this.slices.template]))), this.rectangles = this.slices;
  }
  /**
   * @ignore
   */
  makeNode(t) {
    const e = super.makeNode(t, "chord"), s = e.children.insertIndex(0, this.slices.make());
    t.set("slice", s), s._setSoft("fill", t.get("fill")), s._setSoft("fillPattern", t.get("fillPattern"));
    const n = this.labels.make();
    return this.labels.push(n), n.addTag("flow"), n.addTag("chord"), n.addTag("node"), e.children.push(n), t.set("label", n), e.events.on("dragstart", (i) => {
      let a = this.toLocal(i.point);
      const r = re({ x: 0, y: 0 }, a);
      this.flow && (this._dAngle = this.flow.get("startAngle", 0) - r);
    }), e.events.on("dragged", (i) => {
      let a = this.toLocal(i.point);
      const r = re({ x: 0, y: 0 }, a);
      e.setAll({ x: 0, y: 0 }), this.flow && this.flow.set("startAngle", r + this._dAngle);
    }), n._setDataItem(t), s._setDataItem(t), e;
  }
  _positionBullet(t) {
    const e = t.get("sprite");
    if (e) {
      const s = e.dataItem;
      if (s) {
        const n = t.get("sprite");
        if (n) {
          const i = s.get("slice"), a = t.get("locationX", 0.5), r = t.get("locationY", 0.5);
          if (i) {
            const o = i.get("radius", 0), l = i.get("innerRadius", 0), g = l + (o - l) * r, f = i.get("startAngle", 0) + i.get("arc", 0) * a;
            n.setAll({ x: g * M(f), y: g * G(f) });
          }
        }
      }
    }
  }
  _updateNodeColor(t) {
    const e = t.get("slice");
    e && (e.set("fill", t.get("fill")), e.set("fillPattern", t.get("fillPattern")));
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    let e = t.get("slice");
    e && (this.slices.removeValue(e), e.dispose());
  }
}
pe.className = "ChordNodes";
pe.classNames = Y.classNames.concat([pe.className]);
class X extends Ze {
  _changed() {
    if (super._changed(), this.isDirty("fillStyle")) {
      const t = this.series, e = this.dataItem;
      t && e && t._updateLinkColor(e);
    }
  }
  _getTooltipPoint() {
    let t = this.get("tooltipY"), e = 0.5;
    return t instanceof dt && (e = t.value), this.getPoint(e);
  }
}
X.className = "FlowLink";
X.classNames = Ze.classNames.concat([X.className]);
class ae extends X {
  getPoint(t) {
    if (this._p0 && this._p1)
      if (this._type === "line") {
        let e = ft(this._p0, this._p1, t);
        return { x: e.x, y: e.y, angle: re(this._p0, this._p1) };
      } else {
        let e = De(this._p0, this._p1, { x: 0, y: 0 }, Math.max(0, t - 0.01)), s = De(this._p0, this._p1, { x: 0, y: 0 }, Math.min(1, t + 0.01)), n = De(this._p0, this._p1, { x: 0, y: 0 }, t);
        return { x: n.x, y: n.y, angle: re(e, s) };
      }
    return { x: 0, y: 0, angle: 0 };
  }
}
ae.className = "ChordLink";
ae.classNames = X.classNames.concat([ae.className]);
class se extends H {
  constructor() {
    super(...arguments), this.links = this.addDisposer(new O(B.new({}), () => ae._new(this._root, { themeTags: ["link", "shape"] }, [this.links.template]))), this.nodes = this.children.push(pe.new(this._root, {})), this._d3chord = Dt(), this._chordLayout = [], this._ribbon = st();
  }
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["chord"]), this.linksContainer.setAll({ x: I, y: I }), this.bulletsContainer.setAll({ x: I, y: I }), super._afterNew();
  }
  _fixRibbon(t) {
    t.startAngle((e) => e.startAngle + this.get("startAngle", 0) * ge + Math.PI / 2), t.endAngle((e) => e.endAngle + this.get("startAngle", 0) * ge + Math.PI / 2);
  }
  /**
   * @ignore
   */
  makeLink(t) {
    const e = this.linksContainer.children.push(this.links.make());
    return this.links.push(e), e._setDataItem(t), e.set("source", t.get("source")), e.set("target", t.get("target")), e.series = this, e;
  }
  _makeMatrix() {
    const t = [];
    return N(this.nodes.dataItems, (e) => {
      const s = [];
      t.push(s);
      let n = e.get("outgoingLinks");
      N(this.nodes.dataItems, (i) => {
        let a = 0;
        n && N(n, (r) => {
          r.get("target") === i && (a = r.get("valueWorking"));
          let o = this.getPrivate("valueSum", 0), l = this.get("minSize", 0);
          a > 0 && l > 0 && a < o * l && (a = o * l);
        }), s.push(a);
      });
    }), t;
  }
  _prepareChildren() {
    super._prepareChildren(), this._fixRibbon(this._ribbon);
    let t = !1;
    if (this._valuesDirty || this._sizeDirty || this.isDirty("padAngle") || this.isDirty("startAngle")) {
      const e = this._makeMatrix();
      this._d3chord.padAngle(this.get("padAngle", 0) * ge);
      const s = this.get("sort");
      s === "ascending" ? this._d3chord.sortGroups(Rt) : s === "descending" && this._d3chord.sortGroups(Gt), this._chordLayout = this._d3chord(e), t = !0;
    }
    if (t || this.isDirty("radius") || this.isDirty("nodeWidth")) {
      let e = Ae(this.get("radius", 0), Math.min(this.innerWidth(), this.innerHeight())) / 2, s = 0;
      const n = this.get("startAngle", 0), i = this.get("nodeWidth", 0);
      N(this.nodes.dataItems, (r) => {
        const o = r.get("slice"), l = this._chordLayout.groups[s], g = l.startAngle * Fe + n, f = l.endAngle * Fe + n;
        o.setAll({ radius: e, innerRadius: e - i, startAngle: g, arc: f - g });
        const D = r.get("label");
        D.setAll({ labelAngle: g + (f - g) / 2 }), D.setPrivate("radius", e), D.setPrivate("innerRadius", 0.1), s++;
      });
      const a = e - this.get("nodeWidth", 0);
      N(this._chordLayout, (r) => {
        let o = this._linksByIndex[r.source.index + "_" + r.target.index];
        if (o || (o = this._linksByIndex[r.target.index + "_" + r.source.index]), o) {
          const l = o.get("link");
          this._getLinkPoints(l, a, r), this._updateLink(this._ribbon, l, a, r);
        }
      });
    }
  }
  _getLinkPoints(t, e, s) {
    const n = s.source, i = s.target, a = this.get("startAngle", 0) * ge;
    if (n && i) {
      const r = n.startAngle, o = n.endAngle, l = r + (o - r) / 2 + a, g = i.startAngle, f = i.endAngle, D = g + (f - g) / 2 + a;
      t._p0 = { x: e * Math.cos(l), y: e * Math.sin(l) }, t._p1 = { x: e * Math.cos(D), y: e * Math.sin(D) };
    }
  }
  _updateLink(t, e, s, n) {
    n && (t.sourceRadius(Ae(e.get("sourceRadius", z), s)), t.targetRadius(Ae(e.get("targetRadius", z), s)), e.set("draw", (i) => {
      t.context(i), t(n);
    }));
  }
}
se.className = "Chord";
se.classNames = H.classNames.concat([se.className]);
class ke extends ae {
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["chord", "link", "directed"]), super._afterNew();
  }
}
ke.className = "ChordLinkDirected";
ke.classNames = ae.classNames.concat([ke.className]);
class Te extends se {
  constructor() {
    super(...arguments), this._d3chord = At(), this._ribbonArrow = Ye(), this.links = this.addDisposer(new O(B.new({}), () => ke._new(this._root, { themeTags: ["link", "shape"] }, [this.links.template])));
  }
  /**
   * @ignore
   */
  makeLink(t) {
    const e = this.linksContainer.children.push(this.links.make());
    return e._setDataItem(t), e.set("source", t.get("source")), e.set("target", t.get("target")), e.series = this, e;
  }
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["directed"]), super._afterNew(), this._markDirtyKey("linkHeadRadius");
  }
  _prepareChildren() {
    const t = "linkHeadRadius";
    if (this.isDirty(t)) {
      const e = this.get(t);
      if (e == null)
        this._ribbon = st();
      else {
        let s = Ye();
        s.headRadius(e), this._ribbon = s;
      }
    }
    super._prepareChildren();
  }
}
Te.className = "ChordDirected";
Te.classNames = se.classNames.concat([Te.className]);
class Ce extends se {
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["chord", "basic"]), super._afterNew();
  }
  _makeMatrix() {
    const t = [];
    return N(this.nodes.dataItems, (e) => {
      const s = [];
      t.push(s), N(this.nodes.dataItems, (n) => {
        let i = 1;
        e === n && (i = 0), s.push(i);
      });
    }), t;
  }
  _updateLink(t, e, s, n) {
    if (e._type = this.get("linkType"), n) {
      const i = this.get("linkType");
      e.set("draw", (a) => {
        let r = e._p0, o = e._p1;
        r && o && (a.moveTo(r.x, r.y), i == "line" ? a.lineTo(o.x, o.y) : a.quadraticCurveTo(0, 0, o.x, o.y));
      });
    }
  }
  _getLinkPoints(t, e, s) {
    const n = t.get("source"), i = t.get("target");
    if (n && i) {
      const a = n.get("slice"), r = i.get("slice"), o = a.get("startAngle", 0), l = a.get("arc", 0), g = o + l / 2, f = r.get("startAngle", 0), D = r.get("arc", 0), _ = f + D / 2;
      t._p0 = { x: e * M(g), y: e * G(g) }, t._p1 = { x: e * M(_), y: e * G(_) };
    }
  }
}
Ce.className = "ChordNonRibbon";
Ce.classNames = se.classNames.concat([Ce.className]);
class me extends Y {
  constructor() {
    super(...arguments), this.rectangles = this.addDisposer(new O(B.new({}), () => pt._new(this._root, { themeTags: ["shape"] }, [this.rectangles.template])));
  }
  /**
   * @ignore
   */
  makeNode(t) {
    const e = this.flow, s = super.makeNode(t, "sankey"), n = s.children.insertIndex(0, this.rectangles.make());
    this.rectangles.push(n), n._setSoft("fill", t.get("fill")), n._setSoft("fillPattern", t.get("fillPattern")), t.set("rectangle", n), s.events.on("dragged", () => {
      const a = s.dataItem.get("d3SankeyNode");
      a && e && (e.get("orientation") == "horizontal" ? (a.x0 = s.x(), a.y0 = s.y()) : (a.x0 = s.y(), a.y0 = s.x()), e.updateSankey());
    });
    const i = this.labels.make();
    return this.labels.push(i), e && i.addTag(e.get("orientation", "")), s.children.push(i), t.set("label", i), i._setDataItem(t), n._setDataItem(t), s;
  }
  _positionBullet(t) {
    const e = t.get("sprite");
    if (e) {
      const s = e.dataItem;
      if (s) {
        const n = t.get("sprite");
        if (n) {
          const i = s.get("rectangle"), a = s.get("node"), r = t.get("locationX", 0.5), o = t.get("locationY", 0.5);
          i && n.setAll({ x: a.x() + i.width() * r, y: a.y() + i.height() * o });
        }
      }
    }
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    let e = t.get("rectangle");
    e && (this.rectangles.removeValue(e), e.dispose());
  }
  _updateNodeColor(t) {
    const e = t.get("rectangle");
    e && (e.set("fill", t.get("fill")), e.set("fillPattern", t.get("fillPattern")));
  }
}
me.className = "SankeyNodes";
me.classNames = Y.classNames.concat([me.className]);
class ye extends X {
  constructor() {
    super(...arguments), this._svgPath = document.createElementNS("http://www.w3.org/2000/svg", "path"), this._totalLength = 0;
  }
  _beforeChanged() {
    if (super._beforeChanged(), this.isDirty("source")) {
      const i = this.get("source");
      if (i) {
        const a = i.get("node");
        this._disposers.push(a.events.on("positionchanged", () => {
          this.markDirty();
        }));
      }
    }
    if (this.isDirty("target")) {
      const i = this.get("target");
      if (i) {
        const a = i.get("node");
        this._disposers.push(a.events.on("positionchanged", () => {
          this.markDirty();
        }));
      }
    }
    if (this.isPrivateDirty("orientation")) {
      const i = this.series, a = this.dataItem;
      a && i && i._updateLinkColor(a);
    }
    const t = this.get("target"), e = this.get("source");
    let s, n;
    if (e && t) {
      this._clear = !0, s = e.get("node"), n = t.get("node");
      let i = 0, a = 0, r = 0, o = 0, l = 0, g = 0, f = 0, D = 0, _ = 0, p = 0, x = 0, u = 0, b = 0, S = 0, y = 0, v = 0, C = 0, R = 0;
      const q = this.dataItem;
      if (q) {
        const V = q.get("d3SankeyLink");
        if (V) {
          let P = V.width || 0, ce = this.getPrivate("orientation");
          ce == "vertical" ? (s && (r = s.y() + s.get("dy", 0)), n && (o = n.y() + n.get("dy", 0)), C = 90, R = 90, i = V.y0 || 0, a = V.y1 || 0, i += s.get("dx", 0), a += n.get("dx", 0), o < r && ([i, a] = [a, i], [r, o] = [o, r]), e.get("unknown") && (i = a, r = r + (o - r) / 2), t.get("unknown") && (a = i, o = r + (o - r) / 2), l = i - P / 2, g = r, f = a - P / 2, D = o, _ = i + P / 2, p = a + P / 2, x = r, u = o, b = i, S = a, y = r, v = o) : (s && (i = s.x() + s.get("dx", 0)), n && (a = n.x() + n.get("dx", 0)), r = V.y0 || 0, o = V.y1 || 0, r += s.get("dy", 0), o += n.get("dy", 0), a < i && ([i, a] = [a, i], [r, o] = [o, r]), e.get("unknown") && (r = o, i = i + (a - i) / 2), t.get("unknown") && (o = r, a = i + (a - i) / 2), l = i, g = r - P / 2, f = a, D = o - P / 2, _ = i, p = a, x = r + P / 2, u = o + P / 2, b = i, S = a, y = r, v = o), K(l, 3) == K(f, 3) && (f += 0.01), K(g, 3) == K(D, 3) && (D += 0.01), K(_, 3) == K(p, 3) && (p += 0.01), K(x, 3) == K(u, 3) && (u += 0.01);
          let T = this.get("controlPointDistance", 0.2);
          T = Math.min(0.4999, T);
          let J = l + (f - l) * T * M(C), Q = g + (D - g) * T * G(C), Z = f - (f - l) * T * M(R), h = D - (D - g) * T * G(R), w = b + (S - b) * T * M(C), k = y + (v - y) * T * G(C), m = S - (S - b) * T * M(R), d = v - (v - y) * T * G(R), A = re({ x: J, y: Q }, { x: Z, y: h }), L = (P / M(A) - P) / Oe(A) * M(C), W = (P / G(A) - P) * Oe(A) * G(C), F = -L / 2 + _ + (p - _) * T * M(C), j = -W / 2 + x + (u - x) * T * G(C), E = -L / 2 + p - (p - _) * T * M(R), U = -W / 2 + u - (u - x) * T * G(R);
          J += L / 2, Q += W / 2, Z += L / 2, h += W / 2, ce == "vertical" ? (Q = Math.min(D, Math.max(g + 1, Q)), j = Math.min(u, Math.max(x + 1, j)), h = Math.max(g, Math.min(D - 1, h)), U = Math.max(x, Math.min(u - 1, U))) : (J = Math.min(f, Math.max(l + 1, J)), F = Math.min(p, Math.max(_ + 1, F)), Z = Math.max(l, Math.min(f - 1, Z)), E = Math.max(_, Math.min(p - 1, E)));
          let ee = [[l, g, _, x], [J, Q, F, j], [Z, h, E, U], [f, D, p, u]];
          this.set("draw", (rt) => {
            const Ie = this.series;
            Ie._fillGenerator.context(rt), Ie._fillGenerator(ee);
          });
          let ot = [[b, y], [w, k], [m, d], [S, v]];
          const Me = this.series._strokeGenerator(ot);
          Me && (this._svgPath.setAttribute("d", Me), this._totalLength = this._svgPath.getTotalLength());
        }
      }
    }
    this.series && this.dataItem && this.series._positionBullets(this.dataItem);
  }
  getPoint(t) {
    if (this._svgPath && this._svgPath.getAttribute("d")) {
      let e = this._svgPath.getPointAtLength(t * this._totalLength - 0.1), s = this._svgPath.getPointAtLength(t * this._totalLength + 0.1), n = this.toGlobal(this._svgPath.getPointAtLength(t * this._totalLength));
      return { x: n.x, y: n.y, angle: re(e, s) };
    }
    return { x: 0, y: 0, angle: 0 };
  }
  _getTooltipPoint() {
    return this.toLocal(super._getTooltipPoint());
  }
}
ye.className = "SankeyLink";
ye.classNames = X.classNames.concat([ye.className]);
function Xe(c, t) {
  let e;
  if (t === void 0)
    for (const s of c)
      s != null && (e < s || e === void 0 && s >= s) && (e = s);
  else {
    let s = -1;
    for (let n of c)
      (n = t(n, ++s, c)) != null && (e < n || e === void 0 && n >= n) && (e = n);
  }
  return e;
}
function nt(c, t) {
  let e;
  if (t === void 0)
    for (const s of c)
      s != null && (e > s || e === void 0 && s >= s) && (e = s);
  else {
    let s = -1;
    for (let n of c)
      (n = t(n, ++s, c)) != null && (e > n || e === void 0 && n >= n) && (e = n);
  }
  return e;
}
function Le(c, t) {
  let e = 0;
  if (t === void 0)
    for (let s of c)
      (s = +s) && (e += s);
  else {
    let s = -1;
    for (let n of c)
      (n = +t(n, ++s, c)) && (e += n);
  }
  return e;
}
function Mt(c) {
  return c.target.depth;
}
function It(c) {
  return c.depth;
}
function Ft(c, t) {
  return t - 1 - c.height;
}
function it(c, t) {
  return c.sourceLinks.length ? c.depth : t - 1;
}
function Ot(c) {
  return c.targetLinks.length ? c.depth : c.sourceLinks.length ? nt(c.sourceLinks, Mt) - 1 : 0;
}
function de(c) {
  return function() {
    return c;
  };
}
function Ke(c, t) {
  return _e(c.source, t.source) || c.index - t.index;
}
function $e(c, t) {
  return _e(c.target, t.target) || c.index - t.index;
}
function _e(c, t) {
  return c.y0 - t.y0;
}
function Se(c) {
  return c.value;
}
function Bt(c) {
  return c.index;
}
function Wt(c) {
  return c.nodes;
}
function zt(c) {
  return c.links;
}
function qe(c, t) {
  const e = c.get(t);
  if (!e) throw new Error("missing: " + t);
  return e;
}
function Je({ nodes: c }) {
  for (const t of c) {
    let e = t.y0, s = e;
    for (const n of t.sourceLinks)
      n.y0 = e + n.width / 2, e += n.width;
    for (const n of t.targetLinks)
      n.y1 = s + n.width / 2, s += n.width;
  }
}
function Vt() {
  let c = 0, t = 0, e = 1, s = 1, n = 24, i = 8, a, r = Bt, o = it, l, g, f = Wt, D = zt, _ = 6;
  function p() {
    const h = { nodes: f.apply(null, arguments), links: D.apply(null, arguments) };
    return x(h), u(h), b(h), S(h), C(h), Je(h), h;
  }
  p.update = function(h) {
    return Je(h), h;
  }, p.nodeId = function(h) {
    return arguments.length ? (r = typeof h == "function" ? h : de(h), p) : r;
  }, p.nodeAlign = function(h) {
    return arguments.length ? (o = typeof h == "function" ? h : de(h), p) : o;
  }, p.nodeSort = function(h) {
    return arguments.length ? (l = h, p) : l;
  }, p.nodeWidth = function(h) {
    return arguments.length ? (n = +h, p) : n;
  }, p.nodePadding = function(h) {
    return arguments.length ? (i = a = +h, p) : i;
  }, p.nodes = function(h) {
    return arguments.length ? (f = typeof h == "function" ? h : de(h), p) : f;
  }, p.links = function(h) {
    return arguments.length ? (D = typeof h == "function" ? h : de(h), p) : D;
  }, p.linkSort = function(h) {
    return arguments.length ? (g = h, p) : g;
  }, p.size = function(h) {
    return arguments.length ? (c = t = 0, e = +h[0], s = +h[1], p) : [e - c, s - t];
  }, p.extent = function(h) {
    return arguments.length ? (c = +h[0][0], e = +h[1][0], t = +h[0][1], s = +h[1][1], p) : [[c, t], [e, s]];
  }, p.iterations = function(h) {
    return arguments.length ? (_ = +h, p) : _;
  };
  function x({ nodes: h, links: w }) {
    for (const [m, d] of h.entries())
      d.index = m, d.sourceLinks = [], d.targetLinks = [];
    const k = new Map(h.map((m, d) => [r(m, d, h), m]));
    for (const [m, d] of w.entries()) {
      d.index = m;
      let { source: A, target: L } = d;
      typeof A != "object" && (A = d.source = qe(k, A)), typeof L != "object" && (L = d.target = qe(k, L)), A.sourceLinks.push(d), L.targetLinks.push(d);
    }
    if (g != null)
      for (const { sourceLinks: m, targetLinks: d } of h)
        m.sort(g), d.sort(g);
  }
  function u({ nodes: h }) {
    for (const w of h)
      w.value = w.fixedValue === void 0 ? Math.max(Le(w.sourceLinks, Se), Le(w.targetLinks, Se)) : w.fixedValue;
  }
  function b({ nodes: h }) {
    const w = h.length;
    let k = new Set(h), m = /* @__PURE__ */ new Set(), d = 0;
    for (; k.size; ) {
      for (const A of k) {
        A.depth = d;
        for (const { target: L } of A.sourceLinks)
          m.add(L);
      }
      if (++d > w) throw new Error("circular link");
      k = m, m = /* @__PURE__ */ new Set();
    }
  }
  function S({ nodes: h }) {
    const w = h.length;
    let k = new Set(h), m = /* @__PURE__ */ new Set(), d = 0;
    for (; k.size; ) {
      for (const A of k) {
        A.height = d;
        for (const { source: L } of A.targetLinks)
          m.add(L);
      }
      if (++d > w) throw new Error("circular link");
      k = m, m = /* @__PURE__ */ new Set();
    }
  }
  function y({ nodes: h }) {
    const w = Xe(h, (d) => d.depth) + 1, k = (e - c - n) / (w - 1), m = new Array(w);
    for (const d of h) {
      const A = Math.max(0, Math.min(w - 1, Math.floor(o.call(null, d, w))));
      d.layer = A, d.x0 = c + A * k, d.x1 = d.x0 + n, m[A] ? m[A].push(d) : m[A] = [d];
    }
    if (l) for (const d of m)
      d.sort(l);
    return m;
  }
  function v(h) {
    const w = nt(h, (k) => (s - t - (k.length - 1) * a) / Le(k, Se));
    for (const k of h) {
      let m = t;
      for (const d of k) {
        d.y0 = m, d.y1 = m + d.value * w, m = d.y1 + a;
        for (const A of d.sourceLinks)
          A.width = A.value * w;
      }
      m = (s - m + a) / (k.length + 1);
      for (let d = 0; d < k.length; ++d) {
        const A = k[d];
        A.y0 += m * (d + 1), A.y1 += m * (d + 1);
      }
      J(k);
    }
  }
  function C(h) {
    const w = y(h);
    a = Math.min(i, (s - t) / (Xe(w, (k) => k.length) - 1)), v(w);
    for (let k = 0; k < _; ++k) {
      const m = Math.pow(0.99, k), d = Math.max(1 - m, (k + 1) / _);
      q(w, m, d), R(w, m, d);
    }
  }
  function R(h, w, k) {
    for (let m = 1, d = h.length; m < d; ++m) {
      const A = h[m];
      for (const L of A) {
        let W = 0, F = 0;
        for (const { source: E, value: U } of L.targetLinks) {
          let ee = U * (L.layer - E.layer);
          W += Q(E, L) * ee, F += ee;
        }
        if (!(F > 0)) continue;
        let j = (W / F - L.y0) * w;
        L.y0 += j, L.y1 += j, T(L);
      }
      l === void 0 && A.sort(_e), V(A, k);
    }
  }
  function q(h, w, k) {
    for (let m = h.length, d = m - 2; d >= 0; --d) {
      const A = h[d];
      for (const L of A) {
        let W = 0, F = 0;
        for (const { target: E, value: U } of L.sourceLinks) {
          let ee = U * (E.layer - L.layer);
          W += Z(L, E) * ee, F += ee;
        }
        if (!(F > 0)) continue;
        let j = (W / F - L.y0) * w;
        L.y0 += j, L.y1 += j, T(L);
      }
      l === void 0 && A.sort(_e), V(A, k);
    }
  }
  function V(h, w) {
    const k = h.length >> 1, m = h[k];
    ce(h, m.y0 - a, k - 1, w), P(h, m.y1 + a, k + 1, w), ce(h, s, h.length - 1, w), P(h, t, 0, w);
  }
  function P(h, w, k, m) {
    for (; k < h.length; ++k) {
      const d = h[k], A = (w - d.y0) * m;
      A > 1e-6 && (d.y0 += A, d.y1 += A), w = d.y1 + a;
    }
  }
  function ce(h, w, k, m) {
    for (; k >= 0; --k) {
      const d = h[k], A = (d.y1 - w) * m;
      A > 1e-6 && (d.y0 -= A, d.y1 -= A), w = d.y0 - a;
    }
  }
  function T({ sourceLinks: h, targetLinks: w }) {
    if (g === void 0) {
      for (const { source: { sourceLinks: k } } of w)
        k.sort($e);
      for (const { target: { targetLinks: k } } of h)
        k.sort(Ke);
    }
  }
  function J(h) {
    if (g === void 0)
      for (const { sourceLinks: w, targetLinks: k } of h)
        w.sort($e), k.sort(Ke);
  }
  function Q(h, w) {
    let k = h.y0 - (h.sourceLinks.length - 1) * a / 2;
    for (const { target: m, width: d } of h.sourceLinks) {
      if (m === w) break;
      k += d + a;
    }
    for (const { source: m, width: d } of w.targetLinks) {
      if (m === h) break;
      k -= d;
    }
    return k;
  }
  function Z(h, w) {
    let k = w.y0 - (w.targetLinks.length - 1) * a / 2;
    for (const { source: m, width: d } of w.targetLinks) {
      if (m === h) break;
      k += d + a;
    }
    for (const { target: m, width: d } of h.sourceLinks) {
      if (m === w) break;
      k -= d;
    }
    return k;
  }
  return p;
}
class Pe extends H {
  constructor() {
    super(...arguments), this.links = this.addDisposer(new O(B.new({}), () => ye._new(this._root, { themeTags: ["link", "shape"] }, [this.links.template]))), this.nodes = this.children.push(me.new(this._root, {})), this._d3Sankey = Vt(), this._fillGenerator = kt(), this._strokeGenerator = mt();
  }
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["sankey", this._settings.orientation || "horizontal"]), this._fillGenerator.y0(function(t) {
      return t[3];
    }), this._fillGenerator.x0(function(t) {
      return t[2];
    }), this._fillGenerator.y1(function(t) {
      return t[1];
    }), this._fillGenerator.x1(function(t) {
      return t[0];
    }), super._afterNew();
  }
  /**
   * @ignore
   */
  makeLink(t) {
    const e = t.get("source"), s = t.get("target"), n = this.links.make();
    return e.get("unknown") && (n.addTag("source"), n.addTag("unknown")), s.get("unknown") && (n.addTag("target"), n.addTag("unknown")), this.linksContainer.children.push(n), n._setDataItem(t), n.set("source", e), n.set("target", s), n.series = this, this.links.push(n), n;
  }
  /**
   * @ignore
   */
  updateSankey() {
    const t = this._d3Graph;
    t && (this._d3Sankey.update(t), N(this.dataItems, (e) => {
      const s = e.get("link");
      s.setPrivate("orientation", this.get("orientation")), s.markDirty();
    }));
  }
  _updateLinkColor(t) {
    super._updateLinkColor(t);
    const e = this.get("orientation"), s = t.get("link")._fillGradient, n = t.get("link")._strokeGradient;
    e == "vertical" ? (s && s.set("rotation", 90), n && n.set("rotation", 90)) : (s && s.set("rotation", 0), n && n.set("rotation", 0));
  }
  _getBulletLocation(t) {
    return this.get("orientation") == "vertical" ? t.get("locationY", 0) : t.get("locationX", 0);
  }
  _prepareChildren() {
    super._prepareChildren();
    let t = !1;
    if (this.get("orientation") == "vertical" && (t = !0), this.isDirty("orientation") || this.isDirty("linkTension")) {
      const e = this.get("linkTension", 0.5);
      t ? (this._fillGenerator.curve(We(e)), this._strokeGenerator.curve(We(e))) : (this._fillGenerator.curve(ze(e)), this._strokeGenerator.curve(ze(e)));
    }
    if ((this._valuesDirty || this._sizeDirty || this.isDirty("nodePadding") || this.isDirty("nodeWidth") || this.isDirty("nodeAlign") || this.isDirty("nodeSort") || this.isDirty("orientation") || this.isDirty("linkTension") || this.isDirty("linkSort")) && this._nodesData.length > 0) {
      const e = this._d3Sankey;
      let s = this.innerWidth(), n = this.innerHeight();
      switch (t && ([s, n] = [n, s]), e.size([s, n]), e.nodePadding(this.get("nodePadding", 10)), e.nodeWidth(this.get("nodeWidth", 10)), e.nodeSort(this.get("nodeSort", null)), e.linkSort(this.get("linkSort")), this.get("nodeAlign")) {
        case "right":
          e.nodeAlign(Ft);
          break;
        case "justify":
          e.nodeAlign(it);
          break;
        case "center":
          e.nodeAlign(Ot);
          break;
        default:
          e.nodeAlign(It);
          break;
      }
      this._d3Graph = e({ nodes: this._nodesData, links: this._linksData }), N(this.dataItems, (a) => {
        const r = a.get("link");
        r.setPrivate("orientation", this.get("orientation")), r.markDirty();
      });
      const i = this._d3Graph;
      if (i) {
        const a = i.nodes;
        N(a, (r) => {
          const o = r.dataItem, l = o.get("node");
          let g, f, D, _;
          t ? (g = r.y0, f = r.y1, D = r.x0, _ = r.x1) : (g = r.x0, f = r.x1, D = r.y0, _ = r.y1), $(g) && $(f) && $(D) && $(_) && (l.setAll({ x: g, y: D, width: f - g, height: _ - D }), o.get("rectangle").setAll({ width: f - g, height: _ - D }));
        });
      }
    }
  }
}
Pe.className = "Sankey";
Pe.classNames = H.classNames.concat([Pe.className]);
class we extends Y {
  constructor() {
    super(...arguments), this.labels = this.addDisposer(new O(B.new({}), () => Qe._new(this._root, {}, [this.labels.template]))), this._dAngle = 0, this.circles = this.addDisposer(new O(B.new({}), () => wt._new(this._root, { themeTags: ["shape"] }, [this.circles.template])));
  }
  /**
   * @ignore
   */
  makeNode(t) {
    const e = super.makeNode(t, "ArcDiagram"), s = e.children.insertIndex(0, this.circles.make());
    t.set("circle", s), s._setSoft("fill", t.get("fill")), s._setSoft("fillPattern", t.get("fillPattern"));
    const n = this.labels.make();
    return this.labels.push(n), n.addTag("flow"), n.addTag("arcdiagram"), n.addTag("node"), e.children.push(n), t.set("label", n), n._setDataItem(t), s._setDataItem(t), e;
  }
  /**
   * @ignore
   */
  disposeDataItem(t) {
    super.disposeDataItem(t);
    let e = t.get("circle");
    e && (this.circles.removeValue(e), e.dispose());
  }
  _updateNodeColor(t) {
    const e = t.get("circle");
    e && (e.set("fill", t.get("fill")), e.set("fillPattern", t.get("fillPattern")));
  }
}
we.className = "ArcDiagramNodes";
we.classNames = Y.classNames.concat([we.className]);
class xe extends X {
  constructor() {
    super(...arguments), this._radius = 0;
  }
  _beforeChanged() {
    if (super._beforeChanged(), this.isDirty("source")) {
      const t = this.get("source");
      if (t) {
        const e = t.get("node");
        this._disposers.push(e.events.on("positionchanged", () => {
          this._markDirtyKey("stroke");
        }));
      }
    }
    if (this.isDirty("target")) {
      const t = this.get("target");
      if (t) {
        const e = t.get("node");
        this._disposers.push(e.events.on("positionchanged", () => {
          this._markDirtyKey("stroke");
        }));
      }
    }
    if (this.isPrivateDirty("orientation")) {
      const t = this.series, e = this.dataItem;
      e && t && t._updateLinkColor(e);
    }
    this.series && this.dataItem && this.series._positionBullets(this.dataItem), this.get("strokeStyle") == "gradient" ? this.set("isMeasured", !0) : this.set("isMeasured", !1);
  }
  _changed() {
    super._changed(), this._clear && this._draw();
  }
  _draw() {
    const t = this.get("target"), e = this.get("source");
    if (e && t) {
      let s = e.get("node"), n = t.get("node");
      const i = s.x(), a = s.y(), r = n.x(), o = n.y();
      this._p0 = { x: i, y: a }, this._p1 = { x: r, y: o };
      let l = 0;
      if (this.getPrivate("orientation") == "vertical") {
        l = (o - a) / 2;
        let g = 1;
        a > o && (g = -1), this._display.arc(i, a + l, l * g, -Math.PI / 2, Math.PI / 2);
      } else {
        l = (r - i) / 2;
        let g = 1;
        i > r && (g = -1), this._display.arc(i + l, a, l * g, -Math.PI, 0);
      }
      this._radius = l;
    }
  }
  getPoint(t) {
    if (this._p0 && this._p1) {
      const e = this._radius;
      if (this.getPrivate("orientation") == "vertical") {
        let s = -90 + 180 * t;
        return { y: this._p0.y + e + e * G(s), x: e * M(s), angle: s + 90 };
      } else {
        let s = 180 + 180 * t;
        return { x: this._p0.x + e + e * M(s), y: e * G(s), angle: s + 90 };
      }
    }
    return { x: 0, y: 0, angle: 0 };
  }
}
xe.className = "ArcDiagramLink";
xe.classNames = X.classNames.concat([xe.className]);
class Re extends H {
  constructor() {
    super(...arguments), this.links = this.addDisposer(new O(B.new({}), () => xe._new(this._root, { themeTags: ["link", "shape"] }, [this.links.template]))), this.nodes = this.children.push(we.new(this._root, {}));
  }
  _afterNew() {
    this._settings.themeTags = le(this._settings.themeTags, ["arcdiagram", this._settings.orientation || "horizontal"]), super._afterNew(), this.nodes.children.push(this.bulletsContainer);
  }
  /**
   * @ignore
   */
  makeLink(t) {
    const e = this.nodes.children.moveValue(this.links.make(), 0);
    return this.links.push(e), e._setDataItem(t), e.set("source", t.get("source")), e.set("target", t.get("target")), e.series = this, e;
  }
  _prepareChildren() {
    if (super._prepareChildren(), this._valuesDirty || this._sizeDirty || this.isDirty("orientation")) {
      let t = 1;
      const e = this.get("orientation");
      N(this.dataItems, (p) => {
        p.get("link").setPrivate("orientation", this.get("orientation"));
      }), e == "vertical" ? t = this.innerHeight() : t = this.innerWidth();
      let s = 0, n = 1 / 0, i = this.get("radiusKey");
      i != "none" && N(this.nodes.dataItems, (p) => {
        let x = p.get(i + "Working");
        s += x, n = Math.min(n, x);
      });
      const a = this.nodes.dataItems.length, r = this.get("nodePadding", 10), o = this.get("minRadius", 5);
      t = t - a * (r + o * 2), t <= 0 && (t = 0);
      let l = s - a * n, g = t / l, f = 0;
      const D = this.get("animationDuration", 0), _ = this.get("animationEasing");
      N(this.nodes.dataItems, (p) => {
        let x = p.get(i + "Working");
        const u = p.get("node");
        let b = o + g * (x - n) / 2;
        if (i == "none" && (b = o + t / a / 2), e == "vertical") {
          u.set("x", 0);
          const S = f + r + b;
          u.y() == 0 ? u.set("y", S) : u.animate({ key: "y", to: S, duration: D, easing: _ });
        } else {
          u.set("y", 0);
          const S = f + r + b;
          u.x() == 0 ? u.set("x", S) : u.animate({ key: "x", to: S, duration: D, easing: _ });
        }
        f = f + r + b * 2, p.get("circle").set("radius", b);
      });
    }
  }
  _updateLinkColor(t) {
    super._updateLinkColor(t);
    const e = this.get("orientation"), s = t.get("link")._fillGradient, n = t.get("link")._strokeGradient;
    e == "vertical" ? (s && s.set("rotation", 90), n && n.set("rotation", 90)) : (s && s.set("rotation", 0), n && n.set("rotation", 0));
  }
}
Re.className = "ArcDiagram";
Re.classNames = H.classNames.concat([Re.className]);
export {
  Re as ArcDiagram,
  xe as ArcDiagramLink,
  we as ArcDiagramNodes,
  se as Chord,
  Te as ChordDirected,
  ae as ChordLink,
  ke as ChordLinkDirected,
  pe as ChordNodes,
  Ce as ChordNonRibbon,
  xt as DefaultTheme,
  H as Flow,
  X as FlowLink,
  fe as FlowNode,
  Y as FlowNodes,
  Pe as Sankey,
  ye as SankeyLink,
  me as SankeyNodes
};
