diff --git a/package-lock.json b/package-lock.json index 1868b0d..83aa915 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@remixicon/react": "^4.2.0", "@tremor/react": "^3.17.2", "axios": "^1.7.2", + "cubic-spline": "^3.0.3", "next": "14.2.3", "react": "^18", "react-dom": "^18" @@ -1486,6 +1487,11 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==" }, + "node_modules/cubic-spline": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/cubic-spline/-/cubic-spline-3.0.3.tgz", + "integrity": "sha512-yAvcHgrpf/k83pZiO4+R2reWOJlufgjpQhmDD3OXa8YMbjmRgjtUK8pcFOCZvJwqXaMD1isZdL7Z4ghqDPN/yw==" + }, "node_modules/d3-array": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/d3-array/-/d3-array-3.2.4.tgz", diff --git a/package.json b/package.json index 889d11d..a5d655d 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@remixicon/react": "^4.2.0", "@tremor/react": "^3.17.2", "axios": "^1.7.2", + "cubic-spline": "^3.0.3", "next": "14.2.3", "react": "^18", "react-dom": "^18" diff --git a/src/app/page.tsx b/src/app/page.tsx index 2da9d4a..dfa9b37 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -7,11 +7,68 @@ import Graph from "../components/graph"; import { useState } from "react"; export default function Home() { + const initialData = [ + { date: "Apr 15", Stars: 0 }, + { date: "Apr 16", Stars: 160 }, + { date: "Apr 17", Stars: 320 }, + { date: "Apr 18", Stars: 480 }, + { date: "Apr 19", Stars: 720 }, + { date: "Apr 20", Stars: 990 }, + { date: "Apr 21", Stars: 1125 }, + { date: "Apr 22", Stars: 1260 }, + { date: "Apr 23", Stars: 1530 }, + { date: "Apr 24", Stars: 1620 }, + { date: "Apr 25", Stars: 1710 }, + { date: "Apr 26", Stars: 1755 }, + { date: "Apr 27", Stars: 1800 }, + { date: "Apr 28", Stars: 2040 }, + { date: "Apr 29", Stars: 2175 }, + { date: "Apr 30", Stars: 2242 }, + { date: "May 01", Stars: 2310 }, + { date: "May 02", Stars: 2378 }, + { date: "May 03", Stars: 2445 }, + { date: "May 04", Stars: 2512 }, + { date: "May 05", Stars: 2546 }, + { date: "May 06", Stars: 2580 }, + { date: "May 07", Stars: 2648 }, + { date: "May 08", Stars: 2715 }, + { date: "May 09", Stars: 2782 }, + { date: "May 10", Stars: 2850 }, + { date: "May 11", Stars: 2917 }, + { date: "May 12", Stars: 2985 }, + { date: "May 13", Stars: 3052 }, + { date: "May 14", Stars: 3120 }, + { date: "May 15", Stars: 3187 }, + { date: "May 16", Stars: 3255 }, + { date: "May 17", Stars: 3322 }, + { date: "May 18", Stars: 3390 }, + { date: "May 19", Stars: 3510 }, + { date: "May 20", Stars: 3630 }, + { date: "May 21", Stars: 3900 }, + { date: "May 22", Stars: 4082 }, + { date: "May 23", Stars: 4263 }, + { date: "May 24", Stars: 4445 }, + { date: "May 25", Stars: 4594 }, + ]; const [padding, setPadding] = useState(64); + const [chartData, setChartData] = useState(initialData); + const [xName, setXName] = useState("Date"); + const [yName, setYName] = useState("Stars"); return (
- - + +
); } diff --git a/src/components/graph.tsx b/src/components/graph.tsx index c96ca18..801f196 100644 --- a/src/components/graph.tsx +++ b/src/components/graph.tsx @@ -2,78 +2,40 @@ import { AreaChart, Color } from "@tremor/react"; import { useState } from "react"; +import { useEffect } from "react"; -export default function Graph({ padding }: { padding: number }) { - const mockchartdata = [ - { - date: "Apr 15", - Stars: 0, - }, - { - date: "Apr 18", - Stars: 480, - }, - { - date: "Apr 19", - Stars: 720, - }, - { - date: "Apr 20", - Stars: 990, - }, - { - date: "Apr 22", - Stars: 1260, - }, - { - date: "Apr 23", - Stars: 1530, - }, - { - date: "Apr 27", - Stars: 1800, - }, - { - date: "Apr 28", - Stars: 2040, - }, - { - date: "May 01", - Stars: 2310, - }, - { - date: "May 06", - Stars: 2580, - }, - { - date: "May 16", - Stars: 2850, - }, - { - date: "May 18", - Stars: 3120, - }, - { - date: "May 19", - Stars: 3360, - }, - { - date: "May 20", - Stars: 3630, - }, - { - date: "May 21", - Stars: 3900, - }, - { - date: "May 25", - Stars: 4594, - }, - ]; +export default function Graph({ + padding, + chartData, + xName, + yName, +}: { + padding: number; + chartData: any; + xName: string; + yName: string; +}) { + const [maxValue, setMaxValue] = useState(0); + const [finalChartData, setFinalChartData] = useState(chartData); + useEffect(() => { + if ( + chartData.length > 0 && + "Stars" in chartData[0] && + "date" in chartData[0] + ) { + const maxStars = Math.max(...chartData.map((data: any) => data.Stars)); + setMaxValue(maxStars); - const [chartData, setChartData] = useState(mockchartdata); - const maxStars = Math.max(...mockchartdata.map((data) => data.Stars)); - const [maxValue, setMaxValue] = useState(maxStars); + setFinalChartData(chartData); + } else { + setMaxValue(1000); + setFinalChartData(chartData); + } + console.log(finalChartData); + console.log(maxValue); + console.log(yName); + console.log(xName); + }, [chartData]); return (
{ if (value > 99) { return (value / 1000).toFixed(1) + "k"; @@ -107,7 +72,6 @@ export default function Graph({ padding }: { padding: number }) { }} maxValue={maxValue} connectNulls={true} - curveType="natural" />
diff --git a/src/components/menu.tsx b/src/components/menu.tsx index 1289d00..8375aac 100644 --- a/src/components/menu.tsx +++ b/src/components/menu.tsx @@ -3,9 +3,15 @@ import React from "react"; export default function Menu({ padding, setPadding, + setChartData, + setXName, + setYName, }: { padding: number; setPadding: (padding: number) => void; + setChartData: (data: any) => void; + setXName: (xName: string) => void; + setYName: (yName: string) => void; }) { return (
@@ -22,8 +28,107 @@ export default function Menu({
- +