import Chart from "./Chart"; import { isEmpty } from "@vci/helper/src/other"; export default class ChartHighLight extends Chart { #ic; init() { super.init(); this.isChartHighLight = true; this.amtHighLight = { indexCurrent: 0 }; } initEc() { super.initEc(); this._pause = this.pause.bind(this); this._play = this.play.bind(this); this.el.addEventListener("pointermove", this._pause); this.el.addEventListener("pointerleave", this._play); this.ec.on("highlight", e => { if(!isEmpty(e.dataIndex)) this.amtHighLight.indexCurrent = e.dataIndex; if(e.batch && e.batch.length > 0) this.amtHighLight.indexCurrent = e.batch[0].dataIndex; this.dispatchEvent("highlight", { indexCurrent: this.amtHighLight.indexCurrent }); }); } getLength() { throw new Error("请实现获取数据长度方法 getLength"); } play() { const { indexCurrent } = this.amtHighLight; const length = this.getLength(); this.pause(); !isEmpty(this.#ic) && this.ec.dispatchAction({ type: "downplay", dataIndex: this.#ic }); this.#ic = Math.min(indexCurrent, length - 1); this.ec.dispatchAction({ type: "highlight", dataIndex: this.#ic }); this.dispatchEvent("play", { indexCurrent: this.#ic }); if(indexCurrent + 1 >= length) { this.amtHighLight.indexCurrent = 0; this.dispatchEvent("playEnd"); } else this.amtHighLight.indexCurrent++; this.inter.highLight = setTimeout(this.play.bind(this), 2e3); } pause() { clearTimeout(this.inter.highLight); } stop() { this.pause(); this.ec.dispatchAction({ type: "downplay" }); } destroy() { super.destroy(); this.el.removeEventListener("pointermove", this._pause); this.el.removeEventListener("pointerleave", this._play); this.stop(); } }