Use numbers instead of dates to calculate visible range
This commit is contained in:
parent
de7cf62918
commit
5ade0bbd3e
|
@ -49,24 +49,24 @@ export const BinaryContractChart = (props: {
|
||||||
onMouseOver?: (p: HistoryPoint<Bet> | undefined) => void
|
onMouseOver?: (p: HistoryPoint<Bet> | undefined) => void
|
||||||
}) => {
|
}) => {
|
||||||
const { contract, bets, onMouseOver } = props
|
const { contract, bets, onMouseOver } = props
|
||||||
const [startDate, endDate] = getDateRange(contract)
|
const [start, end] = getDateRange(contract)
|
||||||
const startP = getInitialProbability(contract)
|
const startP = getInitialProbability(contract)
|
||||||
const endP = getProbability(contract)
|
const endP = getProbability(contract)
|
||||||
const betPoints = useMemo(() => getBetPoints(bets), [bets])
|
const betPoints = useMemo(() => getBetPoints(bets), [bets])
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
return [
|
return [
|
||||||
{ x: new Date(startDate), y: startP },
|
{ x: new Date(start), y: startP },
|
||||||
...betPoints,
|
...betPoints,
|
||||||
{ x: new Date(endDate ?? Date.now() + DAY_MS), y: endP },
|
{ x: new Date(end ?? Date.now() + DAY_MS), y: endP },
|
||||||
]
|
]
|
||||||
}, [startDate, startP, endDate, endP, betPoints])
|
}, [start, startP, end, endP, betPoints])
|
||||||
|
|
||||||
const rightmostDate = getRightmostVisibleDate(
|
const rightmostDate = getRightmostVisibleDate(
|
||||||
endDate ? new Date(endDate) : null,
|
end,
|
||||||
last(betPoints)?.x,
|
last(betPoints)?.x?.getTime(),
|
||||||
new Date(Date.now())
|
Date.now()
|
||||||
)
|
)
|
||||||
const visibleRange = [startDate, rightmostDate]
|
const visibleRange = [start, rightmostDate]
|
||||||
const isMobile = useIsMobile(800)
|
const isMobile = useIsMobile(800)
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const width = useElementWidth(containerRef) ?? 0
|
const width = useElementWidth(containerRef) ?? 0
|
||||||
|
|
|
@ -146,9 +146,9 @@ export const ChoiceContractChart = (props: {
|
||||||
[answers, contract, betPoints, start, end]
|
[answers, contract, betPoints, start, end]
|
||||||
)
|
)
|
||||||
const rightmostDate = getRightmostVisibleDate(
|
const rightmostDate = getRightmostVisibleDate(
|
||||||
end ? new Date(end) : null,
|
end,
|
||||||
last(betPoints)?.x,
|
last(betPoints)?.x?.getTime(),
|
||||||
new Date(Date.now())
|
Date.now()
|
||||||
)
|
)
|
||||||
const visibleRange = [start, rightmostDate]
|
const visibleRange = [start, rightmostDate]
|
||||||
const isMobile = useIsMobile(800)
|
const isMobile = useIsMobile(800)
|
||||||
|
|
|
@ -62,7 +62,7 @@ export const PseudoNumericContractChart = (props: {
|
||||||
}) => {
|
}) => {
|
||||||
const { contract, bets, onMouseOver } = props
|
const { contract, bets, onMouseOver } = props
|
||||||
const { min, max, isLogScale } = contract
|
const { min, max, isLogScale } = contract
|
||||||
const [startDate, endDate] = getDateRange(contract)
|
const [start, end] = getDateRange(contract)
|
||||||
const scaleP = useMemo(
|
const scaleP = useMemo(
|
||||||
() => getScaleP(min, max, isLogScale),
|
() => getScaleP(min, max, isLogScale),
|
||||||
[min, max, isLogScale]
|
[min, max, isLogScale]
|
||||||
|
@ -72,18 +72,18 @@ export const PseudoNumericContractChart = (props: {
|
||||||
const betPoints = useMemo(() => getBetPoints(bets, scaleP), [bets, scaleP])
|
const betPoints = useMemo(() => getBetPoints(bets, scaleP), [bets, scaleP])
|
||||||
const data = useMemo(
|
const data = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{ x: new Date(startDate), y: startP },
|
{ x: new Date(start), y: startP },
|
||||||
...betPoints,
|
...betPoints,
|
||||||
{ x: new Date(endDate ?? Date.now() + DAY_MS), y: endP },
|
{ x: new Date(end ?? Date.now() + DAY_MS), y: endP },
|
||||||
],
|
],
|
||||||
[betPoints, startDate, startP, endDate, endP]
|
[betPoints, start, startP, end, endP]
|
||||||
)
|
)
|
||||||
const rightmostDate = getRightmostVisibleDate(
|
const rightmostDate = getRightmostVisibleDate(
|
||||||
endDate ? new Date(endDate) : null,
|
end,
|
||||||
last(betPoints)?.x,
|
last(betPoints)?.x?.getTime(),
|
||||||
new Date(Date.now())
|
Date.now()
|
||||||
)
|
)
|
||||||
const visibleRange = [startDate, rightmostDate]
|
const visibleRange = [start, rightmostDate]
|
||||||
const isMobile = useIsMobile(800)
|
const isMobile = useIsMobile(800)
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
const containerRef = useRef<HTMLDivElement>(null)
|
||||||
const width = useElementWidth(containerRef) ?? 0
|
const width = useElementWidth(containerRef) ?? 0
|
||||||
|
|
|
@ -263,15 +263,15 @@ export const getDateRange = (contract: Contract) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getRightmostVisibleDate = (
|
export const getRightmostVisibleDate = (
|
||||||
contractEnd: Date | null | undefined,
|
contractEnd: number | null | undefined,
|
||||||
lastActivity: Date | null | undefined,
|
lastActivity: number | null | undefined,
|
||||||
now: Date
|
now: number
|
||||||
) => {
|
) => {
|
||||||
if (contractEnd != null) {
|
if (contractEnd != null) {
|
||||||
return contractEnd
|
return contractEnd
|
||||||
} else if (lastActivity != null) {
|
} else if (lastActivity != null) {
|
||||||
// client-DB clock divergence may cause last activity to be later than now
|
// client-DB clock divergence may cause last activity to be later than now
|
||||||
return new Date(Math.max(lastActivity.getTime(), now.getTime()))
|
return Math.max(lastActivity, now)
|
||||||
} else {
|
} else {
|
||||||
return now
|
return now
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user