-
Notifications
You must be signed in to change notification settings - Fork 17
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
14 changed files
with
323 additions
and
43 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
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,36 @@ | ||
import { buildChartTheme } from '@visx/xychart'; | ||
|
||
export const monthsShort = [ | ||
'Jan', | ||
'Feb', | ||
'Mar', | ||
'Apr', | ||
'May', | ||
'Jun', | ||
'Jul', | ||
'Aug', | ||
'Sep', | ||
'Oct', | ||
'Nov', | ||
'Dec', | ||
]; | ||
|
||
export function getDayOfMonth(dateString: string) { | ||
const date = new Date(dateString); | ||
const monthName = date.toLocaleDateString('en-US', { month: 'short' }); | ||
const dayNumber = date.getDate(); | ||
|
||
return `${dayNumber} ${monthName}`; | ||
} | ||
|
||
export function getRoundedCount(count: number) { | ||
return Math.ceil(count / 1000) * 1000; | ||
} | ||
|
||
export const customTheme = buildChartTheme({ | ||
backgroundColor: '#fff', | ||
colors: ['#469BF5'], | ||
gridColor: '#469BF5', | ||
tickLength: 8, | ||
gridColorDark: '', | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DailyIntervalType } from 'types'; | ||
|
||
export interface ChartProps { | ||
data: DailyIntervalType[]; | ||
} | ||
|
||
export interface WeeklyChartProps { | ||
currentWeek: DailyIntervalType[]; | ||
prevWeek: DailyIntervalType[]; | ||
} | ||
|
||
export type DaysFilter = 7 | 30; | ||
|
||
export type WeekFilter = 'current' | 'prev'; |
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,23 @@ | ||
/* eslint-disable react/prop-types */ | ||
export function CustomTick({ formattedValue, ...tickProps }) { | ||
return ( | ||
<g transform={`translate(${tickProps.x},${tickProps.y})`}> | ||
<text | ||
fontSize={12} | ||
fontWeight={400} | ||
textAnchor="end" | ||
dominantBaseline="middle" | ||
fill="#B8B8B8" // Set tick label color | ||
> | ||
{formattedValue} | ||
</text> | ||
<line | ||
x1={-4} // Adjust the tick line length as needed | ||
x2={0} | ||
y1={0} | ||
y2={0} | ||
stroke="#333" // Set tick line color | ||
/> | ||
</g> | ||
); | ||
} |
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,78 @@ | ||
import { curveCardinal } from '@visx/curve'; | ||
import { | ||
AnimatedAxis, | ||
AnimatedGrid, | ||
AnimatedLineSeries, | ||
XYChart, | ||
Tooltip, | ||
} from '@visx/xychart'; | ||
import { customTheme, getDayOfMonth, getRoundedCount } from './Chart.helper'; | ||
import dayjs from 'dayjs'; | ||
import { ChartProps } from './Chart.type'; | ||
import { CustomTick } from './CustomTick'; | ||
|
||
export const MonthlyChart = (props: ChartProps) => { | ||
const { data } = props; | ||
console.log('data monthly', data); | ||
return ( | ||
<XYChart | ||
theme={customTheme} | ||
height={300} | ||
xScale={{ type: 'band' }} | ||
yScale={{ type: 'linear' }}> | ||
<AnimatedAxis | ||
tickComponent={(props) => <CustomTick {...props} />} | ||
orientation="bottom" | ||
hideTicks | ||
numTicks={7} | ||
tickFormat={(d) => getDayOfMonth(d)} | ||
/> | ||
<AnimatedAxis | ||
orientation="left" | ||
hideAxisLine | ||
hideTicks | ||
numTicks={3} | ||
tickFormat={(c) => getRoundedCount(c).toString()} | ||
tickComponent={(props) => <CustomTick {...props} />} | ||
/> | ||
<AnimatedGrid | ||
lineStyle={{ | ||
stroke: 'rgba(184, 184, 184, 0.30)', | ||
strokeLinecap: 'round', | ||
strokeWidth: 1, | ||
}} | ||
columns={false} | ||
numTicks={3} | ||
/> | ||
|
||
<AnimatedLineSeries | ||
curve={curveCardinal} | ||
dataKey="Last month" | ||
data={data} | ||
stroke="#469BF5" | ||
xAccessor={(d) => d.date} | ||
yAccessor={(d) => d.count} | ||
/> | ||
|
||
<Tooltip | ||
snapTooltipToDatumX | ||
snapTooltipToDatumY | ||
showVerticalCrosshair | ||
renderTooltip={({ tooltipData }: any) => ( | ||
<div className="text-xs"> | ||
<div className="mb-1">Swaps</div> | ||
|
||
<div className="mb-1"> | ||
{dayjs(tooltipData.nearestDatum.datum.date.split('T')[0]).format( | ||
'dddd, YYYY MMMM DD', | ||
)} | ||
</div> | ||
<div className="mb-1"> | ||
Count: {tooltipData.nearestDatum.datum.count} | ||
</div> | ||
</div> | ||
)} | ||
/> | ||
</XYChart> | ||
); | ||
}; |
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,93 @@ | ||
import { curveCardinal } from '@visx/curve'; | ||
import { | ||
AnimatedAxis, | ||
AnimatedGrid, | ||
AnimatedLineSeries, | ||
XYChart, | ||
Tooltip, | ||
} from '@visx/xychart'; | ||
import { customTheme, getDayOfMonth, getRoundedCount } from './Chart.helper'; | ||
import dayjs from 'dayjs'; | ||
import { CustomTick } from './CustomTick'; | ||
import { ChartProps } from './Chart.type'; | ||
|
||
export const WeeklyChart = (props: ChartProps) => { | ||
const { data } = props; | ||
const currentWeek = data.slice(24, 31).map((item) => ({ ...item })); | ||
const prevWeek = data.slice(17, 24).map((item) => ({ ...item })); | ||
|
||
// Update the date property of each item in prevWeek with the corresponding item from deepCopyCurrentWeek | ||
prevWeek.forEach((item, index) => { | ||
prevWeek[index].date = currentWeek[index].date; | ||
}); | ||
|
||
return ( | ||
<XYChart | ||
theme={customTheme} | ||
height={300} | ||
xScale={{ type: 'band' }} | ||
yScale={{ type: 'linear' }}> | ||
<AnimatedAxis | ||
tickComponent={(props) => <CustomTick {...props} />} | ||
orientation="bottom" | ||
hideTicks | ||
numTicks={7} | ||
tickFormat={(d) => getDayOfMonth(d)} | ||
/> | ||
<AnimatedAxis | ||
orientation="left" | ||
hideAxisLine | ||
hideTicks | ||
numTicks={3} | ||
tickFormat={(c) => getRoundedCount(c).toString()} | ||
tickComponent={(props) => <CustomTick {...props} />} | ||
/> | ||
<AnimatedGrid | ||
lineStyle={{ | ||
stroke: 'rgba(184, 184, 184, 0.30)', | ||
strokeLinecap: 'round', | ||
strokeWidth: 1, | ||
}} | ||
columns={false} | ||
numTicks={3} | ||
/> | ||
|
||
<AnimatedLineSeries | ||
curve={curveCardinal} | ||
dataKey="Current Week" | ||
data={currentWeek} | ||
stroke="#469BF5" | ||
xAccessor={(d) => d.date} | ||
yAccessor={(d) => d.count} | ||
/> | ||
<AnimatedLineSeries | ||
curve={curveCardinal} | ||
dataKey="Prev Week" | ||
data={prevWeek} | ||
stroke="#242D5B" | ||
xAccessor={(d) => d.date} | ||
yAccessor={(d) => d.count} | ||
/> | ||
|
||
<Tooltip | ||
snapTooltipToDatumX | ||
snapTooltipToDatumY | ||
showVerticalCrosshair | ||
renderTooltip={({ tooltipData }: any) => ( | ||
<div className="text-xs"> | ||
<div className="mb-1">Swaps</div> | ||
|
||
<div className="mb-1"> | ||
{dayjs(tooltipData.nearestDatum.datum.date.split('T')[0]).format( | ||
'dddd, YYYY MMMM DD', | ||
)} | ||
</div> | ||
<div className="mb-1"> | ||
Count: {tooltipData.nearestDatum.datum.count} | ||
</div> | ||
</div> | ||
)} | ||
/> | ||
</XYChart> | ||
); | ||
}; |
Oops, something went wrong.