forked from ddrilling/asb_cloud_front
filter заменён на интерполяционный поиск
This commit is contained in:
parent
f9d019ffda
commit
023d032e9d
@ -3,12 +3,48 @@ import { Grid, GridItem } from '../../components/Grid'
|
||||
import { ArchiveColumn } from './ArchiveColumn'
|
||||
import { paramsGroups } from '../TelemetryView'
|
||||
|
||||
const interpolationSearch = (data, begin, end, accessor) => {
|
||||
const fy = (i) => new Date(data[i]?.[accessor] ?? 0)
|
||||
const fx = (y, b, e) => Math.round(b + (y - fy(b)) * (e - b) / (fy(e) - fy(b)))
|
||||
const findIdx = (val, startIdx, c) => {
|
||||
let x = startIdx
|
||||
let endIdx = data.length - 1
|
||||
if(val < fy(startIdx))
|
||||
return startIdx
|
||||
if(val > fy(endIdx))
|
||||
return endIdx
|
||||
for(let i = 0; i < c; i++){
|
||||
x = fx(val, startIdx, endIdx)
|
||||
if(fy(x) < val)
|
||||
startIdx = x
|
||||
else
|
||||
endIdx = x
|
||||
if ((startIdx === endIdx)||(fy(startIdx) === fy(endIdx)))
|
||||
return x
|
||||
}
|
||||
return x
|
||||
}
|
||||
let x0 = findIdx(begin, 0, 5)
|
||||
let x1 = findIdx(end, x0, 3)
|
||||
return { start: x0, end: x1, count: x1 - x0 }
|
||||
}
|
||||
|
||||
export const cutData = (data, beginDate, endDate) => {
|
||||
if (data?.length > 0) {
|
||||
let { start, end } = interpolationSearch(data, beginDate, endDate, 'date')
|
||||
if (start > 0) start--
|
||||
if (end + 1 < end.length) end++
|
||||
return data.slice(start, end)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
export const ArchiveDisplay = ({data, startDate, interval, onWheel}) => {
|
||||
const [chartData, setChartData] = useState([])
|
||||
|
||||
useEffect(() => {
|
||||
const endDate = new Date(+startDate + interval)
|
||||
setChartData(data.filter(elm => elm.date >= startDate && elm.date <= endDate))
|
||||
setChartData(cutData(data, startDate, endDate))
|
||||
}, [data, startDate, interval])
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user