From 023d032e9d5c82a514b23cbcfd3cfe3645be65ab Mon Sep 17 00:00:00 2001 From: goodmice Date: Fri, 12 Nov 2021 16:23:26 +0500 Subject: [PATCH] =?UTF-8?q?filter=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=B0=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8F=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B8=D1=81=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Archive/ArchiveDisplay.jsx | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/pages/Archive/ArchiveDisplay.jsx b/src/pages/Archive/ArchiveDisplay.jsx index 54db8b7..7035c82 100644 --- a/src/pages/Archive/ArchiveDisplay.jsx +++ b/src/pages/Archive/ArchiveDisplay.jsx @@ -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 (