diff --git a/web/components/portfolio/portfolio-value-graph.tsx b/web/components/portfolio/portfolio-value-graph.tsx
index be5c3ef0..df4d0e27 100644
--- a/web/components/portfolio/portfolio-value-graph.tsx
+++ b/web/components/portfolio/portfolio-value-graph.tsx
@@ -2,16 +2,18 @@ import { ResponsiveLine } from '@nivo/line'
import { PortfolioMetrics } from 'common/user'
import { formatMoney } from 'common/util/format'
import dayjs from 'dayjs'
+import { connectStorageEmulator } from 'firebase/storage'
import { last, set } from 'lodash'
import { memo } from 'react'
import { useWindowSize } from 'web/hooks/use-window-size'
+import { nFormatter } from 'web/lib/util/appendNumber'
import { formatTime } from 'web/lib/util/time'
import { Col } from '../layout/col'
export const PortfolioValueGraph = memo(function PortfolioValueGraph(props: {
portfolioHistory: PortfolioMetrics[]
mode: 'value' | 'profit'
- setGraphDisplayNumber: (value: number | string) => void
+ setGraphDisplayNumber: (arg0: number | string | null) => void
height?: number
includeTime?: boolean
}) {
@@ -23,11 +25,10 @@ export const PortfolioValueGraph = memo(function PortfolioValueGraph(props: {
let points = portfolioHistory.map((p) => {
const { timestamp, balance, investmentValue, totalDeposits } = p
const value = balance + investmentValue
+
const profit = value - totalDeposits
let posProfit = null
let negProfit = null
-
- // const profit = value - totalDeposits
if (profit < 0) {
negProfit = profit
} else {
@@ -66,8 +67,8 @@ export const PortfolioValueGraph = memo(function PortfolioValueGraph(props: {
]
}
const firstPoints = data[0].data
- // const numXTickValues = !width || width < 800 ? 2 : 5
- // const numYTickValues = 4
+ // const numYTickValues = !width || width < 800 ? 2 : 4
+ const numYTickValues = 2
const endDate = last(firstPoints)?.x
const firstPointsY = firstPoints
@@ -75,7 +76,6 @@ export const PortfolioValueGraph = memo(function PortfolioValueGraph(props: {
return p.y !== null
})
.map((p) => p.y)
- // console.log(firstPointsY)
const yMin =
mode === 'value'
@@ -102,72 +102,72 @@ export const PortfolioValueGraph = memo(function PortfolioValueGraph(props: {
)
return (
-
= 800 ? 200 : 100) }}
- >
-
formatTime(+time, !!includeTime),
- }}
- pointBorderColor="#fff"
- pointSize={firstPoints.length > 100 ? 0 : 6}
- axisLeft={{
- tickValues: 0,
- format: (value) => formatMoney(value),
- }}
- enableGridX={false}
- enableGridY={false}
- enableSlices="x"
- animate={false}
- yFormat={(value) => formatMoney(+value)}
- enableArea={true}
- areaOpacity={0.1}
- sliceTooltip={({ slice }) => {
- slice.points.map((point) =>
- setGraphDisplayNumber(point.data.yFormatted)
- )
- return (
-
- {slice.points.map((point) => (
-
-
-
- Time [{point.data.xFormatted}]
-
-
- {point.serieId} [{point.data.yFormatted}]
-
-
-
- ))}
-
- )
- }}
- >
+
+
= 800 ? 200 : 100) }}
+ onMouseLeave={() => setGraphDisplayNumber(null)}
+ >
+
100 ? 0 : 6}
+ axisLeft={{
+ tickValues: numYTickValues,
+ format: '.3s',
+ }}
+ enableGridX={false}
+ enableGridY={true}
+ gridYValues={numYTickValues}
+ enableSlices="x"
+ animate={false}
+ yFormat={(value) => formatMoney(+value)}
+ enableArea={true}
+ areaOpacity={0.1}
+ sliceTooltip={({ slice }) => {
+ slice.points.map((point) =>
+ setGraphDisplayNumber(point.data.yFormatted)
+ )
+ return (
+
+ {slice.points.map((point) => (
+
+
+
+ {dayjs(point.data.xFormatted).format('MMM/D/YY')}
+
+
+ {dayjs(point.data.xFormatted).format('h:mm A')}
+
+
+
+ ))}
+
+ )
+ }}
+ >
+
)
})
diff --git a/web/components/portfolio/portfolio-value-section.tsx b/web/components/portfolio/portfolio-value-section.tsx
index e6049f0f..2b26d734 100644
--- a/web/components/portfolio/portfolio-value-section.tsx
+++ b/web/components/portfolio/portfolio-value-section.tsx
@@ -16,7 +16,7 @@ export const PortfolioValueSection = memo(
const [portfolioPeriod, setPortfolioPeriod] = useState
('weekly')
const portfolioHistory = usePortfolioHistory(userId, portfolioPeriod)
- const [graphMode, setGraphMode] = useState<'profit' | 'value'>('profit')
+ const [graphMode, setGraphMode] = useState<'profit' | 'value'>('value')
const [graphDisplayNumber, setGraphDisplayNumber] = useState(null)
// Remember the last defined portfolio history.
@@ -32,16 +32,21 @@ export const PortfolioValueSection = memo(
const { balance, investmentValue, totalDeposits } = lastPortfolioMetrics
const totalValue = balance + investmentValue
const totalProfit = totalValue - totalDeposits
-
return (
<>
-
-
-
-
+
+
+ setGraphMode('value')}
+ >
+
Portfolio value
-
+
{graphMode === 'value'
? graphDisplayNumber
? graphDisplayNumber
@@ -49,11 +54,29 @@ export const PortfolioValueSection = memo(
: formatMoney(totalValue)}
-
-
Profit
+
setGraphMode('profit')}
+ >
+
Profit
0 ? 'text-green-500' : 'text-red-600',
+ graphMode === 'profit'
+ ? graphDisplayNumber
+ ? graphDisplayNumber[2] === '-'
+ ? 'text-red-600'
+ : 'text-teal-500'
+ : totalProfit > 0
+ ? 'text-teal-500'
+ : 'text-red-600'
+ : totalProfit > 0
+ ? 'text-teal-500'
+ : 'text-red-600',
'text-lg sm:text-xl'
)}
>
@@ -65,7 +88,7 @@ export const PortfolioValueSection = memo(
-
+ {/*
*/}
)}
{(user.website || user.twitterHandle || user.discordHandle) && (
-
+
{user.website && (
)}
- {/* {currentUser?.id === user.id && REFERRAL_AMOUNT > 0 && (
-
-
-
- Earn {formatMoney(REFERRAL_AMOUNT)} when you refer a friend!
- {' '}
- You've gotten{' '}
-
-
-
-
- )} */}