[fix] elite cycle bug

This commit is contained in:
Jordan Hsu
2021-06-11 13:09:29 +08:00
parent fca7f1a093
commit fd31d41bdb
@@ -35,7 +35,7 @@ export default {
metaID: 0,
showWhichCycles: '',
cycleNum: 0,
eachSliceNum: 0, // 每一等分data數量
cycleDataID: 3, // [TODO] manage by data type factory
}
},
computed: {
@@ -83,26 +83,50 @@ export default {
setCycle () {
console.log('setCycle')
if (this.cycleNum !== 0) {
// get cycle data
const allCycleData = this.recInfo[this.metaID][this.cycleDataID][this.currentScale][this.metaIndex].data
var cycleDict = {}
var cycleStartIndex = 0
var cycleEndIndex = 0
var currentCycleIndex = 0
for (let index = 0; index < allCycleData.length; index++) {
const value = allCycleData[index]
const cycleIndex = parseInt(value[1])
if (cycleIndex === currentCycleIndex) {
if (currentCycleIndex in cycleDict) {
cycleEndIndex = index
cycleDict[cycleIndex][1] = cycleEndIndex
} else {
cycleDict[cycleIndex] = [cycleStartIndex, cycleEndIndex]
}
} else {
cycleStartIndex = index
currentCycleIndex++
}
}
// get recording data
let allXData
if (this.axisXDataType.description !== 'Time') {
allXData = this.recInfo[this.metaID][this.axisXDataType.id][this.currentScale][this.metaIndex].data
}
const allYData = this.recInfo[this.metaID][this.axisYDataType.id][this.currentScale][this.metaIndex].data
const len = allYData.length
const eachSliceNum = parseInt(len / this.cycleNum)
const data = []
for (let sliceIndex = 0; sliceIndex < this.cycleNum; sliceIndex++) {
// console.log(this.slices)
if (this.slices === '' || this.slices.includes((sliceIndex + 1).toString())) {
const sliceYData = allYData.slice(sliceIndex * eachSliceNum, (sliceIndex + 1) * eachSliceNum)
// slice data
const value = cycleDict[sliceIndex + 1]
const start = value[0]
const end = value[1] + 1
const sliceYData = allYData.slice(start, end)
const sliceLen = sliceYData.length
if (allXData !== undefined) {
const sliceXData = allXData.slice(sliceIndex * eachSliceNum, (sliceIndex + 1) * eachSliceNum)
const sliceXData = allXData.slice(start, end)
for (let j = 0; j < sliceLen; j++) {
data.push([sliceXData[j][1], sliceYData[j][1]])
}
} else {
const sliceYData = allYData.slice(sliceIndex * eachSliceNum, (sliceIndex + 1) * eachSliceNum)
const sliceYData = allYData.slice(start, end)
for (let j = 0; j < sliceLen; j++) {
data.push(sliceYData[j])
}
@@ -112,7 +136,7 @@ export default {
this.updateSeriesChart({
chartID: this.chartID,
seriesIndex: this.metaIndex,
data: data,
data: JSON.parse(JSON.stringify(data)),
})
}
this.$emit('refreshChart', this.chartData[this.chartID])