import * as echarts from 'echarts'

// px自适应
let windowHeight = document.documentElement.clientHeight;
export function nowSize(val,initHeight=1080){
  return Math.ceil(val * (windowHeight/initHeight));
}

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', () => {
    windowHeight = document.documentElement.clientHeight;
    myEchart.resize({
      width: myEchart._dom.clientWidth,
      height: myEchart._dom.clientHeight,
    })
  })
  return myEchart
}
