From cf4bbb2df26134ae03069e5dadced7e3f9956a1d Mon Sep 17 00:00:00 2001 From: Eric Ciarla Date: Mon, 27 May 2024 16:09:50 -0400 Subject: [PATCH] init --- src/app/page.tsx | 8 +- src/components/data-input.tsx | 364 ++++++++++++++++++---------------- src/components/graph.tsx | 59 +++--- src/components/menu.tsx | 278 +++++++++++++++----------- 4 files changed, 386 insertions(+), 323 deletions(-) diff --git a/src/app/page.tsx b/src/app/page.tsx index 3e68b62..026bf41 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -61,7 +61,7 @@ export default function Home() { const [chartData, setChartData] = useState(initialData); const [xName, setXName] = useState("Date"); const [yName, setYName] = useState("Stars"); - const [padding, setPadding] = useState(32); + const [padding, setPadding] = useState(window.innerWidth < 450 ? 16 : 32); const [width, setWidth] = useState("400"); const [theme, setTheme] = useState( () => allThemes["firecrawl"] as Theme @@ -187,7 +187,11 @@ export default function Home() { openCsv={openCsv} setOpenCsv={setOpenCsv} /> -
+
Made by{" "} -

Choose data you want to visualize

-
- - - - - - - Enter GitHub URL - - Please enter the GitHub repository URL to fetch stars data. - - - setRepoUrl(e.target.value)} - /> -
- - + + + + Enter GitHub URL + + Please enter the GitHub repository URL to fetch stars data. + + + setRepoUrl(e.target.value)} + /> +
+ + -
-
-
- - - - - - - Paste CSV Data - - Please paste your CSV data or upload a CSV file.
- Make sure you have only 2 columns (X, Y) -
-
- - { - const file = e.target.files![0]; - const reader = new FileReader(); - reader.onload = (e: any) => { - setPastedCsvData(e.target.result); - }; - reader.readAsText(file); - }} - // close the dialog after file is uploaded - /> -
- - + -
-
-
-
+ const parsedData = rows.map((row: any) => { + let [keyValue, valueValue] = row.split(","); + if (containsDate) { + if (isDate(keyValue)) + keyValue = new Date(keyValue).toLocaleDateString( + "en-US", + { year: "numeric", month: "short", day: "numeric" } + ); + if (isDate(valueValue)) + valueValue = new Date(valueValue).toLocaleDateString( + "en-US", + { year: "numeric", month: "short", day: "numeric" } + ); + } + return { + [key]: keyValue, + [value]: isNaN(Number(valueValue)) + ? valueValue + : Number(valueValue), + }; + }); + // print the new formatted data + console.log(parsedData); + setChartData(parsedData); + setXName(key); + setYName(value); + setGraphTitle(`Firegraph🔥`); + // close the dialog after file is uploaded + setOpenCsv(false); + }} + > + Submit + +
+ +
+ ); -} \ No newline at end of file +} diff --git a/src/components/graph.tsx b/src/components/graph.tsx index fb3b72a..d202445 100644 --- a/src/components/graph.tsx +++ b/src/components/graph.tsx @@ -57,12 +57,16 @@ export default function Graph({ return (
@@ -104,35 +108,34 @@ export default function Graph({ {yName}
- { - if (value > 999) { - return (value / 1000).toFixed(1) + "k"; - } - return value.toString(); - }} - maxValue={maxValue} - connectNulls={true} - curveType="monotone" - /> -

- {xName} -

+ { + if (value > 999) { + return (value / 1000).toFixed(1) + "k"; + } + return value.toString(); + }} + maxValue={maxValue} + connectNulls={true} + curveType="monotone" + /> +

+ {xName} +

- - - + + ); diff --git a/src/components/menu.tsx b/src/components/menu.tsx index bb7d131..01d7611 100644 --- a/src/components/menu.tsx +++ b/src/components/menu.tsx @@ -110,140 +110,184 @@ export default function Menu({ }); }; return ( -
- -
+
+
{/*
*/} - +
-
- Theme - + setTheme(allThemes[value as keyof typeof allThemes] as Theme) + } + > + + + + + {Object.entries(allThemes).map(([themeKey, themeValue]) => ( + +
+
+
+ {themeValue.name.charAt(0).toUpperCase() + + themeValue.name.slice(1)} +
-
-
- ))} -
- -
-
- Background - setBackground(checked)} - /> -
-
- Dark Mode - setDarkMode(checked)} - /> -
+ + ))} + + +
+
+ + Background + + setBackground(checked)} + /> +
+
+ + Dark Mode + + setDarkMode(checked)} + /> +
-
- Padding - -
-
- Width - -
-
- - - + - - - - generateEmbedCode()}> -
- - Embed -
-
- {/* + Padding + + +
+
+ + Width + + +
+
+ + + + + + + generateEmbedCode()}> +
+ + Embed +
+
+ {/*
Copy PNG
*/} -
-
-
+ + +
-
{/*