import { ref as v, computed as b, watch as Y, onMounted as pa, onBeforeUnmount as ba, openBlock as S, createElementBlock as se, normalizeStyle as Z, normalizeClass as ma, createBlock as E, createCommentVNode as G, unref as N, createSlots as xa, withCtx as m, renderSlot as k, normalizeProps as V, guardReactiveProps as j, createElementVNode as q, createVNode as La, toDisplayString as Ue, createTextVNode as ka } from "vue";
import { u as Ca, c as wa, t as Sa, a as $a, p as D, b as za, C as fe, i as J, f as K, I as Ta, d as Ze, _ as Ma, o as Ra, e as Ia, x as Ge, y as Oa, q as Pa, r as Fa, s as Q, l as _a } from "./index-DK7qqHGP.js";
import { d as Ea, c as Na, a as Ve, t as Da, l as C, r as ye, b as P, p as je, u as Ha } from "./useResponsive-NZB-WLRF.js";
import { _ as Wa } from "./Tooltip-Bt9pHzBM.js";
import { L as Ya } from "./Legend-D4PxDNTf.js";
import { _ as Ba } from "./Title-Cxlu3Etv.js";
import { S as Xa } from "./Slicer-Bk9LTQad.js";
import { u as Aa, U as Ua } from "./usePrinter-Cza87yNE.js";
import Za from "./vue-ui-accordion-5C4CP3gA.js";
import { D as Ga } from "./DataTable-B9SSwFM2.js";
import Va from "./vue-ui-skeleton-CQnYuosp.js";
import { u as qe } from "./useNestedProp-0nRX_rTi.js";
import { _ as ja } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const qa = ["id"], Ja = ["onClick"], Ka = {
  key: 2,
  class: "vue-data-ui-watermark"
}, Qa = ["innerHTML"], el = {
  __name: "vue-ui-xy-canvas",
  props: {
    dataset: {
      type: Array,
      default() {
        return [];
      }
    },
    config: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  emits: ["selectLegend"],
  setup(ge, { expose: Je, emit: Ke }) {
    const F = ge, { vue_ui_xy_canvas: Qe } = Ca(), ne = v(wa()), ee = v(null), $ = v(null), B = v(null), s = v(null), f = v(1), M = v(1), ae = v(!1), d = v(null), le = v(""), pe = v(null), w = v([]), H = v(1), _ = v(!0), z = v(!0), ie = v(null), be = v(0), me = v(0), ve = v(!1), xe = v(null), Le = v(null), ke = v(null), Ce = v(0), we = v(0), Se = v(0), ce = b(() => !!F.dataset && F.dataset.length), a = b({
      get: () => $e(),
      set: (e) => e
    });
    function $e() {
      const e = qe({
        userConfig: F.config,
        defaultConfig: Qe
      });
      return e.theme ? {
        ...qe({
          userConfig: Sa.vue_ui_xy_canvas[e.theme] || F.config,
          defaultConfig: e
        }),
        customPalette: $a[e.theme] || D
      } : e;
    }
    Y(() => F.config, (e) => {
      a.value = $e(), Ee(), Ce.value += 1, we.value += 1, Se.value += 1;
    }, { deep: !0 });
    const ze = v(a.value.style.chart.aspectRatio), { isPrinting: Te, isImaging: Me, generatePdf: Re, generateImage: Ie } = Aa({
      elementId: `xy_canvas_${ne.value}`,
      fileName: a.value.style.chart.title.text || "vue-ui-xy-canvas"
    }), r = v({
      showTable: a.value.table.show,
      showDataLabels: a.value.style.chart.dataLabels.show,
      stacked: a.value.style.chart.stacked,
      showTooltip: a.value.style.chart.tooltip.show
    });
    function ea(e) {
      ve.value = e, me.value += 1;
    }
    const Oe = b(() => za(a.value.customPalette)), R = b(() => W.value ? Math.max(...W.value.filter((e, t) => !w.value.includes(e.absoluteIndex)).map((e) => e.series.length)) : 0), l = b(() => {
      const e = f.value - f.value * (a.value.style.chart.paddingProportions.left + a.value.style.chart.paddingProportions.right);
      return {
        canvasWidth: f.value,
        canvasHeight: M.value,
        left: f.value * a.value.style.chart.paddingProportions.left,
        top: M.value * a.value.style.chart.paddingProportions.top,
        right: f.value - f.value * a.value.style.chart.paddingProportions.right,
        bottom: M.value - M.value * a.value.style.chart.paddingProportions.bottom,
        width: e,
        height: M.value - M.value * (a.value.style.chart.paddingProportions.top + a.value.style.chart.paddingProportions.bottom),
        slot: e / (u.value.end - u.value.start)
      };
    });
    function Pe(e, t) {
      return e / t;
    }
    function aa({ hasAutoScale: e, series: t, min: o, max: i, scale: c, yOffset: y, individualHeight: n, stackIndex: g = null }) {
      return t.map((L, he) => {
        const T = c.min < 0 ? Math.abs(c.min) : 0, I = Pe(L + T, T + c.max);
        let O, X;
        e && (O = Math.abs(c.min), X = Pe(L + O, c.max + O));
        let A = 0;
        return g === null ? A = l.value.bottom - l.value.height * (e ? X : I) : A = l.value.bottom - y - n * (e ? X : I), {
          x: l.value.left + l.value.slot * he + l.value.slot / 2,
          y: A,
          value: L
        };
      });
    }
    const p = b(() => {
      const e = Math.min(...W.value.filter((n, g) => !w.value.includes(n.absoluteIndex)).flatMap((n) => n.series.slice(u.value.start, u.value.end))), t = Math.max(...W.value.filter((n, g) => !w.value.includes(n.absoluteIndex)).flatMap((n) => n.series.slice(u.value.start, u.value.end))), o = fe(e < 0 ? e : 0, t === e ? e + 1 < 0 ? 0 : e + 1 : t < 0 ? 0 : t, a.value.style.chart.scale.ticks), i = o.min < 0 ? Math.abs(o.min) : 0, c = l.value.bottom - l.value.height * (i / (o.max + i)), y = o.ticks.map((n) => ({
        y: l.value.bottom - l.value.height * ((n + i) / (o.max + i)),
        x: l.value.left - 8,
        value: n
      }));
      return {
        absoluteMin: i,
        max: t,
        min: e,
        scale: o,
        yLabels: y,
        zero: c
      };
    }), la = b(() => h.value.map((e) => `
            <div style="display:flex;flex-direction:row;gap:6px;align-items:center;">
                <svg viewBox="0 0 10 10" height="12" width="12">
                    <circle cx="5" cy="5" r="5" fill="${e.color}"/>
                </svg>
                <span>${e.name ? e.name + ": " : ""}</span>
                <span>${J(
      a.value.style.chart.dataLabels.formatter,
      e.series[d.value],
      K({
        p: e.prefix || "",
        v: e.series[d.value],
        s: e.suffix || "",
        r: e.rounding || 0
      }),
      { datapoint: e, seriesIndex: d.value }
    )}</span>
            </div>
        `)), W = b(() => F.dataset.map((e, t) => ({
      ...e,
      series: Ta(e.series),
      absoluteIndex: t,
      color: Ze(e.color || Oe.value[t] || D[t] || D[t % D.length])
    })));
    Y(R, (e) => {
      e && Fe();
    });
    const h = b(() => Ma(W.value.filter((e, t) => !w.value.includes(e.absoluteIndex))).map((e, t) => ({
      ...e,
      series: e.series.slice(u.value.start, u.value.end)
    })).map((e, t) => {
      let o = Math.min(...e.series) || 0, i = Math.max(...e.series) || 1;
      o === i && (o = o >= 0 ? i - 1 : o, i = i >= 0 ? i : o + 1);
      const y = {
        ratios: e.series.filter((U) => ![null, void 0].includes(U)).map((U) => (U - o) / (i - o)),
        valueMin: o,
        valueMax: i
      }, n = e.scaleSteps || a.value.style.chart.scale.ticks;
      let g;
      e.autoScaling ? g = fe(y.valueMin, y.valueMax, n) : g = fe(y.valueMin < 0 ? y.valueMin : 0, y.valueMax <= 0 ? 0 : y.valueMax, n);
      const L = r.value.stacked ? l.value.height * (1 - e.cumulatedStackRatio) : 0, he = r.value.stacked ? l.value.height / a.value.style.chart.stackGap : 0, T = r.value.stacked ? l.value.height * e.stackRatio - he : l.value.height, I = g.min < 0 ? Math.abs(g.min) : 0;
      let O;
      e.autoScaling && r.value.stacked && i <= 0 ? O = l.value.bottom - L - T : O = l.value.bottom - L - T * (I / (g.max + I));
      const X = g.ticks.map((U, ga) => ({
        y: l.value.bottom - L - T * (ga / (g.ticks.length - 1)),
        x: l.value.left - 8,
        value: U
      })), A = aa({
        hasAutoScale: r.value.stacked && e.autoScaling,
        series: e.series,
        min: r.value.stacked ? o : p.value.min,
        max: r.value.stacked ? i : p.value.max,
        scale: r.value.stacked ? g : p.value.scale,
        yOffset: L,
        individualHeight: T,
        stackIndex: r.value.stacked ? t : null
      });
      return {
        ...e,
        coordinatesLine: A,
        min: o,
        max: i,
        localScale: g,
        localZero: O,
        localMin: I,
        localYLabels: X,
        yOffset: L,
        individualHeight: T
      };
    })), u = v({
      start: 0,
      end: R.value
    });
    function Fe() {
      u.value = {
        start: 0,
        end: R.value
      }, be.value += 1;
    }
    const ta = b(() => h.value.filter((e) => ["line", "plot", void 0].includes(e.type))), x = b(() => h.value.filter((e) => e.type === "bar"));
    function oa() {
      if (!$.value)
        return;
      const e = B.value.offsetWidth, t = B.value.offsetHeight;
      $.value.width = e * H.value * 2, $.value.height = t * H.value * 2, f.value = e * H.value * 2, M.value = t * H.value * 2, s.value.scale(H.value, H.value), de();
    }
    function ua() {
      if (s.value.clearRect(0, 0, 1e4, 1e4), s.value.fillStyle = a.value.style.chart.backgroundColor, s.value.fillRect(0, 0, l.value.canvasWidth, l.value.canvasHeight), r.value.stacked)
        a.value.style.chart.grid.y.verticalLines.show && u.value.end - u.value.start < a.value.style.chart.grid.y.verticalLines.hideUnderXLength && h.value.forEach((e) => {
          for (let t = 0; t < u.value.end - u.value.start + 1; t += 1)
            C(
              s.value,
              [
                {
                  x: l.value.left + l.value.slot * t,
                  y: l.value.bottom - e.yOffset - e.individualHeight
                },
                {
                  x: l.value.left + l.value.slot * t,
                  y: l.value.bottom - e.yOffset
                }
              ],
              {
                color: a.value.style.chart.grid.y.verticalLines.color
              }
            );
        }), a.value.style.chart.grid.x.horizontalLines.show && (a.value.style.chart.grid.x.horizontalLines.alternate ? h.value.forEach((e) => {
          e.localYLabels.forEach((t, o) => {
            o < e.localYLabels.length - 1 && ye(
              s.value,
              [
                { x: l.value.left, y: t.y },
                { x: l.value.right, y: t.y },
                { x: l.value.right, y: e.localYLabels[o + 1].y },
                { x: l.value.left, y: e.localYLabels[o + 1].y }
              ],
              {
                fillColor: o % 2 === 0 ? "transparent" : Q(a.value.style.chart.grid.x.horizontalLines.color, a.value.style.chart.grid.x.horizontalLines.opacity),
                strokeColor: "transparent"
              }
            );
          });
        }) : h.value.forEach((e) => {
          e.localYLabels.slice(u.value.start, u.value.end).forEach((t) => {
            C(
              s.value,
              [
                { x: l.value.left, y: t.y },
                { x: l.value.right, y: t.y }
              ],
              {
                color: a.value.style.chart.grid.x.horizontalLines.color
              }
            );
          });
        })), a.value.style.chart.grid.zeroLine.show && h.value.forEach((e) => {
          C(
            s.value,
            [
              { x: l.value.left, y: e.localZero },
              { x: l.value.right, y: e.localZero }
            ],
            {
              color: a.value.style.chart.grid.zeroLine.color,
              lineDash: a.value.style.chart.grid.zeroLine.dashed ? [10, 10] : [0, 0]
            }
          );
        }), a.value.style.chart.grid.y.axisLabels.show && h.value.forEach((e) => {
          C(
            s.value,
            [
              { x: l.value.left, y: l.value.bottom - e.yOffset },
              { x: l.value.left, y: l.value.bottom - e.yOffset - e.individualHeight }
            ],
            {
              color: e.color
            }
          ), C(
            s.value,
            [
              { x: l.value.right, y: l.value.bottom - e.yOffset },
              { x: l.value.right, y: l.value.bottom - e.yOffset - e.individualHeight }
            ],
            {
              color: e.color
            }
          ), e.localYLabels.forEach((t, o) => {
            P(
              s.value,
              J(
                a.value.style.chart.dataLabels.formatter,
                t.value,
                K({
                  p: e.prefix || a.value.style.chart.grid.y.axisLabels.prefix || "",
                  v: t.value,
                  s: e.suffix || a.value.style.chart.grid.y.axisLabels.suffix || "",
                  r: e.rounding || a.value.style.chart.grid.y.axisLabels.rounding || 0
                }),
                { datapoint: t, seriesIndex: o }
              ),
              t.x + a.value.style.chart.grid.y.axisLabels.offsetX,
              t.y,
              {
                align: "right",
                font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
                color: e.color
              }
            );
          });
        }), h.value.forEach((e) => {
          P(
            s.value,
            e.name,
            f.value / 35,
            l.value.bottom - e.yOffset - e.individualHeight / 2,
            {
              align: "center",
              rotation: -90,
              color: e.color,
              font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`
            }
          );
        });
      else {
        if (a.value.style.chart.grid.y.verticalLines.show && u.value.end - u.value.start < a.value.style.chart.grid.y.verticalLines.hideUnderXLength)
          for (let e = 0; e < u.value.end - u.value.start + 1; e += 1)
            C(
              s.value,
              [
                { x: l.value.left + l.value.slot * e, y: l.value.top },
                { x: l.value.left + l.value.slot * e, y: l.value.bottom }
              ],
              {
                color: a.value.style.chart.grid.y.verticalLines.color
              }
            );
        a.value.style.chart.grid.x.horizontalLines.show && (a.value.style.chart.grid.x.horizontalLines.alternate ? p.value.yLabels.forEach((e, t) => {
          t < p.value.yLabels.length - 1 && ye(
            s.value,
            [
              { x: l.value.left, y: e.y },
              { x: l.value.right, y: e.y },
              { x: l.value.right, y: p.value.yLabels[t + 1].y },
              { x: l.value.left, y: p.value.yLabels[t + 1].y }
            ],
            {
              fillColor: t % 2 === 0 ? "transparent" : Q(a.value.style.chart.grid.x.horizontalLines.color, a.value.style.chart.grid.x.horizontalLines.opacity),
              strokeColor: "transparent"
            }
          );
        }) : p.value.yLabels.forEach((e) => {
          C(
            s.value,
            [
              { x: l.value.left, y: e.y },
              { x: l.value.right, y: e.y }
            ],
            {
              color: a.value.style.chart.grid.x.horizontalLines.color
            }
          );
        })), a.value.style.chart.grid.y.showAxis && C(
          s.value,
          [
            { x: l.value.left, y: l.value.top },
            { x: l.value.left, y: l.value.bottom }
          ],
          {
            color: a.value.style.chart.grid.y.axisColor,
            lineWidth: a.value.style.chart.grid.y.axisThickness
          }
        ), a.value.style.chart.grid.x.showAxis && C(
          s.value,
          [
            { x: l.value.left, y: l.value.bottom },
            { x: l.value.right, y: l.value.bottom }
          ],
          {
            color: a.value.style.chart.grid.x.axisColor,
            lineWidth: a.value.style.chart.grid.x.axisThickness
          }
        ), a.value.style.chart.grid.zeroLine.show && C(
          s.value,
          [
            { x: l.value.left, y: p.value.zero },
            { x: l.value.right, y: p.value.zero }
          ],
          {
            color: a.value.style.chart.grid.zeroLine.color,
            lineDash: a.value.style.chart.grid.zeroLine.dashed ? [10, 10] : [0, 0]
          }
        ), a.value.style.chart.grid.y.axisLabels.show && p.value.yLabels.forEach((e, t) => {
          P(
            s.value,
            J(
              a.value.style.chart.dataLabels.formatter,
              e.value,
              K({
                p: a.value.style.chart.grid.y.axisLabels.prefix || "",
                v: e.value,
                s: a.value.style.chart.grid.y.axisLabels.suffix || "",
                r: a.value.style.chart.grid.y.axisLabels.rounding || 0
              }),
              { datapoint: e, seriesIndex: t }
            ),
            e.x + a.value.style.chart.grid.y.axisLabels.offsetX,
            e.y,
            {
              align: "right",
              font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
              color: a.value.style.chart.grid.y.axisLabels.color
            }
          );
        });
      }
      a.value.style.chart.grid.y.axisName && P(
        s.value,
        a.value.style.chart.grid.y.axisName,
        f.value - f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio * 1.2,
        l.value.bottom - l.value.height / 2,
        {
          font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
          color: a.value.style.chart.color,
          align: "center",
          rotation: 90
        }
      ), a.value.style.chart.grid.x.axisName && P(
        s.value,
        a.value.style.chart.grid.x.axisName,
        f.value / 2,
        M.value,
        {
          font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.axisLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
          color: a.value.style.chart.color,
          align: "center"
        }
      );
    }
    function ra(e) {
      for (let t = 0; t < e.coordinatesLine.length; t += 1) {
        const o = (d.value === t ? f.value / 150 : a.value.style.chart.line.plots.show ? f.value / 200 : 0) * a.value.style.chart.line.plots.radiusRatio;
        Ve(
          s.value,
          { x: e.coordinatesLine[t].x, y: e.coordinatesLine[t].y },
          o,
          {
            color: a.value.style.chart.backgroundColor,
            fillStyle: e.color,
            strokeColor: "transparent"
          }
        );
      }
    }
    function sa(e) {
      for (let t = 0; t < e.coordinatesLine.length; t += 1)
        P(
          s.value,
          J(
            a.value.style.chart.dataLabels.formatter,
            e.coordinatesLine[t].value,
            K({
              p: e.prefix || "",
              v: e.coordinatesLine[t].value,
              s: e.suffix || "",
              r: e.rounding || 0
            }),
            { datapoint: e.coordinatesLine[t], seriesIndex: t }
          ),
          e.coordinatesLine[t].x,
          e.coordinatesLine[t].y + a.value.style.chart.dataLabels.offsetY,
          {
            align: "center",
            font: `${Math.round(f.value / 40 * a.value.style.chart.dataLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
            color: a.value.style.chart.dataLabels.useSerieColor ? e.color : a.value.style.chart.dataLabels.color,
            strokeColor: a.value.style.chart.backgroundColor,
            lineWidth: 0.8
          }
        );
    }
    function na() {
      for (let e = u.value.start; e < u.value.end; e += 1)
        (u.value.end - u.value.start < a.value.style.chart.grid.y.timeLabels.modulo || u.value.end - u.value.start >= a.value.style.chart.grid.y.timeLabels.modulo && (e % Math.floor((u.value.end - u.value.start) / a.value.style.chart.grid.y.timeLabels.modulo) === 0 || e === d.value + u.value.start)) && P(
          s.value,
          a.value.style.chart.grid.y.timeLabels.values[e] || e + 1,
          l.value.left + l.value.slot * (e - u.value.start) + l.value.slot / 2,
          l.value.bottom + f.value / a.value.style.chart.grid.y.timeLabels.offsetY,
          {
            align: a.value.style.chart.grid.y.timeLabels.rotation === 0 ? "center" : a.value.style.chart.grid.y.timeLabels.rotation > 0 ? "left" : "right",
            font: `${Math.round(f.value / 40 * a.value.style.chart.grid.y.timeLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
            color: Q(a.value.style.chart.grid.y.timeLabels.color, d.value !== null ? d.value + u.value.start === e ? 100 : 20 : 100),
            rotation: a.value.style.chart.grid.y.timeLabels.rotation
          }
        );
    }
    function _e() {
      C(
        s.value,
        [
          { x: l.value.left + l.value.slot * d.value + l.value.slot / 2, y: l.value.top },
          { x: l.value.left + l.value.slot * d.value + l.value.slot / 2, y: l.value.bottom }
        ],
        {
          color: a.value.style.chart.selector.color,
          lineDash: a.value.style.chart.selector.dashed ? [8, 8] : [0, 0],
          lineWidth: 2,
          linceCap: "round"
        }
      );
    }
    function ia() {
      x.value.forEach((e, t) => {
        for (let o = 0; o < e.coordinatesLine.length; o += 1)
          ye(
            s.value,
            [
              {
                x: l.value.left + l.value.slot * o + l.value.slot / 10 + (r.value.stacked ? 0 : l.value.slot / x.value.length * t - (t === 0 ? 0 : l.value.slot / (5 * x.value.length) * t)),
                y: r.value.stacked ? e.localZero : p.value.zero
              },
              {
                x: l.value.left + l.value.slot * o + l.value.slot / 10 + (r.value.stacked ? 0 : l.value.slot / x.value.length * t - (t === 0 ? 0 : l.value.slot / (5 * x.value.length) * t)) + l.value.slot * 0.8 / (r.value.stacked ? 1 : x.value.length),
                y: r.value.stacked ? e.localZero : p.value.zero
              },
              {
                x: l.value.left + l.value.slot * o + l.value.slot / 10 + (r.value.stacked ? 0 : l.value.slot / x.value.length * t - (t === 0 ? 0 : l.value.slot / (5 * x.value.length) * t)) + l.value.slot * 0.8 / (r.value.stacked ? 1 : x.value.length),
                y: e.coordinatesLine[o].y
              },
              {
                x: l.value.left + l.value.slot * o + l.value.slot / 10 + (r.value.stacked ? 0 : l.value.slot / x.value.length * t - (t === 0 ? 0 : l.value.slot / (5 * x.value.length) * t)),
                y: e.coordinatesLine[o].y
              }
            ],
            {
              strokeColor: a.value.style.chart.backgroundColor,
              gradient: {
                type: "linear",
                start: {
                  x: e.coordinatesLine[o].x,
                  y: e.coordinatesLine[o].y
                },
                end: {
                  x: e.coordinatesLine[o].x,
                  y: r.value.stacked ? e.localZero : p.value.zero
                },
                stops: [
                  { offset: 0, color: e.color },
                  { offset: 1, color: _a(e.color, 0.5) }
                ]
              }
            }
          ), r.value.showDataLabels && [!0, void 0].includes(e.dataLabels) && P(
            s.value,
            J(
              a.value.style.chart.dataLabels.formatter,
              e.coordinatesLine[o].value,
              K({
                p: e.prefix || "",
                v: e.coordinatesLine[o].value,
                s: e.suffix || "",
                r: e.rounding || 0
              }),
              { datapoint: e.coordinatesLine[o], seriesIndex: o }
            ),
            l.value.left + l.value.slot * o + l.value.slot / 10 + (r.value.stacked ? 0 : l.value.slot / x.value.length * t - (t === 0 ? 0 : l.value.slot / (5 * x.value.length) * t)) + l.value.slot * 0.4 / (r.value.stacked ? 1 : x.value.length),
            (e.coordinatesLine[o].value < 0 ? r.value.stacked ? e.localZero : p.value.zero : e.coordinatesLine[o].y) + a.value.style.chart.dataLabels.offsetY,
            {
              align: "center",
              font: `${Math.round(f.value / 40 * a.value.style.chart.dataLabels.fontSizeRatio)}px ${a.value.style.fontFamily}`,
              color: a.value.style.chart.dataLabels.useSerieColor ? e.color : a.value.style.chart.dataLabels.color,
              strokeColor: a.value.style.chart.backgroundColor,
              lineWidth: 0.8
            }
          );
      });
    }
    function va(e) {
      e.useArea ? r.value.stacked ? je(
        s.value,
        [{ x: e.coordinatesLine[0].x, y: e.localZero }, ...e.coordinatesLine, { x: e.coordinatesLine.at(-1).x, y: e.localZero }],
        {
          fillColor: Q(e.color, a.value.style.chart.area.opacity),
          strokeColor: "transparent"
        }
      ) : je(
        s.value,
        [{ x: e.coordinatesLine[0].x, y: p.value.zero }, ...e.coordinatesLine, { x: e.coordinatesLine.at(-1).x, y: p.value.zero }],
        {
          fillColor: Q(e.color, a.value.style.chart.area.opacity),
          strokeColor: "transparent"
        }
      ) : C(s.value, e.coordinatesLine, {
        color: e.color,
        lineWidth: 3
      });
    }
    function ca() {
      h.value.forEach((e, t) => {
        C(
          s.value,
          [
            { x: l.value.left, y: l.value.bottom - e.yOffset },
            { x: l.value.right, y: l.value.bottom - e.yOffset }
          ],
          {
            color: a.value.style.chart.grid.x.horizontalLines.color,
            lineWidth: 1
          }
        );
      });
    }
    function de() {
      ua(), _.value ? (z.value && d.value !== null && a.value.style.chart.selector.show && _e(), ia(), r.value.stacked && a.value.style.chart.grid.x.showAxis && ca(), ta.value.forEach((e) => {
        (e.type === "line" || !e.type) && va(e), z.value && (ra(e), r.value.showDataLabels && [!0, void 0].includes(e.dataLabels) && sa(e));
      }), ie.value = Na($.value)) : (ie.value && (s.value.clearRect(0, 0, 1e4, 1e4), s.value.drawImage(ie.value, 0, 0)), z.value && d.value !== null && a.value.style.chart.selector.show && _e(), z.value && d.value !== null && h.value.forEach((e) => {
        if (e.type === "line" || !e.type || e.type === "plot") {
          if (!e.coordinatesLine[d.value]) return;
          e.coordinatesLine[d.value].x !== void 0 && e.coordinatesLine[d.value].y !== void 0 && Ve(
            s.value,
            {
              x: e.coordinatesLine[d.value].x,
              y: e.coordinatesLine[d.value].y
            },
            f.value / 150 * a.value.style.chart.line.plots.radiusRatio,
            {
              color: a.value.style.chart.backgroundColor,
              fillStyle: e.color,
              strokeColor: "transparent"
            }
          );
        }
      })), a.value.style.chart.grid.y.timeLabels.show && na(), _.value = !1;
    }
    const te = Ea(() => {
      z.value = !0, oa();
    }, R.value > 200 ? 10 : 1, !z.value);
    function da(e) {
      const { left: t } = $.value.getBoundingClientRect(), o = e.clientX - t;
      if (o * 2 < l.value.left || o * 2 > l.value.right) {
        ae.value = !1, d.value = null;
        return;
      }
      const i = o * 2 - l.value.left;
      if (d.value = Math.floor(i / l.value.slot), ae.value = !0, !z.value) return;
      let c = "";
      const y = a.value.style.chart.tooltip.customFormat;
      Ge(y) && Oa(() => y({
        seriesIndex: d.value,
        datapoint: h.value.map((n) => ({
          shape: n.shape || null,
          name: n.name,
          color: n.color,
          type: n.type || "line",
          value: n.series.find((g, L) => L === d.value)
        })),
        series: h.value,
        config: a.value
      })) ? le.value = y({
        seriesIndex: d.value,
        datapoint: h.value.map((n) => ({
          shape: n.shape || null,
          name: n.name,
          color: n.color,
          type: n.type || "line",
          value: n.series.find((g, L) => L === d.value)
        })),
        series: h.value,
        config: a.value
      }) : (a.value.style.chart.grid.y.timeLabels.values.slice(u.value.start, u.value.end)[d.value] && (c += `<div style="padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid ${a.value.style.chart.tooltip.borderColor}; width:100%">${a.value.style.chart.grid.y.timeLabels.values.slice(u.value.start, u.value.end)[d.value]}</div>`), c += la.value.join(""), le.value = c), z.value = !1;
    }
    Y(() => d.value, (e) => {
      te();
    }), Y(() => u.value, (e) => {
      _.value = !0, de();
    }, {
      deep: !0
    }), Y(() => r.value.showDataLabels, (e) => {
      _.value = !0, de();
    }), Y(() => r.value.stacked, (e) => {
      _.value = !0, z.value = !0, te();
    });
    function ha() {
      ae.value = !1, d.value = null, le.value = "";
    }
    const oe = v(null), ue = v(null);
    pa(() => {
      Ee();
    });
    function Ee() {
      if (Ra(F.dataset) ? Ia({
        componentName: "VueUiXyCanvas",
        type: "dataset"
      }) : $.value && (s.value = $.value.getContext("2d", { willReadFrequently: !0 })), a.value.responsive) {
        const e = Da(() => {
          const { width: t, height: o } = Ha({
            chart: ee.value,
            title: a.value.style.chart.title.text ? xe.value : null,
            legend: a.value.style.chart.legend.show ? Le.value : null,
            slicer: a.value.style.chart.zoom.show && R.value > 1 ? ke.value : null
          });
          ze.value = `${t} / ${o}`;
        });
        oe.value = new ResizeObserver(e), oe.value.observe(ee.value.parentNode);
      }
      ue.value = new ResizeObserver((e) => {
        for (const t of e)
          t.contentBoxSize && B.value && (_.value = !0, te());
      }), ue.value.observe(B.value);
    }
    ba(() => {
      ue.value && ue.value.disconnect(), oe.value && oe.value.disconnect();
    });
    function Ne(e) {
      Ke("selectLegend", h.value.find((t) => t.absoluteIndex === e)), w.value.includes(e) ? w.value = w.value.filter((t) => t !== e) : w.value.push(e), _.value = !0, te();
    }
    const De = b(() => W.value.map((e, t) => ({
      ...e,
      name: e.name,
      color: Ze(e.color) || Oe.value[t] || D[t] || D[t % D.length],
      shape: e.shape || "circle",
      prefix: e.prefix || "",
      suffix: e.suffix || "",
      rounding: e.rounding || 0
    })).map((e) => ({
      ...e,
      opacity: w.value.includes(e.absoluteIndex) ? 0.5 : 1,
      segregate: () => Ne(e.absoluteIndex),
      isSegregated: w.value.includes(e.absoluteIndex)
    }))), fa = b(() => ({
      cy: "donut-div-legend",
      backgroundColor: a.value.style.chart.legend.backgroundColor,
      color: a.value.style.chart.legend.color,
      fontSize: a.value.style.chart.legend.fontSize,
      paddingBottom: 12,
      fontWeight: a.value.style.chart.legend.bold ? "bold" : ""
    })), re = b(() => {
      const e = [""].concat(h.value.map((c) => c.name)).concat(' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>');
      let t = [];
      for (let c = 0; c < R.value; c += 1) {
        const y = h.value.map((n) => n.series[c] ?? 0).reduce((n, g) => n + g, 0);
        t.push([a.value.style.chart.grid.y.timeLabels.values.slice(u.value.start, u.value.end)[c] ?? c + 1].concat(h.value.map((n) => (n.series[c] ?? 0).toFixed(a.value.table.rounding))).concat((y ?? 0).toFixed(a.value.table.rounding)));
      }
      const o = {
        th: {
          backgroundColor: a.value.table.th.backgroundColor,
          color: a.value.table.th.color,
          outline: a.value.table.th.outline
        },
        td: {
          backgroundColor: a.value.table.td.backgroundColor,
          color: a.value.table.td.color,
          outline: a.value.table.td.outline
        },
        breakpoint: a.value.table.responsiveBreakpoint
      }, i = [a.value.table.columnNames.period].concat(h.value.map((c) => c.name)).concat(a.value.table.columnNames.total);
      return { head: e, body: t.slice(0, u.value.end - u.value.start), config: o, colNames: i };
    }), He = b(() => {
      if (h.value.length === 0) return { head: [], body: [], config: {}, columnNames: [] };
      const e = h.value.map((o) => ({
        label: o.name,
        color: o.color,
        type: o.type
      })), t = [];
      for (let o = u.value.start; o < u.value.end; o += 1) {
        const i = [a.value.style.chart.grid.y.timeLabels.values[o] || o + 1];
        h.value.forEach((c) => {
          i.push(Number((c.series[o] || 0).toFixed(a.value.table.rounding)));
        }), t.push(i);
      }
      return { head: e, body: t };
    });
    function We() {
      const e = [[a.value.style.chart.title.text], [a.value.style.chart.title.subtitle.text], [""]], t = ["", ...He.value.head.map((y) => y.label)], o = He.value.body, i = e.concat([t]).concat(o), c = Pa(i);
      Fa({ csvContent: c, title: a.value.style.chart.title.text || "vue-ui-xy-canvas" });
    }
    function ya() {
      return h.value;
    }
    function Ye() {
      r.value.showTable = !r.value.showTable;
    }
    function Be() {
      r.value.showDataLabels = !r.value.showDataLabels;
    }
    function Xe() {
      r.value.stacked = !r.value.stacked;
    }
    function Ae() {
      r.value.showTooltip = !r.value.showTooltip;
    }
    return Je({
      getData: ya,
      generateCsv: We,
      generatePdf: Re,
      generateImage: Ie,
      toggleTable: Ye,
      toggleLabels: Be,
      toggleStack: Xe,
      toggleTooltip: Ae
    }), (e, t) => (S(), se("div", {
      style: Z(`width:100%; position: relative;${a.value.responsive ? "height: 100%" : ""}`),
      ref_key: "xy",
      ref: ee,
      id: `xy_canvas_${ne.value}`,
      class: ma(`vue-ui-donut ${ve.value ? "vue-data-ui-wrapper-fullscreen" : ""}`)
    }, [
      a.value.style.chart.title.text ? (S(), se("div", {
        key: 0,
        ref_key: "chartTitle",
        ref: xe,
        style: Z(`width:100%;background:${a.value.style.chart.backgroundColor};`)
      }, [
        (S(), E(Ba, {
          key: `title_${Ce.value}`,
          config: {
            title: {
              cy: "xy-canvas-title",
              ...a.value.style.chart.title
            },
            subtitle: {
              cy: "xy-canvas-subtitle",
              ...a.value.style.chart.title.subtitle
            }
          }
        }, null, 8, ["config"]))
      ], 4)) : G("", !0),
      a.value.userOptions.show && ce.value ? (S(), E(Ua, {
        ref: "details",
        key: `user_option_${me.value}`,
        backgroundColor: a.value.style.chart.backgroundColor,
        color: a.value.style.chart.color,
        isPrinting: N(Te),
        isImaging: N(Me),
        uid: ne.value,
        hasTooltip: a.value.userOptions.buttons.tooltip && a.value.style.chart.tooltip.show,
        hasPdf: a.value.userOptions.buttons.pdf,
        hasImg: a.value.userOptions.buttons.img,
        hasXls: a.value.userOptions.buttons.csv,
        hasLabel: a.value.userOptions.buttons.labels,
        hasStack: ge.dataset.length > 1 && a.value.userOptions.buttons.stack,
        hasFullscreen: a.value.userOptions.buttons.fullscreen,
        hasTable: u.value.end - u.value.start < 200 && a.value.userOptions.buttons.table,
        isFullscreen: ve.value,
        isTooltip: r.value.showTooltip,
        isStacked: r.value.stacked,
        titles: { ...a.value.userOptions.buttonTitles },
        chartElement: ee.value,
        position: a.value.userOptions.position,
        onToggleFullscreen: ea,
        onGeneratePdf: N(Re),
        onGenerateCsv: We,
        onGenerateImage: N(Ie),
        onToggleTable: Ye,
        onToggleLabels: Be,
        onToggleStack: Xe,
        onToggleTooltip: Ae
      }, xa({ _: 2 }, [
        e.$slots.optionTooltip ? {
          name: "optionTooltip",
          fn: m(() => [
            k(e.$slots, "optionTooltip", {}, void 0, !0)
          ]),
          key: "0"
        } : void 0,
        e.$slots.optionPdf ? {
          name: "optionPdf",
          fn: m(() => [
            k(e.$slots, "optionPdf", {}, void 0, !0)
          ]),
          key: "1"
        } : void 0,
        e.$slots.optionCsv ? {
          name: "optionCsv",
          fn: m(() => [
            k(e.$slots, "optionCsv", {}, void 0, !0)
          ]),
          key: "2"
        } : void 0,
        e.$slots.optionImg ? {
          name: "optionImg",
          fn: m(() => [
            k(e.$slots, "optionImg", {}, void 0, !0)
          ]),
          key: "3"
        } : void 0,
        e.$slots.optionTable ? {
          name: "optionTable",
          fn: m(() => [
            k(e.$slots, "optionTable", {}, void 0, !0)
          ]),
          key: "4"
        } : void 0,
        e.$slots.optionLabels ? {
          name: "optionLabels",
          fn: m(() => [
            k(e.$slots, "optionLabels", {}, void 0, !0)
          ]),
          key: "5"
        } : void 0,
        e.$slots.optionStack ? {
          name: "optionStack",
          fn: m(() => [
            k(e.$slots, "optionStack", {}, void 0, !0)
          ]),
          key: "6"
        } : void 0,
        e.$slots.optionFullscreen ? {
          name: "optionFullscreen",
          fn: m(({ toggleFullscreen: o, isFullscreen: i }) => [
            k(e.$slots, "optionFullscreen", V(j({ toggleFullscreen: o, isFullscreen: i })), void 0, !0)
          ]),
          key: "7"
        } : void 0
      ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasTooltip", "hasPdf", "hasImg", "hasXls", "hasLabel", "hasStack", "hasFullscreen", "hasTable", "isFullscreen", "isTooltip", "isStacked", "titles", "chartElement", "position", "onGeneratePdf", "onGenerateImage"])) : G("", !0),
      q("div", {
        class: "vue-ui-xy-canvas",
        style: Z(`position: relative; aspect-ratio: ${ze.value}`),
        ref_key: "container",
        ref: B
      }, [
        ce.value ? (S(), se("canvas", {
          key: 0,
          ref_key: "canvas",
          ref: $,
          style: { width: "100%", height: "100%" },
          onMousemove: t[0] || (t[0] = (o) => da(o)),
          onMouseleave: ha
        }, null, 544)) : (S(), E(Va, {
          key: 1,
          config: {
            type: "line",
            style: {
              backgroundColor: a.value.style.chart.backgroundColor,
              line: {
                axis: {
                  color: "#CCCCCC"
                },
                path: {
                  color: "#CCCCCC",
                  strokeWidth: 0.5
                }
              }
            }
          }
        }, null, 8, ["config"])),
        La(Wa, {
          show: r.value.showTooltip && ae.value,
          backgroundColor: a.value.style.chart.tooltip.backgroundColor,
          color: a.value.style.chart.tooltip.color,
          fontSize: a.value.style.chart.tooltip.fontSize,
          borderRadius: a.value.style.chart.tooltip.borderRadius,
          borderColor: a.value.style.chart.tooltip.borderColor,
          borderWidth: a.value.style.chart.tooltip.borderWidth,
          position: a.value.style.chart.tooltip.position,
          offsetY: a.value.style.chart.tooltip.offsetY,
          parent: $.value,
          content: le.value,
          backgroundOpacity: a.value.style.chart.tooltip.backgroundOpacity,
          isCustom: N(Ge)(a.value.style.chart.tooltip.customFormat)
        }, {
          "tooltip-before": m(() => [
            k(e.$slots, "tooltip-before", V(j({ ...pe.value })), void 0, !0)
          ]),
          "tooltip-after": m(() => [
            k(e.$slots, "tooltip-after", V(j({ ...pe.value })), void 0, !0)
          ]),
          _: 3
        }, 8, ["show", "backgroundColor", "color", "fontSize", "borderRadius", "borderColor", "borderWidth", "position", "offsetY", "parent", "content", "backgroundOpacity", "isCustom"])
      ], 4),
      q("div", {
        ref_key: "chartSlicer",
        ref: ke,
        style: Z(`width:100%;background:${a.value.style.chart.backgroundColor}`),
        "data-html2canvas-ignore": ""
      }, [
        a.value.style.chart.zoom.show && R.value > 1 ? (S(), E(Xa, {
          key: `slicer_${be.value}`,
          background: a.value.style.chart.zoom.color,
          borderColor: a.value.style.chart.backgroundColor,
          fontSize: a.value.style.chart.zoom.fontSize,
          useResetSlot: a.value.style.chart.zoom.useResetSlot,
          labelLeft: a.value.style.chart.grid.y.timeLabels.values[u.value.start] ? a.value.style.chart.grid.y.timeLabels.values[u.value.start] : "",
          labelRight: a.value.style.chart.grid.y.timeLabels.values[u.value.end - 1] ? a.value.style.chart.grid.y.timeLabels.values[u.value.end - 1] : "",
          textColor: a.value.style.chart.color,
          inputColor: a.value.style.chart.zoom.color,
          selectColor: a.value.style.chart.zoom.highlightColor,
          max: R.value,
          min: 0,
          valueStart: u.value.start,
          valueEnd: u.value.end,
          start: u.value.start,
          "onUpdate:start": t[1] || (t[1] = (o) => u.value.start = o),
          end: u.value.end,
          "onUpdate:end": t[2] || (t[2] = (o) => u.value.end = o),
          onReset: Fe
        }, {
          "reset-action": m(({ reset: o }) => [
            k(e.$slots, "reset-action", V(j({ reset: o })), void 0, !0)
          ]),
          _: 3
        }, 8, ["background", "borderColor", "fontSize", "useResetSlot", "labelLeft", "labelRight", "textColor", "inputColor", "selectColor", "max", "valueStart", "valueEnd", "start", "end"])) : G("", !0)
      ], 4),
      q("div", {
        ref_key: "chartLegend",
        ref: Le
      }, [
        a.value.style.chart.legend.show && ce.value ? (S(), E(Ya, {
          legendSet: De.value,
          config: fa.value,
          key: `legend_${Se.value}`,
          onClickMarker: t[3] || (t[3] = ({ i: o }) => Ne(o))
        }, {
          item: m(({ legend: o, index: i }) => [
            q("div", {
              onClick: (c) => o.segregate(),
              style: Z(`opacity:${w.value.includes(i) ? 0.5 : 1}`)
            }, Ue(o.name), 13, Ja)
          ]),
          _: 1
        }, 8, ["legendSet", "config"])) : k(e.$slots, "legend", {
          key: 1,
          legend: De.value
        }, void 0, !0)
      ], 512),
      e.$slots.watermark ? (S(), se("div", Ka, [
        k(e.$slots, "watermark", V(j({ isPrinting: N(Te) || N(Me) })), void 0, !0)
      ])) : G("", !0),
      u.value.end - u.value.start < 200 ? (S(), E(Za, {
        key: 3,
        hideDetails: "",
        config: {
          open: r.value.showTable,
          maxHeight: 1e4,
          body: {
            backgroundColor: a.value.style.chart.backgroundColor,
            color: a.value.style.chart.color
          },
          head: {
            backgroundColor: a.value.style.chart.backgroundColor,
            color: a.value.style.chart.color
          }
        }
      }, {
        content: m(() => [
          (S(), E(Ga, {
            key: `table_${we.value}`,
            colNames: re.value.colNames,
            head: re.value.head,
            body: re.value.body,
            config: re.value.config,
            title: `${a.value.style.chart.title.text}${a.value.style.chart.title.subtitle.text ? ` : ${a.value.style.chart.title.subtitle.text}` : ""}`,
            onClose: t[4] || (t[4] = (o) => r.value.showTable = !1)
          }, {
            th: m(({ th: o }) => [
              q("div", { innerHTML: o }, null, 8, Qa)
            ]),
            td: m(({ td: o }) => [
              ka(Ue(o), 1)
            ]),
            _: 1
          }, 8, ["colNames", "head", "body", "config", "title"]))
        ]),
        _: 1
      }, 8, ["config"])) : G("", !0)
    ], 14, qa));
  }
}, fl = /* @__PURE__ */ ja(el, [["__scopeId", "data-v-180df9f3"]]);
export {
  fl as default
};
