king
2023-12-12 49f09cc6f8ff8c30a75ed1a9d6f510b69b73962a
src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -353,8 +353,6 @@
  /**
   * @description 图表数据预处理
   * 1、通过显示列进行数据类型转换
   * 2、重复数据:取平均值、累计、去重
   * 3、柱状图数据补齐
   */
  getdata = () => {
    const { plot } = this.state
@@ -362,91 +360,22 @@
    if (this.data.length === 0) {
      this.setState({empty: true})
      return []
    } else {
      this.setState({empty: false})
    }
    let _data = []
    let _cdata = fromJS(this.data).toJS()
    if (plot.repeat === 'average') {
      let _mdata = new Map()
      _cdata.forEach(item => {
    return fromJS(this.data).toJS().map(item => {
        if (typeof(item[plot.Yaxis]) !== 'number') {
          item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
          if (isNaN(item[plot.Yaxis])) {
            return
          item[plot.Yaxis] = 0
          }
        } else if (!item[plot.Xaxis]) {
          return
        }
        if (!_mdata.has(item[plot.Xaxis])) {
          item.$count = 1
          _mdata.set(item[plot.Xaxis], item)
        } else {
          let _item = _mdata.get(item[plot.Xaxis])
          _item.$count++
          _item[plot.Yaxis] += item[plot.Yaxis]
          _mdata.set(item[plot.Xaxis], _item)
        }
      })
      _data = [..._mdata.values()]
      _data = _data.map(item => {
        item[plot.Yaxis] = item[plot.Yaxis] / item.$count
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        return item
      })
    } else if (plot.repeat === 'cumsum') {
      let _mdata = new Map()
      _cdata.forEach(item => {
        if (typeof(item[plot.Yaxis]) !== 'number') {
          item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
          if (isNaN(item[plot.Yaxis])) {
            return
          }
        } else if (!item[plot.Xaxis]) {
          return
        }
        if (!_mdata.has(item[plot.Xaxis])) {
          _mdata.set(item[plot.Xaxis], item)
        } else {
          let _item = _mdata.get(item[plot.Xaxis])
          _item[plot.Yaxis] += item[plot.Yaxis]
          _mdata.set(item[plot.Xaxis], _item)
        }
      })
      _data = [..._mdata.values()]
      _data = _data.map(item => {
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        return item
      })
    } else { // plot.repeat === 'unrepeat'
      let _mdata = new Map()
      _cdata.forEach(item => {
        if (!item[plot.Xaxis] || _mdata.has(item[plot.Xaxis])) {
          return
        }
        if (typeof(item[plot.Yaxis]) !== 'number') {
          item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
          if (isNaN(item[plot.Yaxis])) {
            return
          }
        }
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        _mdata.set(item[plot.Xaxis], item)
      })
      _data = [..._mdata.values()]
    }
    this.setState({empty: _data.length === 0})
    return _data
  }
  getnestdata = () => {
@@ -458,97 +387,11 @@
    }
    let _data = []
    let _cdata = fromJS(this.data).toJS()
    if (plot.repeat === 'average') {
      let _mdata = new Map()
      let map = new Map()
      let sort = 1
      _cdata.forEach(item => {
        if (typeof(item[plot.Yaxis]) !== 'number') {
          item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
          if (isNaN(item[plot.Yaxis])) {
            return
          }
        } else if (!item[plot.Xaxis] || !item[plot.type]) {
          return
        }
        item.$type = item[plot.type]
        let sign = item.$type + item[plot.Xaxis]
        if (!_mdata.has(sign)) {
          let _sort = sort
          if (map.has(item.$type)) {
            _sort = map.get(item.$type)
          } else {
            map.set(item.$type, _sort)
            sort++
          }
          item.$count = 1
          item.$sort = _sort
          _mdata.set(sign, item)
        } else {
          let _item = _mdata.get(sign)
          _item.$count++
          _item[plot.Yaxis] += item[plot.Yaxis]
          _mdata.set(sign, _item)
        }
      })
      _data = [..._mdata.values()]
      _data = _data.map(item => {
        item[plot.Yaxis] = item[plot.Yaxis] / item.$count
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        return item
      })
    } else if (plot.repeat === 'cumsum') {
      let _mdata = new Map()
      let map = new Map()
      let sort = 1
      _cdata.forEach(item => {
        if (typeof(item[plot.Yaxis]) !== 'number') {
          item[plot.Yaxis] = parseFloat(item[plot.Yaxis])
          if (isNaN(item[plot.Yaxis])) {
            return
          }
        } else if (!item[plot.Xaxis] || !item[plot.type]) {
          return
        }
        item.$type = item[plot.type]
        let sign = item.$type + item[plot.Xaxis]
        if (!_mdata.has(sign)) {
          let _sort = sort
          if (map.has(item.$type)) {
            _sort = map.get(item.$type)
          } else {
            map.set(item.$type, _sort)
            sort++
          }
          item.$sort = _sort
          _mdata.set(sign, item)
        } else {
          let _item = _mdata.get(sign)
          _item[plot.Yaxis] += item[plot.Yaxis]
          _mdata.set(sign, _item)
        }
      })
      _data = [..._mdata.values()]
      _data = _data.map(item => {
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        return item
      })
    } else { // plot.repeat === 'unrepeat'
      let _mdata = new Map()
      let map = new Map()
      let sort = 1
      _cdata.forEach(item => {
    fromJS(this.data).toJS().forEach(item => {
        let sign = item[plot.type] + item[plot.Xaxis]
        if (!item[plot.Xaxis] || !item[plot.type] || _mdata.has(sign)) {
          return
@@ -574,11 +417,10 @@
        item.$sort = _sort
        item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal)
        _mdata.set(sign, item)
      })
      _mdata.set(sign, true)
      _data = [..._mdata.values()]
    }
      _data.push(item)
    })
    this.setState({empty: _data.length === 0})