import * as w from "echarts";
import { C as e } from "./base-PQGakkrl.js";
import { C as A } from "./Element_Event_drag-DeZYlveu.js";
class N {
  colorPalette;
  constructor() {
    this.colorPalette = [
      "#2ec7c9",
      "#b6a2de",
      "#5ab1ef",
      "#ffb980",
      "#d87a80",
      "#8d98b3",
      "#e5cf0d",
      "#97b552",
      "#95706d",
      "#dc69aa",
      "#07a2a4",
      "#9a7fd1",
      "#588dd5",
      "#f5994e",
      "#c05050",
      "#59678c",
      "#c9ab00",
      "#7eb00a",
      "#6f5553",
      "#c14089"
    ];
  }
  getBaseOptions(n) {
    const c = {
      title: { show: !1, text: "" },
      tooltip: {
        trigger: "item",
        padding: 5,
        borderWidth: 0,
        textStyle: {
          color: "#FFFFFF"
        }
      },
      toolbox: { show: !1 },
      legend: { data: [] },
      series: []
    };
    return e.getJsonMergeDeep(c, n);
  }
  /**
   * 获取初始化配置信息
   * @param chartParam 条件{chartType:day|hour,element:容器元素,dataOriginal,tipTitleFormat,seriesNameFormat}
   * @returns
   */
  getOptionAxis(n) {
    let c = !0;
    switch (n.chartType) {
      case "hour":
        c = !1;
        break;
      case "day":
        c = !1;
        break;
    }
    const t = {
      interval: "auto"
    };
    c ? t.interval = 0 : t.interval = n.chartType === "hour" ? 0 : "auto";
    const i = e.isEmpty(n.tipTitleFormat) ? "" : n.tipTitleFormat, r = e.isEmpty(n.seriesNameFormat) ? "" : n.seriesNameFormat, a = e.isBoolean(n.isMultiple) ? n.isMultiple : !1, f = e.isBoolean(n.isTitleMergeSeriesName) ? n.isTitleMergeSeriesName : !1;
    return this.getBaseOptions({
      title: { text: "" },
      tooltip: {
        trigger: "axis",
        formatter: (l) => {
          const u = [];
          let s = l[0].name;
          switch (e.isObject(l[0].data) && l[0].data.extInfo && !e.isUndefined(l[0].data.extInfo.xValueOriginal) && (s = l[0].data.extInfo.xValueOriginal), n.chartType) {
            case "hour":
              s = e.getHourInterval(s);
              break;
            case "day":
              s = e.getValueByFormat(s, "date");
              break;
          }
          if (i.length > 0) {
            const g = a ? n.dataOriginal[0].list[l[0].dataIndex] : n.dataOriginal[l[0].dataIndex], o = e.getJsonClone(g);
            o._title = s, s = e.convertStringFormat(i, o);
          }
          f || u.push(s);
          const m = "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:${color}'></span>";
          for (let g = 0; g < l.length; g++) {
            const o = l[g], d = a ? n.dataOriginal[g].list[o.dataIndex] : n.dataOriginal[o.dataIndex], h = o.marker || e.convertStringFormat(m, { color: o.color });
            let y = e.encodeHTML(o.seriesName);
            if (r.length > 0) {
              const E = e.getJsonClone(d);
              E._seriesName = y, y = e.convertStringFormat(r, E);
            }
            let p;
            if (e.isUndefined(o.value))
              p = null;
            else if (e.isNumber(o.value)) {
              const E = Number(o.value);
              if (E < 0.01)
                p = e.getNumCeil(E, { isCeil: !1 });
              else {
                let b = "num";
                const V = { isEmptyDefault: !1 };
                E < 0.1 && (b = "float", V.decimalNum = 3), p = e.getValueByFormat(o.value, b, V);
              }
            } else
              p = o.value;
            if (!e.isUndefined(o.data.extInfo) && o.data.extInfo.tipValueFormat && o.data.extInfo.tipValueFormat.length > 0) {
              const E = e.getJsonClone(d);
              E._value = p, p = e.convertStringFormat(o.data.extInfo.tipValueFormat, E);
            }
            u.push(h + (f ? s : y) + " : " + p);
          }
          return u.join("<br />");
        }
      },
      legend: { data: [] },
      grid: { top: "20px", left: "1%", right: "1%", bottom: "1%", containLabel: !0 },
      xAxis: {
        type: "category",
        boundaryGap: !0,
        axisLabel: {
          interval: t.interval,
          formatter: (l) => {
            if (c && n?.element?.clientWidth) {
              const u = n.element.clientWidth, s = parseInt(((u - 200) / n.dataOriginal.length).toString()), m = l.toString().split(""), g = [];
              let o = 0;
              for (let h = 0; h < m.length && (o += Math.ceil(A.getTextWidth(m[h])), !(o > s)); h++)
                g.push(m[h]);
              let d = "";
              return m.length === g.length ? d = l : d = g.slice(0, g.length - 3).join("") + "...", d;
            } else
              return l;
          }
        },
        splitLine: { show: !1 },
        data: []
      },
      yAxis: [],
      series: []
    });
  }
  _getBaseDataInfo(n, c, t, i = {}) {
    const r = [], a = [], f = [], x = !e.isUndefined(i.seriesExtData);
    let l = 0;
    if (n.forEach((m, g) => {
      let o = Number(m[t]);
      if (o.toString() === "NaN" ? o = 0 : o = Number(o.toFixed(2)), g < i.totalOther || !i.isSumOther) {
        const d = m[c] || "";
        r.push(d);
        const h = {
          value: o,
          name: d
        };
        x && (h.extInfo = i.seriesExtData), a.push(h), f.push(o);
      } else
        l += Number(o);
    }), i.isSumOther) {
      const m = e.isEmpty(i.otherText) ? "其他" : i.otherText;
      r.push(m);
      const g = { value: l, name: m };
      x && (g.extInfo = i.seriesExtData), a.push(g), f.push(l);
    }
    let u = Math.max.apply(null, f);
    u = e.getNumCeil(u, { isEndFive: Number(u) < 100 });
    let s = Math.min.apply(null, f);
    return s = e.getNumCeil(s, { isEndFive: Number(u) < 100 }), { legendData: r, seriesData: a, seriesMax: u, seriesMin: s };
  }
  /**
   * 获取图表数据
   * @param list  数据格式 [{legendKey:"xxx",seriesKey:"123"}]
   * @param legendKey 显示 legend.data 的关键字
   * @param seriesKey 显示 series.data 的关键字 可单个或多个
   * @param extOpt 额外参数 {totalOther} totalOther:配置大于0时,大于的个数归其他类别
   * @returns 返回格式{legendData,seriesData ,max,sort}
   */
  getBaseData(n, c, t, i = {}) {
    const r = e.isEmpty(i.totalOther) ? -1 : parseInt(i.totalOther), a = r > 0 && n.length > r, f = e.isUndefined(i.seriesExtData) ? null : i.seriesExtData, x = { totalOther: r, isSumOther: a, seriesExtData: f };
    if (e.isArray(t)) {
      let l = [];
      const u = [], s = [], m = [];
      t.forEach((d, h) => {
        const y = this._getBaseDataInfo(n, c, d, x);
        h === 0 && (l = y.legendData), u.push({ valueKey: d, data: y.seriesData, maxData: y.seriesMax, minData: y.seriesMin }), s.push(y.seriesMax), m.push(y.seriesMin);
      });
      const g = Math.max.apply(null, s), o = Math.min.apply(null, m);
      return { legendData: l, seriesData: u, seriesMax: g, seriesMin: o };
    } else
      return this._getBaseDataInfo(n, c, t, x);
  }
  _getItemXAxisSeries(n, c, t, i) {
    let r, a;
    if (!e.isEmpty(c.xKey))
      if (r = n[c.xKey], a = r, e.isEmpty(r))
        r = "";
      else {
        let s = e.isEmpty(t.xValueFormat) ? "" : t.xValueFormat;
        switch (t.chartType) {
          case "day":
            e.isEmpty(t.xValueFormat) && (s = "MM.DD"), r = e.getValueByFormat(r, "date", { dateFormat: s });
            break;
        }
      }
    let f;
    if (!e.isEmpty(c.seriesKey)) {
      let s = c.seriesKey;
      e.isString(s) && e.isExistValue(s, ",") && (s = s.split(",")), e.isString(s) ? (f = Number(n[c.seriesKey]), f.toString() === "NaN" ? f = 0 : f = Number(f.toFixed(2))) : e.isArray(s) && (f = [], s.forEach((m) => {
        let g;
        m === c.xKey ? g = r : (g = Number(n[m]), g.toString() === "NaN" ? g = 0 : g = Number(g.toFixed(2))), f.push(g);
      }));
    }
    let x;
    e.isEmpty(c.legendKey) || (x = n[c.legendKey] || "");
    const l = c.colorKey || "color";
    let u = n[l] || t[l] || "";
    if (e.isEmpty(u) && t.isPolychrome) {
      const s = e.isEmpty(t.colorPalette) ? this.colorPalette : t.colorPalette, m = s.length, g = i % m;
      u = s[g];
    }
    return { xValue: r, xValueOriginal: a, seriesValue: f, legendValue: x, colorValue: u };
  }
  /**
  * 线图
  * @param list list  数据格式 [{xKey:xxx,legendKey:xxx,seriesKey:xxx}]
  * @param keyOpt  xKey legendKey seriesKey
  * @param extOpt 额外参数
  * @returns 
  */
  getLineOption(n, c, t = {}) {
    let i = {
      type: "line",
      areaStyle: {},
      lineStyle: {},
      smooth: !0
    };
    t.seriesItem && (i = e.getJsonMergeDeep(i, t.seriesItem));
    const r = e.getJsonMerge(t, { seriesItemBase: i });
    return this._getOneOptionBase(n, c, r);
  }
  /**
   * 柱状图
   * @param list list  数据格式 [{xKey:xxx,legendKey:xxx,seriesKey:xxx}]
   * @param keyOpt  xKey legendKey seriesKey
   * @param extOpt 额外参数
   * @returns 
   */
  getBarOption(n, c, t = {}) {
    let i = { type: "bar" };
    const r = e.isBoolean(t.isPositiveNegative) ? t.isPositiveNegative : !1;
    let a;
    r && (a = e.isEmpty(t.seriesPos) ? "vertical" : t.seriesPos, i.label = { show: !0 }), i = e.getJsonMergeDeep(i, t.seriesItem);
    const f = e.getJsonMerge(t, { seriesItemBase: i, isPositiveNegative: r, seriesPos: a }), x = this._getOneOptionBase(n, c, f);
    return x.xAxis.boundaryGap = !0, x;
  }
  /**
   * 散点图
    * @param list list  数据格式 [{xKey:xxx,seriesKey:xxx}]
   * @param keyOpt  xKey  seriesKey
   * @param extOpt 额外参数
   * @returns 
   */
  getScatterOption(n, c, t = {}) {
    let i = {
      type: "scatter",
      symbolSize: 10
    };
    t.seriesItem && (i = e.getJsonMergeDeep(i, t.seriesItem));
    const r = e.getJsonMerge(t, { seriesItemBase: i });
    c.seriesKey = [c.xKey, c.seriesKey];
    const a = this._getOneOptionBase(n, c, r);
    return a.legend = { show: !1 }, a.xAxis.axisTick = {
      show: !0,
      alignWithLabel: !0
    }, a.xAxis.splitLine = {
      show: !1
    }, a.xAxis.splitArea = {
      show: !1
    }, a.yAxis.axisTick = {
      show: !0
    }, a.yAxis.splitLine = {
      show: !1
    }, a.yAxis.splitArea = {
      show: !1
    }, a.tooltip.trigger = "item", a.tooltip.formatter = (f) => f.marker + f.value[0] + ": " + f.value[1], a;
  }
  /**
   * 获取数据
   * @param list  数据格式 [{xKey:xxx,legendKey:xxx,seriesKey:xxx}]
   * @param keyOpt  xKey legendKey seriesKey
   * @param extOpt 额外参数 {chartType}  chartType:day|hour| 类型的显示格式转换
   */
  _getOneOptionBase(n, c, t = {}) {
    const i = [];
    let r = [];
    const a = [];
    let f = "";
    const x = e.getJsonMerge(c, { colorKey: t.colorKey });
    n.forEach((m, g) => {
      const o = this._getItemXAxisSeries(m, x, t, g);
      if (e.isUndefined(o.xValue) || i.push(o.xValue), e.isUndefined(o.legendValue) || r.push(o.legendValue), !e.isUndefined(o.seriesValue)) {
        const d = o.seriesValue, h = {
          value: o.seriesValue,
          extInfo: {
            xValueOriginal: o.xValueOriginal,
            infoOriginal: m
          }
        };
        t.isPositiveNegative ? (h.label = {
          position: t.seriesPos === "horizontal" ? d >= 0 ? "left" : "right" : d >= 0 ? "top" : "bottom"
        }, h.itemStyle = { color: d >= 0 ? "#1088F0" : "#ee3c24" }) : (!e.isEmpty(o.colorValue) && f.length == 0 && (f = o.colorValue), t.isPolychrome && !e.isEmpty(o.colorValue) && (h.itemStyle = {
          color: o.colorValue
        })), e.isEmpty(t.seriesDataAddParam) || e.isExistValue(t.seriesDataAddParam, "symbolSize") && !e.isEmpty(m.symbolSize) && (h.symbolSize = m.symbolSize), a.push(h);
      }
    }), e.isUndefined(c.legendKey) || (r = e.getArrUnique(r));
    const l = e.getJsonMerge(t.seriesItemBase || {}, {
      name: t.legendData ? t.legendData : r[0],
      data: a
    });
    e.isEmpty(f) || (l.itemStyle = { color: f });
    let u = {};
    u = e.getJsonMerge(u, t);
    const s = this.getOptionAxis(u);
    return s.legend.data = r, s.xAxis = e.getJsonMerge(s.xAxis, { axisLine: {} }, t.xAxisItem || {}), s.xAxis.data = i, s.series = [l], s.yAxis = { type: "value", axisLine: { show: !0 } }, s;
  }
  /**
   * 根据分组获取多线数据(line)
   * @param list  数据格式 [{legendKey:"xxx",list:[{xKey:xxx,seriesKey:xxx}]}]
   * @param keyOpt  xKey legendKey seriesKey
   * @param extOpt 额外参数 {}
   */
  getLineMultiOption(n, c, t = {}) {
    let i = {
      type: "line",
      areaStyle: {},
      smooth: !0
    };
    t.seriesItem && (i = e.getJsonMergeDeep(i, t.seriesItem));
    const r = e.getJsonMerge(t, { seriesItemBase: i, emptyFill: 0 });
    return this._getMultiOptionBase(n, c, r);
  }
  /**
   * 根据分组获取多线数据(Bar)
   * @param list  数据格式 [{legendKey:"xxx",list:[{xKey:xxx,seriesKey:xxx}]}]
   * @param keyOpt  xKey legendKey seriesKey
   * @param extOpt 额外参数 {}
   */
  getBarMultiOption(n, c, t = {}) {
    let i = { type: "bar" };
    t.seriesItem && (i = e.getJsonMergeDeep(i, t.seriesItem));
    const r = e.getJsonMerge(t, { seriesItemBase: i }), a = this._getMultiOptionBase(n, c, r);
    if (e.isBoolean(t.isHideNull) ? t.isHideNull : !0) {
      const x = this._setBarMultiCustom(a, t);
      x.length > 0 && (a.series = x, a.legend.show = !1, a.tooltip.formatter = (l) => {
        const u = [];
        u.push(l[0].axisValue);
        for (let s = 0; s < l.length; s++) {
          const m = l[s];
          u.push(
            m.marker + e.encodeHTML(m.name) + " : " + e.getValueByFormat(m.value[1], "num")
          );
        }
        return u.join("<br />");
      });
    }
    return a;
  }
  _setBarMultiCustom(n, c) {
    const t = [], i = {};
    let r = !1;
    n.series.forEach((f, x) => {
      const { name: l, itemStyle: u } = f;
      f.data.forEach((s, m) => {
        const g = e.isObject(s) ? s.value : s;
        if (e.isUndefined(g))
          r = !0;
        else {
          const o = m.toString();
          e.isExistJsonKey(i, o) || (i[o] = []), i[o].push(l);
          const d = { name: l, value: [m, g] };
          if (!e.isUndefined(u))
            d.itemStyle = u;
          else {
            const h = e.isEmpty(c.colorPalette) ? this.colorPalette : c.colorPalette, y = x % h.length;
            d.itemStyle = { color: h[y] };
          }
          g < 0 && (d.label = { show: !0, position: "left" }), t.push(d);
        }
      });
    });
    let a = [];
    if (r) {
      a = [{
        type: "custom",
        renderItem: (l, u) => {
          const s = u.value(0), m = u.value(1), g = u.coord([0, s]), o = u.coord([Math.abs(m), s]);
          let d = u.size([0, 1])[1] * 0.8, h = g[1] - d / 2, y = l.coordSys.y;
          const p = u.value(3), E = u.value(4);
          let b = d;
          if (p > 1 || E > 1) {
            p !== E && (d = d / E * p, h = g[1] - d / 2);
            const S = d / p, D = u.value(2), v = S * (D - 1);
            h += v, y += v;
            const M = S * 0.1;
            h += M, y += M, b = S * 0.8;
          }
          const V = {
            x: g[0],
            y: h,
            width: (o[0] - g[0]) * 0.9,
            height: b
          };
          return m < 0 && (V.x -= V.width), {
            type: "rect",
            shape: w.graphic.clipRectByRect(
              V,
              {
                x: l.coordSys.x,
                y,
                width: l.coordSys.width * 0.9,
                height: l.coordSys.height
              }
            ),
            style: { fill: u.visual("color") }
          };
        },
        itemStyle: {
          opacity: 1
        },
        encode: {
          x: 1,
          y: 0
        },
        label: {},
        data: []
      }];
      const f = t.map((l) => i[l.value[0].toString()].length), x = Math.max.apply(null, f);
      t.forEach((l) => {
        const u = l.value[0], s = i[u.toString()], m = s.indexOf(l.name);
        l.value.push(m + 1), l.value.push(s.length), l.value.push(x);
      }), a[0].data = t, a[0].label = n.series[0].label, a[0].label && a[0].label.formatter && (a[0].label.formatter = (l) => e.getValueByFormat(l.value[1], "num"));
    }
    return a;
  }
  /**
   * 根据分组获取多线数据
   * @param list  数据格式 [{legendKey:"xxx",list:[{xKey:xxx,seriesKey:xxx}]}]
   * @param keyOpt legendKey xKey seriesKey
   * @param extOpt 额外参数 {}
   */
  _getMultiOptionBase(n, c, t = {}) {
    let i = [], r = [];
    const a = {}, f = [], x = e.isEmpty(t.seriesItemBase) ? {} : t.seriesItemBase, l = e.isEmpty(t.fillValue) ? null : t.emptyFill, u = e.isBoolean(t.isCompletionLegendX) ? t.isCompletionLegendX : !0, s = !e.isEmpty(t.xAxisSort), m = !e.isEmpty(t.legendSort), g = t.colorKey || "color", o = e.getJsonMerge(c, { colorKey: g });
    n.forEach((y) => {
      const p = y[o.legendKey] || "", E = {};
      y.list.forEach((b, V) => {
        const I = this._getItemXAxisSeries(b, { xKey: o.xKey }, t, V);
        e.isUndefined(I.xValue) || (i.push(I.xValue), E[I.xValue] = b);
      }), r.push(p), a[p] = E;
    }), r = e.getArrUnique(r), i = e.getArrUnique(i), m && (r = t.legendSort), s && (i = t.xAxisSort), r.forEach((y) => {
      const p = [];
      let E = "";
      u ? i.forEach((V, I) => {
        if (e.isExistJsonKey(a, y) && e.isExistJsonKey(a[y], V)) {
          const S = this._getItemXAxisSeries(a[y][V], o, t, I);
          e.isUndefined(S.seriesValue) || p.push({
            value: S.seriesValue,
            extInfo: {
              xValueOriginal: S.xValueOriginal
            }
          }), E = S.colorValue;
        } else
          p.push({ value: l });
      }) : e.isExistJsonKey(a, y) ? Object.keys(a[y]).forEach((V, I) => {
        const S = this._getItemXAxisSeries(a[y][V], o, t, I);
        e.isUndefined(S.seriesValue) || p.push({
          value: S.seriesValue,
          extInfo: {
            xValueOriginal: S.xValueOriginal
          }
        }), E = S.colorValue;
      }) : p.push({ value: l });
      const b = e.getJsonMerge(x, {
        name: y
      });
      b.data = p, b.label && t.isShowLabelThousand && (b.label.formatter = (V) => e.getValueByFormat(V.value, "num")), e.isEmpty(E) || (b.itemStyle = { color: E }), f.push(b);
    });
    let d = {};
    d = e.getJsonMerge(d, t), d.isMultiple = !0;
    const h = this.getOptionAxis(d);
    return h.legend.data = r, h.series = f, h.xAxis = e.getJsonMerge(h.xAxis, t.xAxisItem || {}), h.xAxis.data = i, h.yAxis = { type: "value", axisLine: { show: !0 } }, h;
  }
}
const T = new N();
export {
  T as e
};
//# sourceMappingURL=echart-BtfUJ8lE.js.map
