-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
2,213 additions
and
1,411 deletions.
There are no files selected for viewing
454 changes: 343 additions & 111 deletions
454
centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
centrifuge-app/src/components/Charts/SimpleBarChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { CurrencyBalance, CurrencyMetadata } from '@centrifuge/centrifuge-js' | ||
import { Shelf, Text } from '@centrifuge/fabric' | ||
import { Bar, BarChart, CartesianGrid, ReferenceLine, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' | ||
import { useTheme } from 'styled-components' | ||
import { formatDate } from '../../../src/utils/date' | ||
import { formatBalance, formatBalanceAbbreviated } from '../../../src/utils/formatting' | ||
import { LoadBoundary } from '../LoadBoundary' | ||
import { CustomTick } from './PoolPerformanceChart' | ||
import { TooltipContainer, TooltipTitle } from './Tooltip' | ||
|
||
type SimpleBarChartProps = { | ||
currency?: CurrencyMetadata | ||
data: { name: string; yAxis: number }[] | ||
} | ||
|
||
export const SimpleBarChart = ({ currency, data }: SimpleBarChartProps) => { | ||
const theme = useTheme() | ||
|
||
const getOneDayPerMonth = () => { | ||
const seenMonths = new Set<string>() | ||
const result: string[] = [] | ||
|
||
data.forEach((item) => { | ||
const date = new Date(item.name) | ||
const month = date.getMonth() + 1 | ||
const year = date.getFullYear() | ||
const monthYear = `${year}-${month}` | ||
|
||
if (!seenMonths.has(monthYear)) { | ||
seenMonths.add(monthYear) | ||
result.push(item.name) | ||
} | ||
}) | ||
|
||
return result | ||
} | ||
|
||
if (!data.length) | ||
return ( | ||
<Shelf justifyContent="center"> | ||
<Text>No data available</Text> | ||
</Shelf> | ||
) | ||
|
||
return ( | ||
<LoadBoundary> | ||
<ResponsiveContainer width="100%" height={200}> | ||
<BarChart width={500} height={300} data={data} barSize={10} barGap={10}> | ||
<CartesianGrid stroke={theme.colors.borderPrimary} vertical={false} /> | ||
<XAxis | ||
dy={4} | ||
interval={0} | ||
tickLine={false} | ||
axisLine={false} | ||
tickMargin={10} | ||
type="category" | ||
dataKey="name" | ||
ticks={getOneDayPerMonth()} | ||
tick={<CustomTick />} | ||
angle={45} | ||
/> | ||
<YAxis | ||
tickFormatter={(tick: number) => { | ||
const balance = new CurrencyBalance(tick, currency?.decimals || 0) | ||
return formatBalanceAbbreviated(balance, '', 0) | ||
}} | ||
tick={{ fontSize: 10, color: theme.colors.textPrimary }} | ||
tickLine={false} | ||
axisLine={false} | ||
dataKey="yAxis" | ||
/> | ||
<ReferenceLine y={0} stroke={theme.colors.textSecondary} /> | ||
|
||
<Tooltip | ||
cursor={false} | ||
content={({ payload }) => { | ||
if (payload && payload?.length > 0) { | ||
return ( | ||
<TooltipContainer> | ||
<TooltipTitle>{formatDate(payload[0].payload.name)}</TooltipTitle> | ||
{payload.map((item) => ( | ||
<Text variant="body3">{formatBalance(item.value as number, currency)}</Text> | ||
))} | ||
</TooltipContainer> | ||
) | ||
} | ||
}} | ||
/> | ||
<Bar | ||
dataKey="yAxis" | ||
name="yAxis" | ||
fill={theme.colors.backgroundTertiary} | ||
strokeWidth={0} | ||
fillOpacity={1} | ||
maxBarSize={20} | ||
/> | ||
</BarChart> | ||
</ResponsiveContainer> | ||
</LoadBoundary> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.