Skip to content

Commit a264a48

Browse files
committed
add styling
1 parent 9f404b6 commit a264a48

9 files changed

Lines changed: 76 additions & 155 deletions

File tree

src/App.css

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/App.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import "./App.css";
2-
import Graph from "./Graph.tsx";
3-
import { ChakraProvider } from '@chakra-ui/react'
1+
import Graph from "./components/Graph.tsx";
2+
import Layout from "./components/Layout.tsx";
43

54
function App() {
65
return (
7-
<ChakraProvider>
8-
<h1>RDF Graph Visualization</h1>
6+
<Layout>
97
<Graph />
10-
</ChakraProvider>
8+
</Layout>
119
);
1210
}
1311

src/Graph.tsx renamed to src/components/Graph.tsx

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useState, useEffect } from "react";
22
import ForceGraph3D from "react-force-graph-3d";
3-
import * as THREE from 'three';
4-
import { GraphData, Node } from "./graph";
5-
import { createGraph, rdfGraphToNodes } from "./utils.ts";
3+
import * as THREE from "three";
4+
import { GraphData, Node } from "./Graph.tsx";
5+
import { createGraph, rdfGraphToNodes } from "../utils.ts";
66

77
const Graph: React.FC = () => {
88
const [graphData, setGraphData] = useState<GraphData>({ nodes: [], links: [] });
@@ -17,29 +17,18 @@ const Graph: React.FC = () => {
1717
};
1818

1919
const getGroupColor = (group: string) => {
20-
// const colors: { [key: string]: number } = {
21-
// person: 0,
22-
// dataset: 1,
23-
// organization: 2,
24-
// software: 3,
25-
// document: 4,
26-
// article: 5,
27-
// creativeWork: 6,
28-
// service: 7,
29-
// "": 8, // Default group
30-
// };
3120
const colors: { [key: string]: string } = {
32-
person: 'red',
33-
dataset: 'blue',
34-
organization: 'green',
35-
software: 'yellow',
36-
document: 'orange',
37-
article: 'indigo',
38-
creativeWork: 'violet',
39-
service: 'cyan',
40-
"": 'gray', // Default group
21+
person: "red",
22+
dataset: "blue",
23+
organization: "green",
24+
software: "yellow",
25+
document: "orange",
26+
article: "indigo",
27+
creativeWork: "violet",
28+
service: "cyan",
29+
"": "gray", // Default group
4130
};
42-
return colors[group] || 'gray'; // Default to 3 if group not found
31+
return colors[group] || "gray"; // Default to 3 if group not found
4332
};
4433

4534
useEffect(() => {
@@ -70,7 +59,7 @@ const Graph: React.FC = () => {
7059
const geometry =
7160
group === ""
7261
? new THREE.BoxGeometry(8, 8, 8) // Box for nodes with empty group
73-
: new THREE.SphereGeometry(5); // Sphere for other nodes
62+
: new THREE.SphereGeometry(5); // Sphere for other nodes
7463

7564
const material = new THREE.MeshStandardMaterial({
7665
color: getGroupColor(group),

src/components/Layout.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Box, Flex, useBreakpointValue } from "@chakra-ui/react";
2+
import { ReactNode } from "react";
3+
import Navbar from "./Navbar";
4+
5+
interface LayoutProps {
6+
children: ReactNode;
7+
}
8+
9+
export default function Layout({ children }: LayoutProps) {
10+
const contentWidth = useBreakpointValue({
11+
base: "95%", // for screens smaller than 720px
12+
md: "85%", // for screens between 720px and 1080px
13+
xl: "75%", // for screens larger than 1080px
14+
});
15+
16+
return (
17+
<Flex minHeight="100vh" display="flex" flexDirection="column" width="100vw">
18+
<Navbar />
19+
<Box flex="1" width={contentWidth} mx="auto" justifyContent="center">
20+
{/* Ensure the child component takes the full available space */}
21+
<Box height="100%" width="100%" display="flex" justifyContent="center" alignItems="center">
22+
{children}
23+
</Box>
24+
</Box>
25+
{/*<Footer />*/}
26+
</Flex>
27+
);
28+
}

src/components/Navbar.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Box, Flex, Text } from "@chakra-ui/react";
2+
3+
const Navbar = () => {
4+
return (
5+
<Box bg={"green.100"} px={4} mb={5}>
6+
<Flex h={16} alignItems={"center"} justifyContent={"center"}>
7+
<Text fontSize="xl" fontWeight="bold" color="green.800">
8+
RDF Graph Visualization
9+
</Text>
10+
</Flex>
11+
</Box>
12+
);
13+
};
14+
export default Navbar;

src/graph.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ interface Node {
33
id: string;
44
label?: string;
55
group?: string;
6-
// type?: string;
76
}
87

98
interface Link {

src/index.css

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { StrictMode } from 'react'
2-
import { createRoot } from 'react-dom/client'
3-
import App from './App.tsx'
4-
import './index.css'
1+
import { StrictMode } from "react";
2+
import { createRoot } from "react-dom/client";
3+
import App from "./App.tsx";
4+
import { ChakraProvider } from "@chakra-ui/react";
55

6-
createRoot(document.getElementById('root')!).render(
6+
createRoot(document.getElementById("root")!).render(
77
<StrictMode>
8-
<App />
9-
</StrictMode>,
10-
)
8+
<ChakraProvider>
9+
<App />
10+
</ChakraProvider>
11+
</StrictMode>
12+
);

src/utils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as rdflib from "rdflib";
2-
import { Node, Link, GraphData } from "./graph";
2+
import { Node, Link, GraphData } from "./components/Graph.tsx";
33

44
const createGraph = (rdfData: string, baseUrl: string): rdflib.Store => {
55
const store = rdflib.graph();
@@ -15,7 +15,7 @@ const createGraph = (rdfData: string, baseUrl: string): rdflib.Store => {
1515
return store;
1616
};
1717

18-
const rdfGraphToNodes = (store: rdflib.Store): GraphData => {
18+
const rdfGraphToNodes = (store: rdflib.Store, removeUnconnectedNodes: boolean): GraphData => {
1919
const nodesMap = new Map<string, Node>();
2020
const edges: Link[] = [];
2121

@@ -76,8 +76,8 @@ const rdfGraphToNodes = (store: rdflib.Store): GraphData => {
7676
if (pred.includes("affiliation")) {
7777
safeUpdateElement(obj, undefined, "organization");
7878
}
79-
if (pred.includes('author') || pred.includes('creator')){
80-
safeUpdateElement(obj,undefined, 'person')
79+
if (pred.includes("author") || pred.includes("creator")) {
80+
safeUpdateElement(obj, undefined, "person");
8181
}
8282
if (!nodesMap.has(subj)) {
8383
nodesMap.set(subj, { id: subj, label: subj, group: "" });
@@ -92,7 +92,8 @@ const rdfGraphToNodes = (store: rdflib.Store): GraphData => {
9292
// return graphData;
9393
const connectedNodes = removeNonConnectedNodes(graphData);
9494
console.log("only connected nodes", connectedNodes);
95-
return { nodes: connectedNodes, links: edges };
95+
if (removeUnconnectedNodes) return { nodes: connectedNodes, links: edges };
96+
else return graphData;
9697
};
9798

9899
const removeNonConnectedNodes = (graphData: GraphData): Node[] => {

0 commit comments

Comments
 (0)