Skip to content
Snippets Groups Projects
Commit 68d91529 authored by ericj's avatar ericj
Browse files

add visualization component

parent 14a224fd
Branches master
No related tags found
No related merge requests found
import React from 'react';
import {
Typography
} from '@mui/material';
import "../style/style.scss"
const Visualization: React.FC<{ title: string, children: React.ReactNode}> = (
{
title,
children ,
}) => {
return (<>
<div className="graphContainer">
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>{title}</Typography>
{children}
</div>
</>);
};
export default Visualization;
...@@ -6,6 +6,7 @@ import {calculateInsights} from "../utils/userServices.ts"; ...@@ -6,6 +6,7 @@ import {calculateInsights} from "../utils/userServices.ts";
import {StarFilled} from "@ant-design/icons"; import {StarFilled} from "@ant-design/icons";
import "../style/style.scss" import "../style/style.scss"
import NoRecipes from "../components/NoRecipes.tsx"; import NoRecipes from "../components/NoRecipes.tsx";
import Visualization from "../components/Visualization.tsx";
const starColors = ["#ffad35", "#bdbdbd", "#bf876b"] const starColors = ["#ffad35", "#bdbdbd", "#bf876b"]
...@@ -17,8 +18,7 @@ const InsightsScreen: React.FC = () => { ...@@ -17,8 +18,7 @@ const InsightsScreen: React.FC = () => {
return ( return (
<Container sx={{width: "100%", display: "flex", justifyContent: "stretch", flexDirection: "column"}}> <Container sx={{width: "100%", display: "flex", justifyContent: "stretch", flexDirection: "column"}}>
<div className="graphContainer"> <Visualization title={"Your Favorite Meals"}>
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>Your Favorite Meals</Typography>
{insights.favoriteRecipes.map((recipe, i) => {insights.favoriteRecipes.map((recipe, i) =>
<Container key={i} <Container key={i}
sx={{display: "flex", flexDirection: "column", alignItems: "center", marginBottom: 3}}> sx={{display: "flex", flexDirection: "column", alignItems: "center", marginBottom: 3}}>
...@@ -32,9 +32,8 @@ const InsightsScreen: React.FC = () => { ...@@ -32,9 +32,8 @@ const InsightsScreen: React.FC = () => {
<Typography variant={"body2"}>Views: {recipe.viewCount}</Typography> <Typography variant={"body2"}>Views: {recipe.viewCount}</Typography>
</Container> </Container>
)} )}
</div> </Visualization>
<div className="graphContainer"> <Visualization title={"Ratio of Custom Recipes"}>
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>Ratio of Custom Recipes</Typography>
<PieChart <PieChart
series={[{ series={[{
arcLabel: (item) => `${(item.value * 100).toFixed(0)}%`, arcLabel: (item) => `${(item.value * 100).toFixed(0)}%`,
...@@ -47,9 +46,8 @@ const InsightsScreen: React.FC = () => { ...@@ -47,9 +46,8 @@ const InsightsScreen: React.FC = () => {
margin={{left: -100}} margin={{left: -100}}
height={200} height={200}
/> />
</div> </Visualization>
<div className="graphContainer"> <Visualization title={"Your Favorite Meal Categories"}>
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>Your Favorite Meal Categories</Typography>
<BarChart <BarChart
xAxis={[{ xAxis={[{
scaleType: 'band', scaleType: 'band',
...@@ -63,9 +61,8 @@ const InsightsScreen: React.FC = () => { ...@@ -63,9 +61,8 @@ const InsightsScreen: React.FC = () => {
}]} }]}
height={200} height={200}
/> />
</div> </Visualization>
<div className="graphContainer"> <Visualization title={"Your Favorite Ingredients"}>
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>Your Favorite Ingredients</Typography>
<BarChart <BarChart
xAxis={[{ xAxis={[{
scaleType: 'band', scaleType: 'band',
...@@ -79,9 +76,8 @@ const InsightsScreen: React.FC = () => { ...@@ -79,9 +76,8 @@ const InsightsScreen: React.FC = () => {
}]} }]}
height={200} height={200}
/> />
</div> </Visualization>
<div className="graphContainer"> <Visualization title={"Vegan / Vegetarian Meals"}>
<Typography align={"center"} sx={{margin: 2}} variant={"h5"}>Vegan / Vegetarian Meals</Typography>
<Gauge <Gauge
value={insights.veganVegetarianCount} value={insights.veganVegetarianCount}
valueMax={insights.recipeCount} valueMax={insights.recipeCount}
...@@ -97,7 +93,7 @@ const InsightsScreen: React.FC = () => { ...@@ -97,7 +93,7 @@ const InsightsScreen: React.FC = () => {
text={`${insights.veganVegetarianCount} / ${insights.recipeCount}`} text={`${insights.veganVegetarianCount} / ${insights.recipeCount}`}
height={200} height={200}
/> />
</div> </Visualization>
</Container> </Container>
); );
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment