graph: handle min value of zero
This commit is contained in:
parent
7571a069d0
commit
dffc61ebe4
|
@ -8,6 +8,7 @@ import { getInitialProbability } from 'common/calculate'
|
|||
import { BinaryContract, PseudoNumericContract } from 'common/contract'
|
||||
import { useWindowSize } from 'web/hooks/use-window-size'
|
||||
import { getMappedValue } from 'common/pseudo-numeric'
|
||||
import { formatLargeNumber } from 'common/util/format'
|
||||
|
||||
export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
||||
contract: BinaryContract | PseudoNumericContract
|
||||
|
@ -17,6 +18,7 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
|||
const { contract, height } = props
|
||||
const { resolutionTime, closeTime, outcomeType } = contract
|
||||
const isBinary = outcomeType === 'BINARY'
|
||||
const isLogScale = outcomeType === 'PSEUDO_NUMERIC' && contract.isLogScale
|
||||
|
||||
const bets = props.bets.filter((bet) => !bet.isAnte && !bet.isRedemption)
|
||||
|
||||
|
@ -67,9 +69,10 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
|||
|
||||
const points: { x: Date; y: number }[] = []
|
||||
const s = isBinary ? 100 : 1
|
||||
const c = isLogScale && contract.min === 0 ? 1 : 0
|
||||
|
||||
for (let i = 0; i < times.length - 1; i++) {
|
||||
points[points.length] = { x: times[i], y: s * probs[i] }
|
||||
points[points.length] = { x: times[i], y: s * probs[i] + c }
|
||||
const numPoints: number = Math.floor(
|
||||
dayjs(times[i + 1]).diff(dayjs(times[i]), 'ms') / timeStep
|
||||
)
|
||||
|
@ -81,7 +84,7 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
|||
x: dayjs(times[i])
|
||||
.add(thisTimeStep * n, 'ms')
|
||||
.toDate(),
|
||||
y: s * probs[i],
|
||||
y: s * probs[i] + c,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +97,9 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
|||
const multiYear = !dayjs(startDate).isSame(latestTime, 'year')
|
||||
const lessThanAWeek = dayjs(startDate).add(8, 'day').isAfter(latestTime)
|
||||
|
||||
const formatter = isBinary ? formatPercent : formatNumeric
|
||||
const formatter = isBinary
|
||||
? formatPercent
|
||||
: (x: DatumValue) => formatLargeNumber(+x.valueOf())
|
||||
|
||||
return (
|
||||
<div
|
||||
|
@ -107,8 +112,8 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
|
|||
isBinary
|
||||
? { min: 0, max: 100, type: 'linear' }
|
||||
: {
|
||||
min: contract.min,
|
||||
max: contract.max,
|
||||
min: contract.min + c,
|
||||
max: contract.max + c,
|
||||
type: contract.isLogScale ? 'log' : 'linear',
|
||||
}
|
||||
}
|
||||
|
@ -162,10 +167,6 @@ function formatPercent(y: DatumValue) {
|
|||
return `${Math.round(+y.toString())}%`
|
||||
}
|
||||
|
||||
function formatNumeric(y: DatumValue) {
|
||||
return `${Math.round(+y.toString())}`
|
||||
}
|
||||
|
||||
function formatTime(
|
||||
time: number,
|
||||
includeYear: boolean,
|
||||
|
|
Loading…
Reference in New Issue
Block a user