generated from zourdyzou/react-typescript-croissant
-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
211 additions
and
60 deletions.
There are no files selected for viewing
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,44 @@ | ||
import React from "react"; | ||
import { Tooltip, Typography } from "@material-ui/core"; | ||
import { makeStyles, Theme } from "@material-ui/core/styles"; | ||
import { HelpOutlineRounded } from "@material-ui/icons"; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
header: { | ||
display: "flex", | ||
alignItems: "center", | ||
"& .MuiSvgIcon-root": { | ||
cursor: "pointer", | ||
marginLeft: 6, | ||
height: 16, | ||
width: 16, | ||
}, | ||
}, | ||
customTooltip: { | ||
backgroundColor: theme.palette.background.default, | ||
borderRadius: 12, | ||
}, | ||
})); | ||
|
||
interface Props { | ||
title: string; | ||
tooltipContent: boolean | React.ReactChild | React.ReactFragment | React.ReactPortal; | ||
} | ||
|
||
export const HelpIconHeader: React.FunctionComponent<Props> = ({ title, tooltipContent }) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<Typography className={classes.header} variant="body2" color="textSecondary"> | ||
{title} | ||
<Tooltip | ||
title={tooltipContent} | ||
classes={{ | ||
tooltip: classes.customTooltip, | ||
}} | ||
> | ||
<HelpOutlineRounded /> | ||
</Tooltip> | ||
</Typography> | ||
); | ||
}; |
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
98 changes: 98 additions & 0 deletions
98
src/components/screens/molecules/history-fear-greed-chart.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,98 @@ | ||
import React from "react"; | ||
import { Box, Typography, useTheme } from "@material-ui/core"; | ||
import { makeStyles, Theme } from "@material-ui/core/styles"; | ||
import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts"; | ||
|
||
import { convertTimestamp } from "@/common/helpers/date-handler"; | ||
import { ChartSkeleton } from "@/components/screens/atoms/chart-skeleton-loader"; | ||
import { selectFearGreedIndex } from "@/features/fear-greed-index-slice"; | ||
import { useAppSelector } from "@/hooks/*"; | ||
import { FearGreedIndex } from "@/src/models"; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
responsiveContainer: { | ||
"& .recharts-surface": { | ||
cursor: "pointer", | ||
}, | ||
}, | ||
customTooltip: { | ||
borderRadius: 12, | ||
padding: 12, | ||
backgroundColor: `${theme.palette.background.default}dd`, | ||
"& .MuiTypography-root:not(:first-child)": { | ||
color: theme.palette.secondary.main, | ||
}, | ||
}, | ||
})); | ||
|
||
interface DataFormat { | ||
date: number; | ||
value: number; | ||
classification: string; | ||
} | ||
|
||
export const HistoricFearGreedIndexChart: React.FunctionComponent = () => { | ||
const classes = useStyles(); | ||
const theme = useTheme(); | ||
|
||
const fearGreedIndex = useAppSelector(selectFearGreedIndex); | ||
|
||
const formatRawData = () => { | ||
const chartData: DataFormat[] = []; | ||
fearGreedIndex.value.forEach((indexData: FearGreedIndex) => { | ||
chartData.push({ | ||
date: Number(indexData.timestamp), | ||
value: Number(indexData.value), | ||
classification: indexData.valueClassification, | ||
}); | ||
}); | ||
return chartData; | ||
}; | ||
|
||
return ( | ||
<> | ||
{fearGreedIndex.value.length === 0 ? ( | ||
<ChartSkeleton /> | ||
) : ( | ||
<ResponsiveContainer height="100%" width="100%" className={classes.responsiveContainer}> | ||
<AreaChart data={formatRawData()} margin={{ top: 8, right: 8, left: 8, bottom: 8 }}> | ||
<defs> | ||
<linearGradient id="chart-gradient" x1="0" y1="0" x2="0" y2="1"> | ||
<stop offset="5%" stopColor={theme.palette.primary.main} stopOpacity={0.3} /> | ||
<stop offset="100%" stopColor={theme.palette.primary.main} stopOpacity={0} /> | ||
</linearGradient> | ||
</defs> | ||
<XAxis dataKey="date" hide /> | ||
<YAxis domain={[(dataMin: number) => dataMin * 0.95, (dataMax: number) => dataMax * 1.05]} hide /> | ||
<Tooltip | ||
content={({ active, payload, label }) => { | ||
if (active && payload && payload.length) { | ||
return ( | ||
<Box className={classes.customTooltip}> | ||
<Typography variant="body1">{convertTimestamp(label * 1000, true)}</Typography> | ||
<Typography variant="body2"> | ||
{payload[0].payload.classification} ({payload[0].value}%) | ||
</Typography> | ||
</Box> | ||
); | ||
} else { | ||
return null; | ||
} | ||
}} | ||
/> | ||
<Area | ||
type="monotone" | ||
dataKey="value" | ||
dot={false} | ||
animationDuration={3000} | ||
strokeWidth={2} | ||
stroke={theme.palette.primary.main} | ||
fillOpacity={1} | ||
fill={`url(#chart-gradient)`} | ||
/> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
)} | ||
</> | ||
); | ||
}; |
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.