/* 基本柱状图 */
import Echart from '../echart'
import getOption from '../../libs/get_option'

class Gauge extends Echart {
  constructor(layer, screen) {
    super(layer, screen)
    this.data = []
  }

  setPaint() {
    let paint = this._initPaint()
    let option = this._getOption(paint)
    this._render(option)
  }

  _getOption(paint) {
    let option = getOption(paint, this.type)
    for (let i = 0; i < option.series.length; i++) {
      option.series[i].data = this.data[i] || []
    }
    return option
  }

  /**
   * 根据paint属性中指定的字段，将表格数据处理成图表组件需要的格式
   */
  reduceData(paint) {
    if (!this.originalData || !this.originalData.length) {
      this.data = []
      return
    }
    let series = paint.series
    let seriesData = []
    series.forEach(s => {
      let d = this.originalData[0]
      let t = { name: '', value: '' }
      if (s.nameField) {
        t.name = d[s.nameField]
      } else {
        t.name = s.name
      }
      if (s.valueField) {
        t.value = d[s.valueField]
      }
      let sd = [t]
      seriesData.push(sd)
    })
    this.data = seriesData
  }
}

export default Gauge
