Make graph start from left side for new markets

This commit is contained in:
James Grugett 2022-08-26 01:08:16 -05:00
parent 26a2eb2391
commit 74ce98913c
2 changed files with 26 additions and 14 deletions

View File

@ -71,10 +71,11 @@ export const AnswersGraph = memo(function AnswersGraph(props: {
const yTickValues = [0, 25, 50, 75, 100] const yTickValues = [0, 25, 50, 75, 100]
const numXTickValues = isLargeWidth ? 5 : 2 const numXTickValues = isLargeWidth ? 5 : 2
const hourAgo = latestTime.subtract(1, 'hours') const startDate = new Date(contract.createdTime)
const startDate = dayjs(contract.createdTime).isBefore(hourAgo) const endDate = dayjs(startDate).add(1, 'hour').isAfter(latestTime)
? new Date(contract.createdTime) ? latestTime.add(1, 'hours').toDate()
: hourAgo.toDate() : latestTime.toDate()
const includeMinute = dayjs(endDate).diff(startDate, 'hours') < 2
const multiYear = !dayjs(startDate).isSame(latestTime, 'year') const multiYear = !dayjs(startDate).isSame(latestTime, 'year')
const lessThanAWeek = dayjs(startDate).add(1, 'week').isAfter(latestTime) const lessThanAWeek = dayjs(startDate).add(1, 'week').isAfter(latestTime)
@ -96,14 +97,15 @@ export const AnswersGraph = memo(function AnswersGraph(props: {
xScale={{ xScale={{
type: 'time', type: 'time',
min: startDate, min: startDate,
max: latestTime.toDate(), max: endDate,
}} }}
xFormat={(d) => xFormat={(d) =>
formatTime(+d.valueOf(), multiYear, lessThanAWeek, lessThanAWeek) formatTime(+d.valueOf(), multiYear, lessThanAWeek, lessThanAWeek)
} }
axisBottom={{ axisBottom={{
tickValues: numXTickValues, tickValues: numXTickValues,
format: (time) => formatTime(+time, multiYear, lessThanAWeek, false), format: (time) =>
formatTime(+time, multiYear, lessThanAWeek, includeMinute),
}} }}
colors={[ colors={[
'#fca5a5', // red-300 '#fca5a5', // red-300
@ -163,7 +165,11 @@ function formatTime(
) { ) {
const d = dayjs(time) const d = dayjs(time)
if (d.add(1, 'minute').isAfter(Date.now())) return 'Now' if (
d.add(1, 'minute').isAfter(Date.now()) &&
d.subtract(1, 'minute').isBefore(Date.now())
)
return 'Now'
let format: string let format: string
if (d.isSame(Date.now(), 'day')) { if (d.isSame(Date.now(), 'day')) {

View File

@ -58,10 +58,11 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
const { width } = useWindowSize() const { width } = useWindowSize()
const numXTickValues = !width || width < 800 ? 2 : 5 const numXTickValues = !width || width < 800 ? 2 : 5
const hoursAgo = latestTime.subtract(1, 'hours') const startDate = times[0]
const startDate = dayjs(times[0]).isBefore(hoursAgo) const endDate = dayjs(startDate).add(1, 'hour').isAfter(latestTime)
? times[0] ? latestTime.add(1, 'hours').toDate()
: hoursAgo.toDate() : latestTime.toDate()
const includeMinute = dayjs(endDate).diff(startDate, 'hours') < 2
// Minimum number of points for the graph to have. For smooth tooltip movement // Minimum number of points for the graph to have. For smooth tooltip movement
// On first load, width is undefined, skip adding extra points to let page load faster // On first load, width is undefined, skip adding extra points to let page load faster
@ -133,14 +134,15 @@ export const ContractProbGraph = memo(function ContractProbGraph(props: {
xScale={{ xScale={{
type: 'time', type: 'time',
min: startDate, min: startDate,
max: latestTime.toDate(), max: endDate,
}} }}
xFormat={(d) => xFormat={(d) =>
formatTime(+d.valueOf(), multiYear, lessThanAWeek, lessThanAWeek) formatTime(+d.valueOf(), multiYear, lessThanAWeek, lessThanAWeek)
} }
axisBottom={{ axisBottom={{
tickValues: numXTickValues, tickValues: numXTickValues,
format: (time) => formatTime(+time, multiYear, lessThanAWeek, false), format: (time) =>
formatTime(+time, multiYear, lessThanAWeek, includeMinute),
}} }}
colors={{ datum: 'color' }} colors={{ datum: 'color' }}
curve="stepAfter" curve="stepAfter"
@ -183,7 +185,11 @@ function formatTime(
) { ) {
const d = dayjs(time) const d = dayjs(time)
if (d.add(1, 'minute').isAfter(Date.now())) return 'Now' if (
d.add(1, 'minute').isAfter(Date.now()) &&
d.subtract(1, 'minute').isBefore(Date.now())
)
return 'Now'
let format: string let format: string
if (d.isSame(Date.now(), 'day')) { if (d.isSame(Date.now(), 'day')) {