Архив:

* Исправлена ошибка при переключении периода
* Подкорректирована работа интерполяционного поиска
This commit is contained in:
goodmice 2022-07-19 15:01:20 +05:00
parent 547baa6289
commit c9f28a45af

View File

@ -86,8 +86,8 @@ const interpolationSearch = (data, begin, end, accessor) => {
}
return x
}
let x0 = findIdx(begin, 0, 5)
let x1 = findIdx(end, x0, 3)
let x0 = findIdx(begin, 0, 100)
let x1 = findIdx(end, x0, 100)
return { start: x0, end: x1, count: x1 - x0 }
}
@ -111,10 +111,10 @@ const Archive = memo(() => {
const [search, setSearchParams] = useSearchParams()
const getInitialRange = useCallback(() => parseInt(search.get('range') ?? defaultPeriod) * 1000, [search])
const getInitialDate = useCallback(() => new Date(search.get('start') ?? (Date.now() - chartInterval)), [search])
const [scrollPercent, setScrollPercent] = useState(0.15)
const [chartInterval, setChartInterval] = useState(getInitialRange)
const getInitialDate = useCallback(() => new Date(search.get('start') ?? (Date.now() - chartInterval)), [search, chartInterval])
const [startDate, setStartDate] = useState(getInitialDate)
const onGraphWheel = useCallback((e) => {
@ -133,7 +133,7 @@ const Archive = memo(() => {
if (!date) return false
const dt = new Date(date).setHours(0, 0, 0, 0)
return dt < dateLimit.from || dt > +dateLimit.to - chartInterval
}, [dateLimit])
}, [dateLimit, chartInterval])
const isDateTimeDisabled = useCallback((date) => ({
disabledHours: () => range(24).filter(h => {
@ -151,7 +151,7 @@ const Archive = memo(() => {
const dt = +new Date(date).setSeconds(s)
return dt < dateLimit.from || dt > +dateLimit.to - chartInterval
})
}), [dateLimit])
}), [dateLimit, chartInterval])
useEffect(() => {
const params = {}
@ -213,6 +213,7 @@ const Archive = memo(() => {
const onRangeChange = useCallback((value) => {
setChartInterval(value * 1000)
setDataSaub([])
setLoaded(null)
}, [])
const domain = useMemo(() => ({ min: startDate, max: new Date(+startDate + chartInterval)}), [startDate, chartInterval])