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