// let arr = [{a:20,x:1},{a:20,x:1},{a:23,x:2},{a:31,x:3},{a:31,x:3},{a:20,x:4},{a:32,x:5},{a:32,x:5},{a:32,x:5}]
let arr = [{a:10,x:1},{a:10,x:1},{a:10,x:2}]
let polylineArr = []
let arrI = []
console.log(arr.every(it => {
return it.a > 30
}))
console.log(arr.every(it => {
return it.a < 30
}))
for(let i = 1; i<arr.length; i++) {
let a = arr[i].a
let _a = arr[i-1].a
if (_a < 30 && a > 30) {
arrI.push(i)
} else if (_a > 30 && a < 30) {
arrI.push(i)
}
}
let ss = 0
arrI.forEach((it, index) => {
if (index === arrI.length - 1) {
polylineArr.push(arr.slice(ss))
} else {
polylineArr.push(arr.slice(ss, it+1))
ss = it
}
})
function test(arr, rate) {
let newArr = []
if (!Array.isArray(arr)) return
let isWorkArr = arr.every(it => {
return it.a < rate
})
// 全部都是工作状态
if (isWorkArr) {
return {
points: arr,
color:"#EE1212",
width:2
}
}
let isNoWorkArr = arr.every(it => {
return it.a > rate
})
// 全部都是不在工作状态
if (isNoWorkArr) {
return {
points: arr,
color:"#EEfffd",
width:2
}
}
// 混合状态
let polylineArr = []
let arrI = []
for(let i = 1; i<arr.length; i++) {
let a = arr[i].a
let _a = arr[i-1].a
if (_a < 30 && a > 30) {
arrI.push(i)
} else if (_a > 30 && a < 30) {
arrI.push(i)
}
}
let currtInx = 0
arrI.forEach((it, index) => {
if (index === arrI.length - 1) {
polylineArr.push(arr.slice(currtInx))
} else {
polylineArr.push(arr.slice(currtInx, it+1))
currtInx = it
}
})
polylineArr.forEach(it => {
})
}
console.log(polylineArr)
console