use-chart-controller-d5d0d5a1.js 22.8 KB
Newer Older
zhf's avatar
zhf committed
1 2 3 4 5 6 7
var P = Object.defineProperty;
var F = (h, u, e) => u in h ? P(h, u, { enumerable: !0, configurable: !0, writable: !0, value: e }) : h[u] = e;
var L = (h, u, e) => (F(h, typeof u != "symbol" ? u + "" : u, e), e);
import { useControlController as T } from "@ibiz-template/vue-util";
import { Neuron as I, ControlNerve as N, ControlController as z } from "@ibiz-template/controller";
import { createUUID as M } from "qx-util";
import { init as D } from "echarts";
8
import { mergeDeepRight as y } from "ramda";
zhf's avatar
zhf committed
9 10
import { ControlService as j } from "@ibiz-template/service";
class $ extends I {
11
}
zhf's avatar
zhf committed
12
class H extends N {
13
  createNeuron() {
zhf's avatar
zhf committed
14
    return new $(this.bindAbility());
15 16 17 18 19 20 21 22
  }
  bindAbility() {
    return {
      ...super.bindAbility(),
      load: this.controller.load.bind(this.controller)
    };
  }
}
zhf's avatar
zhf committed
23 24 25
function S(h) {
  const u = {};
  return h && Object.keys(h).forEach((e) => {
26 27 28 29
    const s = e.indexOf(".");
    if (s === -1)
      return;
    const r = e.slice(s + 1);
zhf's avatar
zhf committed
30 31 32 33 34 35 36
    if (r && h[e] !== void 0)
      try {
        u[r] = JSON.parse(h[e]);
      } catch (o) {
        ibiz.log.error(`${r} 解析错误`);
      }
  }), u;
37
}
zhf's avatar
zhf committed
38
function k(h) {
39
  var e;
zhf's avatar
zhf committed
40 41 42 43 44
  const u = {};
  if (h) {
    u.show = h.showTitle, u.text = h.title, u.subtext = h.subTitle;
    const s = (e = h.titlePos) == null ? void 0 : e.toLowerCase();
    s === "left" || s === "right" ? u.left = s : (s === "bottom" || s === "top") && (u.left = "center", u.top = s);
45
  }
zhf's avatar
zhf committed
46
  return u;
47
}
zhf's avatar
zhf committed
48
function q(h) {
49
  var e;
zhf's avatar
zhf committed
50 51 52 53 54
  const u = {};
  if (h) {
    u.show = h.showLegend;
    const s = (e = h.legendPos) == null ? void 0 : e.toLowerCase();
    s === "left" || s === "right" ? (u.left = s, u.top = "middle", u.orient = "vertical") : s === "bottom" && (u.top = s);
55
  }
zhf's avatar
zhf committed
56
  return u;
57
}
zhf's avatar
zhf committed
58
function v(h) {
59 60
  return {
    axisLabel: {
zhf's avatar
zhf committed
61
      formatter: (e) => h === 1 ? e.length > 4 ? `${e.slice(0, 4).split("").join(`
62 63
`)}
...` : e.split("").join(`
zhf's avatar
zhf committed
64 65
`) : h === 2 && e.length > 4 ? `${e.slice(0, 4)}...` : e,
      rotate: h === 2 ? 45 : 0
66 67 68
    }
  };
}
zhf's avatar
zhf committed
69 70 71
function R(h) {
  const u = [];
  return h && h.length && h.forEach((e) => {
72 73 74 75 76 77 78 79 80
    const { caption: s, minValue: r, maxValue: o, eChartsType: t, position: i } = e, n = {
      name: s,
      min: r,
      max: o
    };
    Object.assign(n, {
      type: t,
      position: i,
      ...y(
zhf's avatar
zhf committed
81 82
        v(e.dataShowMode),
        S(e.userParams)
83
      )
zhf's avatar
zhf committed
84 85
    }), u.push(n);
  }), u;
86
}
zhf's avatar
zhf committed
87 88 89
function V(h) {
  const u = [];
  return h && h.length && h.forEach((e) => {
90 91 92 93 94 95 96 97 98
    const { caption: s, minValue: r, maxValue: o, eChartsType: t, position: i } = e, n = {
      name: s,
      min: r,
      max: o
    };
    Object.assign(n, {
      type: t,
      position: i,
      ...y(
zhf's avatar
zhf committed
99 100
        v(e.dataShowMode),
        S(e.userParams)
101
      )
zhf's avatar
zhf committed
102 103
    }), u.push(n);
  }), u;
104
}
zhf's avatar
zhf committed
105
class B extends j {
106 107 108 109 110 111 112 113 114
  constructor(e) {
    super(e);
    /**
     * 序列列表
     *
     * @author zhanghengfeng
     * @date 2023-04-03 16:04:38
     * @type {IPSDEChartSeries[]}
     */
zhf's avatar
zhf committed
115
    L(this, "seriesList", []);
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
    const s = e.source.getPSDEChartSerieses();
    if (!s || !s.length)
      throw new Error("图表序列集合不能为空");
    this.seriesList = s;
  }
  /**
   * 获取数据
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:11
   * @param {IContext} context
   * @param {IParams} [params={}]
   * @return {*}  {Promise<IHttpResponse>}
   */
  async fetch(e, s = {}) {
    return await this.exec(this.model.fetchAction, e, s);
  }
  /**
   * 获取所有代码表映射
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:21
   * @param {IContext} context
   * @param {IParams} params
   * @return {*}
   */
  async getAllCodeListMap(e, s) {
    const r = [];
    return await Promise.all(
      this.seriesList.map(async (o, t) => {
zhf's avatar
zhf committed
146 147
        var a, c, d, g;
        const i = {}, n = (c = (a = o.getCatalogPSCodeList) == null ? void 0 : a.call(o)) == null ? void 0 : c.codeName, m = (g = (d = o.getSeriesPSCodeList) == null ? void 0 : d.call(o)) == null ? void 0 : g.codeName;
148
        if (n) {
zhf's avatar
zhf committed
149
          const p = await ibiz.codeListService.get(
150 151 152 153
            n,
            e,
            s
          );
zhf's avatar
zhf committed
154
          if (p) {
155
            const f = /* @__PURE__ */ new Map();
zhf's avatar
zhf committed
156 157
            p.forEach((l) => {
              f.set(l.value, l.text);
158 159 160
            }), i.catalog = f;
          }
        }
zhf's avatar
zhf committed
161 162 163
        if (m) {
          const p = await ibiz.codeListService.get(
            m,
164 165 166
            e,
            s
          );
zhf's avatar
zhf committed
167
          if (p) {
168
            const f = /* @__PURE__ */ new Map();
zhf's avatar
zhf committed
169 170
            p.forEach((l) => {
              f.set(l.value, l.text);
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
            }), i.series = f;
          }
        }
        r[t] = i;
      })
    ), r;
  }
  /**
   * 生成数据集配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:37
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @return {*}
   */
  generateDatasetOption(e, s, r) {
    var a;
    const o = {}, t = [];
    o.source = t;
zhf's avatar
zhf committed
192 193
    const i = e.catalogField.toLowerCase(), n = e.valueField.toLowerCase(), m = (a = e.seriesField) == null ? void 0 : a.toLowerCase();
    if (m) {
194
      const c = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
195 196
      s.forEach((d) => {
        c.add(d[m]);
197 198 199 200
      }), t.push([i, ...c]);
    } else
      t.push([i, n]);
    t.push(
zhf's avatar
zhf committed
201 202
      ...s.map((c) => t[0].map((d, g) => g === 0 ? (r && r.catalog ? r.catalog.get(c[d]) : c[d]) || "未定义" : m ? d === c[m] && c[n] || 0 : c[n] || 0))
    ), r && r.series && (t[0] = t[0].map((c, d) => {
203
      var g;
zhf's avatar
zhf committed
204
      return d === 0 ? c : ((g = r.series) == null ? void 0 : g.get(c)) || c;
205 206
    }));
    for (let c = 1; c < t.length; c++)
zhf's avatar
zhf committed
207 208 209 210
      for (let d = c + 1; d < t.length; d++)
        t[d][0] === t[c][0] && (t[d].forEach((g, p) => {
          p !== 0 && (t[c][p] += g);
        }), t.splice(d, 1), d -= 1);
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
    return o;
  }
  /**
   * 生成图表配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:49
   * @param {IData[]} data
   * @param {IContext} context
   * @param {IParams} params
   * @return {*}
   */
  async generateChartOption(e, s, r) {
    const o = {};
    o.dataset = [], o.series = [];
    const t = await this.getAllCodeListMap(s, r);
    return this.seriesList.forEach((i, n) => {
      if (i.eChartsType === "radar") {
        const { series: a, radar: c } = this.generateRadarSeriesOption(
          i,
          e,
          t[n]
        );
        Array.isArray(o.series) && o.series.push(...a), o.radar = c;
        return;
      }
zhf's avatar
zhf committed
237 238
      const m = this.generateDatasetOption(i, e, t[n]);
      if (Array.isArray(o.dataset) && o.dataset.push(m), i.eChartsType === "bar") {
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
        const a = this.generateBarSeriesOption(
          i,
          e,
          t[n],
          n
        );
        Array.isArray(o.series) && o.series.push(...a);
      } else if (i.eChartsType === "line") {
        const a = this.generateLineSeriesOption(
          i,
          e,
          t[n],
          n
        );
        Array.isArray(o.series) && o.series.push(...a);
      } else if (i.eChartsType === "pie") {
        const a = this.generatePieSeriesOption(
          i,
          e,
          t[n],
          n
        );
        Array.isArray(o.series) && o.series.push(...a);
      } else if (i.eChartsType === "funnel") {
        const a = this.generateFunnelSeriesOption(
          i,
          e,
          t[n],
          n
        );
        Array.isArray(o.series) && o.series.push(...a);
      } else if (i.eChartsType === "scatter") {
        const a = this.generateScatterSeriesOption(
          i,
          e,
          t[n],
          n
        );
        Array.isArray(o.series) && o.series.push(...a);
      } else
        throw new Error(`${i.eChartsType}类型的图表暂未实现`);
    }), o;
  }
  /**
   * 生成柱状图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:13
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @param {number} index
   * @return {*}
   */
  generateBarSeriesOption(e, s, r, o) {
zhf's avatar
zhf committed
294 295
    var p, f, l, C, w, x, b;
    const t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (p = e.seriesField) == null ? void 0 : p.toLowerCase(), c = +((C = (l = (f = e.M) == null ? void 0 : f.getPSChartSeriesEncode) == null ? void 0 : l.getPSChartXAxis) == null ? void 0 : C.id) || 0, d = +((b = (x = (w = e.M) == null ? void 0 : w.getPSChartSeriesEncode) == null ? void 0 : x.getPSChartYAxis) == null ? void 0 : b.id) || 0, g = {};
296 297
    if (a) {
      const E = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
298 299 300
      s.forEach((O) => {
        const A = O[a];
        E.add(r && r.series && r.series.get(A) || A);
301
      }), t.push(
zhf's avatar
zhf committed
302
        ...[...E].map((O) => ({
303 304
          type: i,
          xAxisIndex: c,
zhf's avatar
zhf committed
305 306
          yAxisIndex: d,
          name: O,
307 308 309
          datasetIndex: o,
          encode: {
            x: n,
zhf's avatar
zhf committed
310
            y: O
311 312 313
          },
          ...y(
            g,
zhf's avatar
zhf committed
314
            S(e.userParams)
315 316 317 318 319 320 321
          )
        }))
      );
    } else
      t.push({
        type: i,
        xAxisIndex: c,
zhf's avatar
zhf committed
322
        yAxisIndex: d,
323 324 325 326
        name: e.caption || e.id,
        datasetIndex: o,
        encode: {
          x: n,
zhf's avatar
zhf committed
327
          y: m
328 329 330
        },
        ...y(
          g,
zhf's avatar
zhf committed
331
          S(e.userParams)
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
        )
      });
    return t;
  }
  /**
   * 生成折线图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:32
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @param {number} index
   * @return {*}
   */
  generateLineSeriesOption(e, s, r, o) {
zhf's avatar
zhf committed
348 349
    var p, f, l, C, w, x, b;
    const t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (p = e.seriesField) == null ? void 0 : p.toLowerCase(), c = +((C = (l = (f = e.M) == null ? void 0 : f.getPSChartSeriesEncode) == null ? void 0 : l.getPSChartXAxis) == null ? void 0 : C.id) || 0, d = +((b = (x = (w = e.M) == null ? void 0 : w.getPSChartSeriesEncode) == null ? void 0 : x.getPSChartYAxis) == null ? void 0 : b.id) || 0, g = {
350 351 352 353 354 355 356 357 358 359 360 361 362
      emphasis: {
        label: {
          fontSize: 20,
          show: !0
        }
      },
      label: {
        position: "top",
        show: !0
      }
    };
    if (a) {
      const E = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
363 364 365
      s.forEach((O) => {
        const A = O[a];
        E.add(r && r.series && r.series.get(A) || A);
366
      }), t.push(
zhf's avatar
zhf committed
367
        ...[...E].map((O) => ({
368 369
          type: i,
          xAxisIndex: c,
zhf's avatar
zhf committed
370 371
          yAxisIndex: d,
          name: O,
372 373 374
          datasetIndex: o,
          encode: {
            x: n,
zhf's avatar
zhf committed
375
            y: O
376 377 378 379 380
          },
          stack: e.M.stack ? e.id : void 0,
          step: e.M.step ? "middle" : !1,
          ...y(
            g,
zhf's avatar
zhf committed
381
            S(e.userParams)
382 383 384 385 386 387 388
          )
        }))
      );
    } else
      t.push({
        type: i,
        xAxisIndex: c,
zhf's avatar
zhf committed
389
        yAxisIndex: d,
390 391 392 393
        name: e.caption || e.id,
        datasetIndex: o,
        encode: {
          x: n,
zhf's avatar
zhf committed
394
          y: m
395 396 397
        },
        ...y(
          g,
zhf's avatar
zhf committed
398
          S(e.userParams)
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
        )
      });
    return t;
  }
  /**
   * 生成饼图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:44
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @param {number} index
   * @return {*}
   */
  generatePieSeriesOption(e, s, r, o) {
zhf's avatar
zhf committed
415 416
    var d;
    const t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (d = e.seriesField) == null ? void 0 : d.toLowerCase(), c = {
417 418 419 420 421 422 423 424 425 426 427 428 429 430
      emphasis: {
        label: {
          fontSize: 20,
          show: !0
        }
      },
      label: {
        formatter: "{b}: {d}%({@age})",
        position: "outside",
        show: !0
      }
    };
    if (a) {
      const g = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
431 432
      s.forEach((p) => {
        const f = p[a];
433 434
        g.add(r && r.series && r.series.get(f) || f);
      }), t.push(
zhf's avatar
zhf committed
435
        ...[...g].map((p) => ({
436
          type: i,
zhf's avatar
zhf committed
437
          name: p,
438 439 440
          datasetIndex: o,
          encode: {
            itemName: n,
zhf's avatar
zhf committed
441
            value: p
442 443 444
          },
          ...y(
            c,
zhf's avatar
zhf committed
445
            S(e.userParams)
446 447 448 449 450 451 452 453 454 455
          )
        }))
      );
    } else
      t.push({
        type: i,
        name: e.caption || e.id,
        datasetIndex: o,
        encode: {
          itemName: n,
zhf's avatar
zhf committed
456
          value: m
457 458 459
        },
        ...y(
          c,
zhf's avatar
zhf committed
460
          S(e.userParams)
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
        )
      });
    return t;
  }
  /**
   * 生成漏斗图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:03
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @param {number} index
   * @return {*}
   */
  generateFunnelSeriesOption(e, s, r, o) {
zhf's avatar
zhf committed
477 478
    var d;
    const t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (d = e.seriesField) == null ? void 0 : d.toLowerCase(), c = {
479 480 481 482 483 484 485 486 487 488 489 490 491 492
      emphasis: {
        label: {
          fontSize: 20,
          show: !0
        }
      },
      label: {
        formatter: "{b}: {d}%({@age})",
        position: "outside",
        show: !0
      }
    };
    if (a) {
      const g = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
493 494
      s.forEach((p) => {
        const f = p[a];
495 496
        g.add(r && r.series && r.series.get(f) || f);
      }), t.push(
zhf's avatar
zhf committed
497
        ...[...g].map((p) => ({
498
          type: i,
zhf's avatar
zhf committed
499
          name: p,
500 501 502
          datasetIndex: o,
          encode: {
            itemName: n,
zhf's avatar
zhf committed
503
            value: p
504 505 506
          },
          ...y(
            c,
zhf's avatar
zhf committed
507
            S(e.userParams)
508 509 510 511 512 513 514 515 516 517
          )
        }))
      );
    } else
      t.push({
        type: i,
        name: e.caption || e.id,
        datasetIndex: o,
        encode: {
          itemName: n,
zhf's avatar
zhf committed
518
          value: m
519 520 521
        },
        ...y(
          c,
zhf's avatar
zhf committed
522
          S(e.userParams)
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
        )
      });
    return t;
  }
  /**
   * 生成散点图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:25
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @param {number} index
   * @return {*}
   */
  generateScatterSeriesOption(e, s, r, o) {
zhf's avatar
zhf committed
539 540
    var d;
    const t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (d = e.seriesField) == null ? void 0 : d.toLowerCase(), c = {
541 542 543 544 545 546 547 548 549 550 551 552 553
      emphasis: {
        label: {
          fontSize: 20,
          show: !0
        }
      },
      label: {
        position: "top",
        show: !0
      }
    };
    if (a) {
      const g = /* @__PURE__ */ new Set();
zhf's avatar
zhf committed
554 555
      s.forEach((p) => {
        const f = p[a];
556 557
        g.add(r && r.series && r.series.get(f) || f);
      }), t.push(
zhf's avatar
zhf committed
558
        ...[...g].map((p) => ({
559
          type: i,
zhf's avatar
zhf committed
560
          name: p,
561 562 563
          datasetIndex: o,
          encode: {
            x: n,
zhf's avatar
zhf committed
564
            y: p
565 566 567
          },
          ...y(
            c,
zhf's avatar
zhf committed
568
            S(e.userParams)
569 570 571 572 573 574 575 576 577 578
          )
        }))
      );
    } else
      t.push({
        type: i,
        name: e.caption || e.id,
        datasetIndex: o,
        encode: {
          x: n,
zhf's avatar
zhf committed
579
          y: m
580 581 582
        },
        ...y(
          c,
zhf's avatar
zhf committed
583
          S(e.userParams)
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
        )
      });
    return t;
  }
  /**
   * 生成雷达图序列配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:47
   * @param {IPSDEChartSeries} series
   * @param {IData[]} data
   * @param {CodeListMap} map
   * @return {*}
   */
  generateRadarSeriesOption(e, s, r) {
    var f;
zhf's avatar
zhf committed
600
    const o = [], t = [], i = e.eChartsType, n = e.catalogField.toLowerCase(), m = e.valueField.toLowerCase(), a = (f = e.seriesField) == null ? void 0 : f.toLowerCase(), c = {
601 602 603 604 605 606 607 608 609 610 611 612
      emphasis: {
        label: {
          fontSize: 20,
          show: !0
        }
      },
      label: {
        position: "top",
        show: !0
      }
    };
    if (a) {
zhf's avatar
zhf committed
613 614 615 616
      const l = /* @__PURE__ */ new Set();
      s.forEach((C) => {
        l.add(C[a]);
      }), t.push([n, ...l]);
617
    } else
zhf's avatar
zhf committed
618
      t.push([n, m]);
619
    t.push(
zhf's avatar
zhf committed
620 621
      ...s.map((l) => t[0].map((C, w) => w === 0 ? (r && r.catalog ? r.catalog.get(l[C]) : l[C]) || "未定义" : a ? C === l[a] ? l[m] : 0 : l[m]))
    ), r && r.series && (t[0] = t[0].map((l, C) => {
622
      var w;
zhf's avatar
zhf committed
623
      return C === 0 ? l : ((w = r.series) == null ? void 0 : w.get(l)) || l;
624
    }));
zhf's avatar
zhf committed
625 626 627 628 629 630
    for (let l = 1; l < t.length; l++)
      for (let C = l + 1; C < t.length; C++)
        t[C][0] === t[l][0] && (t[C].forEach((w, x) => {
          x !== 0 && (t[l][x] += w);
        }), t.splice(C, 1), C -= 1);
    const d = t[0].slice(1).map((l, C) => t.slice(1).map((w) => w[C + 1]));
631 632 633
    o.push({
      type: i,
      name: e.caption || e.id,
zhf's avatar
zhf committed
634 635
      data: d,
      ...y(c, S(e.userParams))
636 637
    });
    let g = -1 / 0;
zhf's avatar
zhf committed
638 639 640
    d.forEach((l) => {
      l.forEach((C) => {
        +C > g && (g = +C);
641 642
      });
    });
zhf's avatar
zhf committed
643 644
    const p = t.slice(1).map((l) => ({
      name: l[0],
645 646 647 648 649
      max: g
    }));
    return {
      series: o,
      radar: {
zhf's avatar
zhf committed
650
        indicator: p
651 652 653 654
      }
    };
  }
}
zhf's avatar
zhf committed
655
class U extends z {
656 657 658 659 660 661 662 663 664
  constructor() {
    super(...arguments);
    /**
     * 图表实例
     *
     * @author zhanghengfeng
     * @date 2023-04-03 16:04:45
     * @type {(EChartsType | null)}
     */
zhf's avatar
zhf committed
665
    L(this, "chart", null);
666 667 668 669 670 671 672
    /**
     * 图表id
     *
     * @author zhanghengfeng
     * @date 2023-04-03 16:04:22
     * @type {string}
     */
zhf's avatar
zhf committed
673
    L(this, "chartId", `chart_${M()}`);
674 675 676 677 678 679 680
    /**
     * 图表静态配置
     *
     * @author zhanghengfeng
     * @date 2023-04-03 16:04:32
     * @type {EChartsOption}
     */
zhf's avatar
zhf committed
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
    L(this, "chartStaticOption", {});
    /**
     * 渲染前钩子函数
     *
     * @author zhanghengfeng
     * @date 2023-11-10 11:11:06
     */
    L(this, "hook");
    /**
     * 加载后处理钩子函数
     *
     * @author zhanghengfeng
     * @date 2023-11-16 17:11:13
     */
    L(this, "loadHook");
696 697 698 699 700 701 702
    /**
     * 数据集合
     *
     * @author zhanghengfeng
     * @date 2023-04-07 16:04:34
     * @type {IData[]}
     */
zhf's avatar
zhf committed
703
    L(this, "items", []);
704 705 706 707 708 709
    /**
     * 请求参数
     *
     * @author zhanghengfeng
     * @date 2023-04-07 16:04:28
     */
zhf's avatar
zhf committed
710
    L(this, "queryParams", {
711 712 713 714 715 716 717 718 719 720 721
      page: 0,
      size: 1e3,
      query: ""
    });
    /**
     * 图表部件宽度
     *
     * @author zhanghengfeng
     * @date 2023-04-11 15:04:23
     * @type {string}
     */
zhf's avatar
zhf committed
722
    L(this, "width", "100%");
723 724 725 726 727 728 729
    /**
     * 图表部件高度
     *
     * @author zhanghengfeng
     * @date 2023-04-11 15:04:37
     * @type {string}
     */
zhf's avatar
zhf committed
730
    L(this, "height", "100%");
731 732 733 734 735 736 737 738 739 740
  }
  /**
   * 创建图表神经系统
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:24
   * @protected
   * @return {*}  {ChartNerve}
   */
  createNerve() {
zhf's avatar
zhf committed
741
    return new H(this);
742 743 744 745 746 747 748 749 750 751
  }
  /**
   * 初始化配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:41
   * @protected
   * @return {*}  {Promise<void>}
   */
  async onInit() {
zhf's avatar
zhf committed
752
    await super.onInit(), this.service = new B(this.model), await this.service.init(this.context), this.initChartStaticOption(), this.resizeChart = this.resizeChart.bind(this), window.addEventListener("resize", this.resizeChart);
753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
    const { width: e, height: s } = this.model.source;
    e && (this.width = `${e}px`), s && (this.height = `${s}px`);
  }
  /**
   * 重新渲染图表
   *
   * @author zhanghengfeng
   * @date 2023-04-03 18:04:35
   */
  resizeChart() {
    var e;
    (e = this.chart) == null || e.resize();
  }
  /**
   * 初始化图表静态配置
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:52
   */
  initChartStaticOption() {
    const e = {}, s = this.model.source.getPSDEChartTitle();
zhf's avatar
zhf committed
774
    e.title = s ? k(s) : {}, e.tooltip = {
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
      show: !0
    };
    const r = this.model.source.getPSDEChartSerieses();
    r && r.length && r[0].eChartsType === "bar" && (e.tooltip = {
      show: !0,
      padding: 0,
      backgroundColor: "rgba(255, 255, 255, 0)",
      borderWidth: 0,
      className: "chart-tooltip",
      borderRadius: 6,
      extraCssText: "box-shadow: none;",
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      },
      appendToBody: !0,
      formatter: (n) => {
zhf's avatar
zhf committed
792
        const m = n, a = document.createElement("div");
793
        if (a.classList.add("chart-tooltip-container"), Array.isArray(n)) {
zhf's avatar
zhf committed
794 795 796 797 798 799 800
          const c = [], d = /* @__PURE__ */ new Map();
          m.forEach((p) => {
            const f = p.seriesName, l = p.dimensionNames;
            l.slice(1).forEach((C, w) => {
              const x = l.length === 2 ? f : C, b = p.value[w + 1];
              d.has(x) || (c.push({
                x,
801
                y: b
zhf's avatar
zhf committed
802
              }), d.set(x, b));
803 804 805
            });
          });
          const g = document.createElement("div");
zhf's avatar
zhf committed
806
          return g.classList.add("chart-tooltip-title"), g.textContent = m[0].value[0], a.appendChild(g), c.forEach((p) => {
807 808
            const f = document.createElement("div");
            f.classList.add("chart-tooltip-item");
zhf's avatar
zhf committed
809 810 811 812
            const l = document.createElement("div");
            l.classList.add("chart-tooltip-item-name"), l.textContent = p.x, f.appendChild(l);
            const C = document.createElement("div");
            C.classList.add("chart-tooltip-item-number"), C.textContent = p.y, f.appendChild(C), a.appendChild(f);
813 814 815 816 817 818
          }), a;
        }
        return a;
      }
    });
    const o = this.model.source.getPSDEChartLegend();
zhf's avatar
zhf committed
819
    e.legend = o ? q(o) : {};
820
    const t = this.model.source.getPSChartXAxises();
zhf's avatar
zhf committed
821
    e.xAxis = t ? R(t) : [];
822
    const i = this.model.source.getPSChartYAxises();
zhf's avatar
zhf committed
823
    e.yAxis = i ? V(i) : [], Object.assign(
824
      this.chartStaticOption,
zhf's avatar
zhf committed
825
      y(e, S(this.model.source.userParams))
826 827
    );
  }
