| | |
| | | /** |
| | | * @description 图表数据预处理 |
| | | * 1、通过显示列进行数据类型转换 |
| | | * 2、重复数据:取平均值、累计、去重 |
| | | * 3、柱状图数据补齐 |
| | | */ |
| | | getdata = () => { |
| | | const { plot } = this.state |
| | |
| | | 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 => { |
| | | 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 |
| | | 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])) { |
| | | item[plot.Yaxis] = 0 |
| | | } |
| | | } |
| | | |
| | | 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) |
| | | } |
| | | }) |
| | | item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal) |
| | | |
| | | _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 |
| | | return item |
| | | }) |
| | | } |
| | | |
| | | getnestdata = () => { |
| | |
| | | } |
| | | |
| | | 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]) { |
| | | let _mdata = new Map() |
| | | let map = new Map() |
| | | let sort = 1 |
| | | 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 |
| | | } |
| | | |
| | | if (typeof(item[plot.Yaxis]) !== 'number') { |
| | | item[plot.Yaxis] = parseFloat(item[plot.Yaxis]) |
| | | if (isNaN(item[plot.Yaxis])) { |
| | | return |
| | | } |
| | | } |
| | | |
| | | item.$type = item[plot.type] |
| | | let sign = item.$type + item[plot.Xaxis] |
| | | item.$type = item[plot.type] |
| | | |
| | | if (!_mdata.has(sign)) { |
| | | let _sort = sort |
| | | if (map.has(item.$type)) { |
| | | _sort = map.get(item.$type) |
| | | } else { |
| | | map.set(item.$type, _sort) |
| | | sort++ |
| | | } |
| | | 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) |
| | | } |
| | | }) |
| | | item.$sort = _sort |
| | | item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal) |
| | | |
| | | _data = [..._mdata.values()] |
| | | _data = _data.map(item => { |
| | | item[plot.Yaxis] = item[plot.Yaxis] / item.$count |
| | | item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal) |
| | | _mdata.set(sign, true) |
| | | |
| | | 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 => { |
| | | let sign = item[plot.type] + item[plot.Xaxis] |
| | | if (!item[plot.Xaxis] || !item[plot.type] || _mdata.has(sign)) { |
| | | return |
| | | } |
| | | |
| | | if (typeof(item[plot.Yaxis]) !== 'number') { |
| | | item[plot.Yaxis] = parseFloat(item[plot.Yaxis]) |
| | | if (isNaN(item[plot.Yaxis])) { |
| | | return |
| | | } |
| | | } |
| | | |
| | | item.$type = item[plot.type] |
| | | |
| | | let _sort = sort |
| | | if (map.has(item.$type)) { |
| | | _sort = map.get(item.$type) |
| | | } else { |
| | | map.set(item.$type, _sort) |
| | | sort++ |
| | | } |
| | | |
| | | item.$sort = _sort |
| | | item[plot.Yaxis] = +item[plot.Yaxis].toFixed(plot.$decimal) |
| | | |
| | | _mdata.set(sign, item) |
| | | }) |
| | | |
| | | _data = [..._mdata.values()] |
| | | } |
| | | _data.push(item) |
| | | }) |
| | | |
| | | this.setState({empty: _data.length === 0}) |
| | | |