diff --git a/app/components/ChartModal.js b/app/components/ChartModal.js
index 2e10f55..5316713 100644
--- a/app/components/ChartModal.js
+++ b/app/components/ChartModal.js
@@ -1,122 +1,111 @@
"use client";
-import { CartesianGrid, Line, LineChart, ResponsiveContainer, XAxis, YAxis } from 'recharts';
-import { calculateAverageIntake, calculateDayAverageLoss, sortEntries } from '../constants';
-import { Button, Stack, TextField } from '@mui/material';
-import { useState } from 'react';
+import {
+ calculateAverageIntake,
+ calculateDayAverageLoss,
+ sortEntries,
+} from "../constants";
+import { Button, Stack, TextField, Typography } from "@mui/material";
+import { useState } from "react";
+import Graph from "./Graph";
+import { getCharts } from "../charts";
export default function ChartModal({ user }) {
+ const [show, setShow] = useState(false);
+ const [daysToGraph, setDaysToGraph] = useState(30);
+ const [daysToAverage, setDaysToAverage] = useState(7);
- const [show, setShow] = useState(false);
- const [days, setDays] = useState(30);
-
- const data = [];
- var entries = [];
- var lastEntry = {};
+ const data = [];
+ var entries = [];
- if (days) {
- const lastDayEntries = user.entries.slice(0, days);
- entries = sortEntries(lastDayEntries, true);
- for (var i = 1; i < entries.length; i++) {
- const curEntry = entries[i - 1];
- const nextEntry = entries[i];
-
- const curWeekWeight = calculateDayAverageLoss(user, curEntry, 7);
- const nextWeekWeight = calculateDayAverageLoss(user, nextEntry, 7);
-
- const curWeekCalories = calculateAverageIntake(user, curEntry, 7);
- const nextWeekCalories = calculateAverageIntake(user, nextEntry, 7);
-
- const prevDataWeightVariance = data.length > 0 ? data[i - 2].weightVariance : 0;
- const prevDataCaloricVariance = data.length > 0 ? data[i - 2].caloricVariance : 0;
- const prevWeightChange = data.length > 0 ? data[i - 2].weightChange : 0;
- const prevCaloricChange = data.length > 0 ? data[i - 2].caloricChange : 0;
-
- data.push({
- date: curEntry.date,
- weightChange: ((nextWeekWeight - curWeekWeight)) + prevWeightChange,
- caloricChange: ((nextWeekCalories - curWeekCalories)) + prevCaloricChange,
- weightVariance: ((nextWeekWeight - curWeekWeight)),
- caloricVariance: ((nextWeekCalories - curWeekCalories)),
- });
- }
+ if (daysToGraph && daysToAverage) {
+ const lastDayEntries = user.entries.slice(0, daysToGraph);
+ entries = sortEntries(lastDayEntries, true);
+ for (var i = 1; i < entries.length; i++) {
+ const curEntry = entries[i - 1];
+ const nextEntry = entries[i];
- lastEntry = entries[0];
- }
-
- if (user.entries.length <= 1) {
- return;
- }
+ const curWeight = parseFloat(
+ calculateDayAverageLoss(user, curEntry, daysToAverage)
+ );
+ const nextWeight = parseFloat(
+ calculateDayAverageLoss(user, nextEntry, daysToAverage)
+ );
- return (
- <>
-
- {show &&
- <>
-