import * as ECharts from "echarts";

const HANDLER = "_vue_resize_handler";
export const vEchartResize = {
    mounted(el:any,binding:any){
        el[HANDLER] = binding.value
        ? binding.value
        : () => {
            let chart = ECharts.getInstanceByDom(el);
            if (!chart) {
              return;
            }
            chart.resize();
          };
          window.addEventListener("resize",el[HANDLER]);
    },
    beforeUnmount(el:any){
        window.removeEventListener("resize",el[HANDLER]);
    }
}
