import * as echarts from 'echarts'

// px自适应
let windowWidth = document.documentElement.clientWidth;
export function nowSize(val,initWidth=1920){
  return Math.ceil(val * (windowWidth/initWidth));
}

export function setOptions(ele, option) {
  let myEchart = echarts.init(ele)
  myEchart.setOption({
    ...option,
  }, true)
  myEchart.resize({
    width: myEchart._dom.clientWidth,
    height: myEchart._dom.clientHeight,
  })
  window.addEventListener('resize', () => {
    windowWidth = document.documentElement.clientWidth;
    myEchart.resize({
      width: myEchart._dom.clientWidth,
      height: myEchart._dom.clientHeight,
    })
  })
  return myEchart
}
