Skip to content

Commit

Permalink
Merge branch 'main' of github.com:andy89923/DVVA_Final-Project into main
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Jan 11, 2023
2 parents b308fdf + 26b7c20 commit e320a65
Show file tree
Hide file tree
Showing 13 changed files with 335 additions and 95 deletions.
1 change: 1 addition & 0 deletions movis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-chartjs-2": "^5.1.0",
"react-dom": "18.2.0",
"react-force-graph": "^1.41.18",
"react-force-graph-2d": "^1.23.15",
"react-icons": "^4.7.1",
"superjson": "1.9.1",
"three": "^0.148.0",
Expand Down
13 changes: 13 additions & 0 deletions movis/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions movis/src/pages/ctfangland/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import {
BarElement,
Title,
Tooltip,
Legend
Legend,
} from "chart.js";

import { Bar } from "react-chartjs-2";
import { ChartOptions, ElementCount } from "../../utils/chartUtils";
import { ChartOptions, getTopElementCount } from "../../utils/chartUtils";

ChartJS.register(
CategoryScale,
Expand All @@ -34,22 +34,24 @@ ChartJS.register(

const MyBarPlot: React.FC<{ data: MovieData[] }> = (props) => {
// get genre counts
const { labels, data: countArr } = ElementCount(
const { labels, data: countArr } = getTopElementCount(
props.data,
["genres"],
["name"],
[],
"name",
10
);

const data = {
labels: labels,
datasets: [{
datasets: [
{
label: "2001 Movies",
data: countArr,
backgroundColor: "rgba(255, 99, 132, 0.6)",
borderColor: "rgba(255, 99, 132, 0.8)",
borderWidth: 1,
}
},
],
};

Expand All @@ -59,36 +61,30 @@ const MyBarPlot: React.FC<{ data: MovieData[] }> = (props) => {
const CTFHome: NextPage = () => {
const { data: movies } = api.movie.betweenYearRange.useQuery({
minYear: 2001,
maxYear: 2001
maxYear: 2001,
});

return (
<>
<Navbar />
<main className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">

<div className="container flex flex-col items-center justify-center gap-12 px-4 py-16 ">
<div className="text-left font-extrabold tracking-tight text-white">

<span className="text-[hsl(295,32%,69%)]">CTFang</span>
<span className="text-[hsl(295,32%,69%)]">CTFang</span>
</div>
</div>

{movies != null ? (
<div className="grid grid-cols-1 gap-4 sm:grid-cols-3 md:gap-8">

<div className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-lg text-white hover:bg-white/20">
<h3 className="text-2xl font-bold">Fixed</h3>


</div>

<ZoomCard title="Movies Genres Compare">
<div className="flex flex-col gap-4 rounded-xl bg-white/95 p-4 text-lg text-black hover:bg-white/100">
<MyBarPlot data={movies} />
</div>
</ZoomCard>

</div>
) : (
<h1 className="text-2xl font-bold text-white">Querying Data...</h1>
Expand Down
81 changes: 81 additions & 0 deletions movis/src/pages/f315/geo-map.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useEffect, useRef, useState } from "react";
import { Chart } from "react-chartjs-2";
import * as ChartGeo from "chartjs-chart-geo";
import {
Chart as ChartJS,
CategoryScale,
Tooltip,
Title,
Legend,
} from "chart.js";

ChartJS.register(
Title,
Tooltip,
Legend,
CategoryScale,
ChartGeo.ChoroplethController,
ChartGeo.ProjectionScale,
ChartGeo.ColorScale,
ChartGeo.GeoFeature
);

export default function Map() {
const chartRef = useRef();
const [countries, setCountries] = useState<any>([]);

useEffect(() => {
fetch("https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json")
.then((response) => response.json())
.then((data) => {
setCountries(
ChartGeo.topojson.feature(data, data.objects.countries).features
);
});
}, []);

return (
<Chart
ref={chartRef}
type="choropleth"
data={{
labels: countries.map((d: any) => d.properties.name),
datasets: [
{
outline: countries,
label: "Countries",
data: countries.map((d: any) => ({
feature: d,
value: Math.random() * 10,
})),
// color from https://mdigi.tools/color-shades/#9417e2
backgroundColor: [
"#f5e8fd",
"#e0baf8",
"#cb8bf3",
"#b75def",
"#a22fea",
"#8815d0",
],
},
],
}}
options={{
showOutline: true,
showGraticule: false,
plugins: {
legend: {
display: false,
},
},
scales: {
projection: {
axis: "x",
projection: "equalEarth",
},
// Hide color scale
},
}}
/>
);
}
54 changes: 5 additions & 49 deletions movis/src/pages/f315/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type NextPage } from "next";
import Head from "next/head";
import Link from "next/link";
import Navbar from "../../components/Navbar";
import ZoomCard from "../../components/ZoomCard";

import { api } from "../../utils/api";
import Map from "./geo-map";
import ZoomCard from "../../components/ZoomCard";

const Home: NextPage = () => {
const hello = api.example.hello.useQuery({ text: "from tRPC" });
Expand Down Expand Up @@ -33,54 +32,11 @@ const Home: NextPage = () => {
</span>
</h2>
</div>

<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:gap-8">
<ZoomCard title="Link 1">
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
href="https://create.t3.gg/en/usage/first-steps"
target="_blank"
>
<h3 className="text-2xl font-bold">First Steps →</h3>
<div className="text-lg">
Just the basics - Everything you need to know to set up your
database and authentication.
</div>
</Link>
</ZoomCard>
<ZoomCard title="Link 2">
<Link
className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-white hover:bg-white/20"
href="https://create.t3.gg/en/introduction"
target="_blank"
>
<h3 className="text-2xl font-bold">Documentation →</h3>
<div className="text-lg">
Learn more about Create T3 App, the libraries it uses, and how
to deploy it.
</div>
</Link>
</ZoomCard>
</div>
<p className="text-2xl text-white">
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
</p>
</div>
<div className="grid grid-cols-1 gap-4 sm:grid-cols-3 md:gap-8">
<div className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-lg text-white hover:bg-white/20">
<h3 className="text-2xl font-bold">Some</h3>
</div>
<div className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-lg text-white hover:bg-white/20">
<h3 className="text-2xl font-bold">Arbitary</h3>
<ZoomCard title="Production count by Country">
<div className="flex flex-col gap-4 rounded-xl bg-white/90 p-4 text-lg text-black hover:bg-white/100">
<Map />
</div>
<div className="flex max-w-xs flex-col gap-4 rounded-xl bg-white/10 p-4 text-lg text-white hover:bg-white/20">
<h3 className="text-2xl font-bold">Blocks</h3>
</div>
</div>
<ZoomCard title="Some Title">
<p className="text-2xl text-white">
{hello.data ? hello.data.greeting : "Loading tRPC query..."}
</p>
</ZoomCard>
</main>
</>
Expand Down
11 changes: 5 additions & 6 deletions movis/src/pages/playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ZoomCard from "../../components/ZoomCard";

import { api } from "../../utils/api";
import type { KeyMap, MovieData, Subset } from "../../utils/myClasses";
import { AllGenres } from "../../utils/myClasses";

import {
Chart as ChartJS,
Expand All @@ -21,7 +20,7 @@ import {
} from "chart.js";

import { Bar } from "react-chartjs-2";
import { ChartOptions, ElementCount } from "../../utils/chartUtils";
import { ChartOptions, getTopElementCount } from "../../utils/chartUtils";
import MyListbox from "../../components/MyListbox";

ChartJS.register(
Expand All @@ -41,18 +40,18 @@ const keyMap = {
keywords: "The amount of movies with the specific keyword",
spoken_languages: "The amount of movies spoken a specific language",
countries: "The amount of movies produced in a specific country",
} as KeyMap;
} as KeyMap<string>;

const MyBarPlot: React.FC<{ data: MovieData[] }> = (props) => {
const [filterkey, setFilterkey] = useState("genres");

// get genre counts
const showCount = 20;
const { labels, data: countArr } = ElementCount(
const { labels, data: countArr } = getTopElementCount(
props.data,
[filterkey], //["genres"]
["name"],
true,
[],
"name",
showCount
);

Expand Down
48 changes: 48 additions & 0 deletions movis/src/pages/relation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { type NextPage } from "next";
import Head from "next/head";
import Link from "next/link";
import { ForceGraph2D, ForceGraph3D } from "react-force-graph";
import Navbar from "../../components/Navbar";
import ZoomCard from "../../components/ZoomCard";
// import SpriteText from "three-spritetext";

import { api } from "../../utils/api";
import { getKeywordGraph } from "../../utils/relationUtils";

const Overview: NextPage = () => {
// const hello = api.example.hello.useQuery({ text: "from tRPC" });
// const { data: graph } = api.graph.linkRatingBetween.useQuery({
// minRating: 10,
// maxRating: 10,
// });
const { data: movies } = api.movie.betweenYearRange.useQuery({
minYear: 2018,
maxYear: 2020,
});

const graph = movies != null ? getKeywordGraph(movies, 0, 50) : null;

console.log(graph);

return (
<>
<Head>
<title>MoVis</title>
<meta
name="description"
content="A Comprehensive Visualization System for The Movies Dataset"
/>
<link rel="icon" href="/favicon.ico" />
</Head>
<Navbar />
<main className="flex min-h-screen flex-col items-center bg-gradient-to-b from-[#2e026d] to-[#15162c]">
<div className="container flex flex-col py-6">
{graph != null && <ForceGraph3D graphData={graph} />}
{/* <ForceGraph2D graphData={graph} /> */}
</div>
</main>
</>
);
};

export default Overview;
2 changes: 2 additions & 0 deletions movis/src/server/api/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createTRPCRouter } from "./trpc";
import { exampleRouter } from "./routers/example";
import { movieRouter } from "./routers/movies";
import { getAllRouter } from "./routers/getAll";
import { graphRouter } from "./routers/graph";

/**
* This is the primary router for your server.
Expand All @@ -12,6 +13,7 @@ export const appRouter = createTRPCRouter({
example: exampleRouter,
movie: movieRouter,
getAll: getAllRouter,
graph: graphRouter,
});

// export type definition of API
Expand Down
Loading

0 comments on commit e320a65

Please sign in to comment.