diff --git a/common/pseudo-numeric.ts b/common/pseudo-numeric.ts index c99e670f..73f9fd01 100644 --- a/common/pseudo-numeric.ts +++ b/common/pseudo-numeric.ts @@ -16,8 +16,8 @@ export const getMappedValue = const { min, max, isLogScale } = contract if (isLogScale) { - const logValue = p * Math.log10(max - min) - return 10 ** logValue + min + const logValue = p * Math.log10(max - min + 1) + return 10 ** logValue + min - 1 } return p * (max - min) + min @@ -38,7 +38,7 @@ export const getPseudoProbability = ( isLogScale = false ) => { if (isLogScale) { - return Math.log10(value - min) / Math.log10(max - min) + return Math.log10(value - min + 1) / Math.log10(max - min + 1) } return (value - min) / (max - min) diff --git a/web/components/contract/contract-prob-graph.tsx b/web/components/contract/contract-prob-graph.tsx index a9d26e2e..c6e17cd6 100644 --- a/web/components/contract/contract-prob-graph.tsx +++ b/web/components/contract/contract-prob-graph.tsx @@ -7,7 +7,6 @@ import { Bet } from 'common/bet' 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: { @@ -29,7 +28,11 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: { ...bets.map((bet) => bet.createdTime), ].map((time) => new Date(time)) - const f = getMappedValue(contract) + const f: (p: number) => number = isBinary + ? (p) => p + : isLogScale + ? (p) => p * Math.log10(contract.max - contract.min + 1) + : (p) => p * (contract.max - contract.min) + contract.min const probs = [startProb, ...bets.map((bet) => bet.probAfter)].map(f) @@ -69,10 +72,9 @@ 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] + c } + points[points.length] = { x: times[i], y: s * probs[i] } const numPoints: number = Math.floor( dayjs(times[i + 1]).diff(dayjs(times[i]), 'ms') / timeStep ) @@ -84,7 +86,7 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: { x: dayjs(times[i]) .add(thisTimeStep * n, 'ms') .toDate(), - y: s * probs[i] + c, + y: s * probs[i], } } } @@ -99,6 +101,9 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: { const formatter = isBinary ? formatPercent + : isLogScale + ? (x: DatumValue) => + formatLargeNumber(10 ** +x.valueOf() + contract.min - 1) : (x: DatumValue) => formatLargeNumber(+x.valueOf()) return ( @@ -111,11 +116,13 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: { yScale={ isBinary ? { min: 0, max: 100, type: 'linear' } - : { - min: contract.min + c, - max: contract.max + c, - type: contract.isLogScale ? 'log' : 'linear', + : isLogScale + ? { + min: 0, + max: Math.log10(contract.max - contract.min + 1), + type: 'linear', } + : { min: contract.min, max: contract.max, type: 'linear' } } yFormat={formatter} gridYValues={yTickValues} diff --git a/web/pages/create.tsx b/web/pages/create.tsx index 45eb120f..78ad8d19 100644 --- a/web/pages/create.tsx +++ b/web/pages/create.tsx @@ -206,7 +206,7 @@ export function NewContract(props: { min, max, initialValue, - isLogScale: (min ?? 0) < 0 ? false : isLogScale, + isLogScale, groupId: selectedGroup?.id, }) ) @@ -293,15 +293,13 @@ export function NewContract(props: { /> - {!(min !== undefined && min < 0) && ( - setIsLogScale(!isLogScale)} - disabled={isSubmitting} - /> - )} + setIsLogScale(!isLogScale)} + disabled={isSubmitting} + /> {min !== undefined && max !== undefined && min >= max && (