Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Create the AnomalyChart in Frontend Home Page #77

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const App: React.FC = () => {
<Routes>
<Route path="/login" element={<Login setUser={setUser} />} />
<Route path="/signup" element={<SignUp />} />
{user !== null && <>
{/* {user !== null && <> */}
<Route path="/" element={<Home isDarkMode={isDarkMode} />} />
<Route path="/profile" element={<Profile isDarkMode={isDarkMode} user={user} />} />
<Route
path="/events-dashboard"
element={<EventsDashboard isDarkMode={isDarkMode} />}
/>
</>}
{/* </>} */}
</Routes>
</Router>
);
Expand Down
65 changes: 65 additions & 0 deletions client/src/components/charts/AnomalyChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import {
ScatterChart,
Scatter,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
Legend,
ScatterProps,

Check failure on line 11 in client/src/components/charts/AnomalyChart.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

'ScatterProps' is defined but never used
} from 'recharts';

interface DataPoint {
timestamp: string;
count: number;
}

const dummyData: DataPoint[] = [
{ timestamp: '2024-10-29T09:00:00Z', count: 30 },
{ timestamp: '2024-10-29T09:10:00Z', count: 25 },
{ timestamp: '2024-10-29T09:20:00Z', count: 80 },
{ timestamp: '2024-10-29T09:30:00Z', count: 40 },
{ timestamp: '2024-10-29T09:40:00Z', count: 50 },
{ timestamp: '2024-10-29T09:50:00Z', count: 90 },
{ timestamp: '2024-10-29T10:00:00Z', count: 45 },
];

const isAnomaly = (count: number): boolean => count > 70; // Define a threshold for anomalies

const AnomalyChart: React.FC = () => {
return (
<ResponsiveContainer width="100%" height={300}>
<ScatterChart margin={{ top: 5, right: 30, left: 20, bottom: 5 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis
dataKey="timestamp"
name="Time"
tickFormatter={(time: string) => new Date(time).toLocaleTimeString()}
/>
<YAxis dataKey="count" name="Event Count" />
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
<Legend />
<Scatter
name="Event Counts"
data={dummyData}
fill="#8884d8"
shape="circle"
>
{dummyData.map((entry, index) => (
<circle
key={`dot-${index}`}
cx={entry.cx}

Check failure on line 53 in client/src/components/charts/AnomalyChart.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unsafe assignment of an error typed value
cy={entry.cy}

Check failure on line 54 in client/src/components/charts/AnomalyChart.tsx

View workflow job for this annotation

GitHub Actions / lint-and-format

Unsafe assignment of an error typed value
r={isAnomaly(entry.count) ? 8 : 4}
fill={isAnomaly(entry.count) ? '#FF0000' : '#0088FE'}
/>
))}
</Scatter>
</ScatterChart>
</ResponsiveContainer>
);
};

export default AnomalyChart;
29 changes: 25 additions & 4 deletions client/src/pages/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import React, { lazy, useState } from 'react';
import { DragDropContext, Droppable, Draggable, DropResult } from '@hello-pangea/dnd';
import {
DragDropContext,
Droppable,
Draggable,
DropResult,
} from '@hello-pangea/dnd';
import { CardState } from '../types';

const Card = lazy(() => import('../components/Card'));
const UserActivityChart = lazy(() => import('../components/charts/UserActivity'));
const UserActivityChart = lazy(
() => import('../components/charts/UserActivity')
);
const HeatMap = lazy(() => import('../components/charts/HeatMap'));
const IpAccessCombined = lazy(() => import('../components/IpAccessCombined'));
const EventTypeChart = lazy(() => import('../components/charts/EventType'));
const EventSourceChart = lazy(() => import('../components/charts/EventSource'));
const AnomalyChart = lazy(() => import('../components/charts/AnomalyChart'));

const Home: React.FC<{ isDarkMode: boolean }> = ({ isDarkMode }) => {
// State to track the current IP (null means no IP selected)
const [currentIp, setCurrentIp] = useState<string | undefined>();

const [cards, setCards] = useState<CardState[]>([
{ id: 'userActivity', title: 'User Activity', component: <UserActivityChart /> },
{
id: 'userActivity',
title: 'User Activity',
component: <UserActivityChart />,
},
{ id: 'eventTypes', title: 'Event Types', component: <EventTypeChart /> },
{ id: 'eventSources', title: 'Event Sources', component: <EventSourceChart /> },
{
id: 'eventSources',
title: 'Event Sources',
component: <EventSourceChart />,
},
{ id: 'heatMap', title: 'IP Address Heat Map', component: <HeatMap /> },
{
id: 'ipAccess',
Expand All @@ -28,6 +44,11 @@ const Home: React.FC<{ isDarkMode: boolean }> = ({ isDarkMode }) => {
/>
),
},
{
id: 'anomalyDetection',
title: 'Anomaly Detection',
component: <AnomalyChart />,
},
]);

const handleDragEnd = (result: DropResult) => {
Expand Down
Loading