-
-
Notifications
You must be signed in to change notification settings - Fork 736
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: LineChart component (#6072)
Initial version of a reusable trend chart, with a tooltip and vertical highlight
- Loading branch information
Showing
6 changed files
with
101 additions
and
59 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
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
frontend/src/component/executiveDashboard/LineChart/LineChart.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,3 @@ | ||
import { lazy } from 'react'; | ||
|
||
export const LineChart = lazy(() => import('./LineChartComponent')); |
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
43 changes: 41 additions & 2 deletions
43
frontend/src/component/executiveDashboard/UsersChart/UsersChart.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 |
---|---|---|
@@ -1,3 +1,42 @@ | ||
import { lazy } from 'react'; | ||
import { useMemo, type VFC } from 'react'; | ||
import 'chartjs-adapter-date-fns'; | ||
import { useTheme } from '@mui/material'; | ||
import { ExecutiveSummarySchema } from 'openapi'; | ||
import { LineChart } from '../LineChart/LineChart'; | ||
|
||
export const UsersChart = lazy(() => import('./UsersChartComponent')); | ||
interface IUsersChartProps { | ||
userTrends: ExecutiveSummarySchema['userTrends']; | ||
} | ||
|
||
export const UsersChart: VFC<IUsersChartProps> = ({ userTrends }) => { | ||
const theme = useTheme(); | ||
const data = useMemo( | ||
() => ({ | ||
labels: userTrends.map((item) => item.date), | ||
datasets: [ | ||
{ | ||
label: 'Total users', | ||
data: userTrends.map((item) => item.total), | ||
borderColor: theme.palette.primary.light, | ||
backgroundColor: theme.palette.primary.light, | ||
fill: true, | ||
}, | ||
{ | ||
label: 'Active users', | ||
data: userTrends.map((item) => item.active), | ||
borderColor: theme.palette.success.border, | ||
backgroundColor: theme.palette.success.border, | ||
}, | ||
{ | ||
label: 'Inactive users', | ||
data: userTrends.map((item) => item.inactive), | ||
borderColor: theme.palette.warning.border, | ||
backgroundColor: theme.palette.warning.border, | ||
}, | ||
], | ||
}), | ||
[theme, userTrends], | ||
); | ||
|
||
return <LineChart data={data} />; | ||
}; |
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