-
Notifications
You must be signed in to change notification settings - Fork 29
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
1 parent
dff62c0
commit 1b61ce5
Showing
22 changed files
with
849 additions
and
178 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
apps/dapp/src/components/Pages/Core/DappPages/SpiceBazaar/Analytics/Chart/BarChart.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,142 @@ | ||
import type { DataKey, AxisDomain } from 'recharts/types/util/types'; | ||
import { | ||
BarChart, | ||
Bar, | ||
XAxis, | ||
YAxis, | ||
Tooltip, | ||
ResponsiveContainer, | ||
} from 'recharts'; | ||
import { useTheme } from 'styled-components'; | ||
import { formatNumberAbbreviated } from 'utils/formatter'; | ||
import { useMediaQuery } from 'react-responsive'; | ||
import { queryPhone } from 'styles/breakpoints'; | ||
|
||
type BarChartProps<T> = { | ||
chartData: T[]; | ||
xDataKey: DataKey<keyof T>; | ||
xTickFormatter: (xValue: any, index: number) => string; | ||
yTickFormatter?: (yValue: any, index: number) => string; | ||
tooltipLabelFormatter: (value: any) => string; | ||
tooltipValuesFormatter?: (value: number, name: string) => string[]; | ||
yDomain?: AxisDomain; | ||
series: { key: string; color: string }[]; | ||
}; | ||
|
||
export default function CustomBarChart<T>( | ||
props: React.PropsWithChildren<BarChartProps<T>> | ||
) { | ||
const { | ||
chartData, | ||
xDataKey, | ||
xTickFormatter, | ||
yTickFormatter, | ||
tooltipLabelFormatter, | ||
tooltipValuesFormatter, | ||
yDomain, | ||
series, | ||
} = props; | ||
|
||
const theme = useTheme(); | ||
const isPhoneOrAbove = useMediaQuery({ | ||
query: queryPhone, | ||
}); | ||
|
||
return ( | ||
<ResponsiveContainer minHeight={200} minWidth={320} height={250}> | ||
<BarChart | ||
data={chartData} | ||
margin={{ top: 20, right: 30, left: 20, bottom: 10 }} | ||
barCategoryGap={20} | ||
> | ||
<XAxis | ||
axisLine={false} | ||
tickLine={false} | ||
dataKey={xDataKey} | ||
tickFormatter={xTickFormatter} | ||
tick={{ stroke: theme.palette.brandLight }} | ||
minTickGap={10} | ||
tickMargin={10} | ||
style={{ | ||
fontFamily: 'Caviar Dreams', | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
lineHeight: '18px', | ||
letterSpacing: '0.05em', | ||
fill: theme.palette.brandLight, | ||
}} | ||
/> | ||
<YAxis | ||
axisLine={false} | ||
tickLine={false} | ||
tickFormatter={ | ||
yTickFormatter | ||
? (val, i) => yTickFormatter(val, i) | ||
: (value) => formatNumberAbbreviated(value).string | ||
} | ||
tick={{ stroke: theme.palette.brandLight }} | ||
domain={yDomain} | ||
tickMargin={16} | ||
style={{ | ||
fontSize: '12px', | ||
fontWeight: '400', | ||
lineHeight: '18px', | ||
letterSpacing: '0.05em', | ||
fill: theme.palette.brandLight, | ||
fontFamily: 'Caviar Dreams', | ||
}} | ||
ticks={[0.0, 2.0, 4.0, 6.0]} | ||
/> | ||
<Tooltip | ||
wrapperStyle={{ outline: 'none' }} | ||
separator={isPhoneOrAbove ? ': ' : ':\n '} | ||
contentStyle={{ | ||
backgroundColor: theme.palette.dark75, | ||
color: theme.palette.brand, | ||
borderRadius: '15px', | ||
border: 0, | ||
minWidth: '180px', | ||
}} | ||
itemStyle={{ | ||
backgroundColor: theme.palette.dark75, | ||
color: theme.palette.brandLight, | ||
whiteSpace: 'pre', | ||
}} | ||
labelStyle={{ | ||
backgroundColor: theme.palette.dark75, | ||
fontWeight: 'bold', | ||
}} | ||
labelFormatter={tooltipLabelFormatter} | ||
formatter={ | ||
tooltipValuesFormatter | ||
? (value, name, _props) => { | ||
//@ts-ignore | ||
return tooltipValuesFormatter(value, name); | ||
} | ||
: undefined | ||
} | ||
/> | ||
{series.map((serie, index) => { | ||
const isTopBar = index === series.length - 1; | ||
const isBottomBar = index === 0; | ||
|
||
return ( | ||
<Bar | ||
key={serie.key} | ||
dataKey={serie.key} | ||
stackId="a" | ||
fill={serie.color} | ||
radius={ | ||
isTopBar | ||
? [5, 5, 0, 0] | ||
: isBottomBar | ||
? [0, 0, 5, 5] | ||
: [0, 0, 0, 0] | ||
} | ||
/> | ||
); | ||
})} | ||
</BarChart> | ||
</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
41 changes: 41 additions & 0 deletions
41
...rc/components/Pages/Core/DappPages/SpiceBazaar/Analytics/Chart/CirculatingSupplyChart.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,41 @@ | ||
import { subDays } from 'date-fns'; | ||
import LineChart from './LineChart'; | ||
import { useTheme } from 'styled-components'; | ||
import { tickFormatter } from './Chart'; | ||
import type { Metric } from './Chart'; | ||
import Loader from 'components/Loader/Loader'; | ||
|
||
const pricesLast7Days: Metric[] = [ | ||
{ timestamp: subDays(new Date(), 6).getTime(), price: 1394823 }, | ||
{ timestamp: subDays(new Date(), 5).getTime(), price: 1494823 }, | ||
{ timestamp: subDays(new Date(), 4).getTime(), price: 1294823 }, | ||
{ timestamp: subDays(new Date(), 3).getTime(), price: 1554823 }, | ||
{ timestamp: subDays(new Date(), 2).getTime(), price: 1394823 }, | ||
{ timestamp: subDays(new Date(), 1).getTime(), price: 1494823 }, | ||
{ timestamp: new Date().getTime(), price: 1394823 }, | ||
]; | ||
|
||
const CirculatingSupplyChart = () => { | ||
const metrics = pricesLast7Days; | ||
const theme = useTheme(); | ||
|
||
const formatWithCommas = (num: number) => { | ||
return new Intl.NumberFormat('en-US').format(num); | ||
}; | ||
|
||
if (!metrics.length) return <Loader />; | ||
return ( | ||
<LineChart | ||
chartData={metrics.reverse()} | ||
xDataKey="timestamp" | ||
lines={[{ series: 'price', color: theme.palette.brandLight }]} | ||
xTickFormatter={tickFormatter} | ||
yTickFormatter={(val) => formatWithCommas(val)} | ||
tooltipLabelFormatter={tickFormatter} | ||
yDomain={[1290000, 1390000, 1490000, 1590000]} | ||
tooltipValuesFormatter={(value) => [value.toFixed(2)]} | ||
/> | ||
); | ||
}; | ||
|
||
export default CirculatingSupplyChart; |
41 changes: 41 additions & 0 deletions
41
...c/components/Pages/Core/DappPages/SpiceBazaar/Analytics/Chart/EmissionAllocationEpoch.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,41 @@ | ||
import { subDays } from 'date-fns'; | ||
import LineChart from './LineChart'; | ||
import { formatNumberAbbreviated } from 'utils/formatter'; | ||
import { useTheme } from 'styled-components'; | ||
import { tickFormatter } from './Chart'; | ||
import type { Metric } from './Chart'; | ||
import Loader from 'components/Loader/Loader'; | ||
|
||
const pricesLast7Days: Metric[] = [ | ||
{ timestamp: subDays(new Date(), 6).getTime(), price: 22 }, | ||
{ timestamp: subDays(new Date(), 5).getTime(), price: 15 }, | ||
{ timestamp: subDays(new Date(), 4).getTime(), price: 25 }, | ||
{ timestamp: subDays(new Date(), 3).getTime(), price: 35 }, | ||
{ timestamp: subDays(new Date(), 2).getTime(), price: 50 }, | ||
{ timestamp: subDays(new Date(), 1).getTime(), price: 65 }, | ||
{ timestamp: new Date().getTime(), price: 75 }, | ||
]; | ||
|
||
const EmissionAllocationEpochChart = () => { | ||
const metrics = pricesLast7Days; | ||
const theme = useTheme(); | ||
|
||
const formatWithPercent = (val: number) => | ||
`${formatNumberAbbreviated(val).number}\u00A0%`; | ||
|
||
if (!metrics.length) return <Loader />; | ||
return ( | ||
<LineChart | ||
chartData={metrics.reverse()} | ||
xDataKey="timestamp" | ||
lines={[{ series: 'price', color: theme.palette.brandLight }]} | ||
xTickFormatter={tickFormatter} | ||
yTickFormatter={formatWithPercent} | ||
tooltipLabelFormatter={tickFormatter} | ||
yDomain={[0, 25, 50, 75]} | ||
tooltipValuesFormatter={(value) => [formatWithPercent(value)]} | ||
/> | ||
); | ||
}; | ||
|
||
export default EmissionAllocationEpochChart; |
41 changes: 41 additions & 0 deletions
41
.../components/Pages/Core/DappPages/SpiceBazaar/Analytics/Chart/EmissionAllocationStaked.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,41 @@ | ||
import { subDays } from 'date-fns'; | ||
import LineChart from './LineChart'; | ||
import { useTheme } from 'styled-components'; | ||
import { tickFormatter } from './Chart'; | ||
import type { Metric } from './Chart'; | ||
import Loader from 'components/Loader/Loader'; | ||
|
||
const pricesLast7Days: Metric[] = [ | ||
{ timestamp: subDays(new Date(), 6).getTime(), price: 1394823 }, | ||
{ timestamp: subDays(new Date(), 5).getTime(), price: 1494823 }, | ||
{ timestamp: subDays(new Date(), 4).getTime(), price: 1294823 }, | ||
{ timestamp: subDays(new Date(), 3).getTime(), price: 1554823 }, | ||
{ timestamp: subDays(new Date(), 2).getTime(), price: 1394823 }, | ||
{ timestamp: subDays(new Date(), 1).getTime(), price: 1494823 }, | ||
{ timestamp: new Date().getTime(), price: 1394823 }, | ||
]; | ||
|
||
const EmissionAllocationStaked = () => { | ||
const metrics = pricesLast7Days; | ||
const theme = useTheme(); | ||
|
||
const formatWithCommas = (num: number) => { | ||
return new Intl.NumberFormat('en-US').format(num); | ||
}; | ||
|
||
if (!metrics.length) return <Loader />; | ||
return ( | ||
<LineChart | ||
chartData={metrics.reverse()} | ||
xDataKey="timestamp" | ||
lines={[{ series: 'price', color: theme.palette.brandLight }]} | ||
xTickFormatter={tickFormatter} | ||
yTickFormatter={(val) => formatWithCommas(val)} | ||
tooltipLabelFormatter={tickFormatter} | ||
yDomain={[1290000, 1390000, 1490000, 1590000]} | ||
tooltipValuesFormatter={(value) => [value.toFixed(2)]} | ||
/> | ||
); | ||
}; | ||
|
||
export default EmissionAllocationStaked; |
Oops, something went wrong.