zhf's avatar
zhf committed
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847
  /**
   * 注册渲染前钩子函数
   *
   * @author zhanghengfeng
   * @date 2023-11-14 10:11:42
   * @param {(_option: EChartsOption) => EChartsOption} hook
   */
  registerHook(e) {
    this.hook = e;
  }
  /**
   * 注册加载后处理钩子函数
   *
   * @author zhanghengfeng
   * @date 2023-11-16 17:11:13
   * @param {(_data: IData) => IData} hook
   */
  registerLoadHook(e) {
    this.loadHook = e;
  }
848 849 850 851 852 853 854 855 856 857 858
  /**
   * 加载数据
   *
   * @author zhanghengfeng
   * @date 2023-04-03 16:04:13
   * @param {IParams} params
   */
  async load() {
    var e;
    await this.startLoading();
    try {
zhf's avatar
zhf committed
859
      let { data: s } = await this.service.fetch(this.context, {
860 861 862
        ...this.params,
        ...this.queryParams
      });
zhf's avatar
zhf committed
863
      if (s = this.loadHook ? this.loadHook(s) : s, Array.isArray(s) && s.length) {
864
        if (this.items = s, !this.chart) {
zhf's avatar
zhf committed
865 866
          const i = document.querySelector(`#${this.chartId}`);
          if (!i)
867
            throw new Error("未找到ECharts绘制容器元素");
zhf's avatar
zhf committed
868
          this.chart = D(i);
869 870 871 872 873
        }
        const r = await this.service.generateChartOption(
          s,
          this.context,
          this.params
zhf's avatar
zhf committed
874 875 876
        ), o = y(
          this.chartStaticOption,
          r
877
        );
zhf's avatar
zhf committed
878 879
        let t = o;
        this.hook && (t = await this.hook(o)), this.chart.setOption(t);
880 881 882 883 884 885 886 887 888 889 890
      } else
        this.items = [], (e = this.chart) == null || e.clear();
    } finally {
      await this.endLoading();
    }
  }
  destroy() {
    var e;
    super.destroy(), (e = this.chart) == null || e.dispose(), window.removeEventListener("resize", this.resizeChart);
  }
}
zhf's avatar
zhf committed
891 892
function Q(h, u, e, s = {}) {
  return T(h, () => new U(u, e, s));
893 894
}
export {
zhf's avatar
zhf committed
895
  Q as u
896
};