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