-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hacking away for visualizer: now showing docs in a very ugly way
- Loading branch information
1 parent
c655792
commit 7bb4b7c
Showing
14 changed files
with
381 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
import "./App.css"; | ||
import {BrowserRouter, HashRouter, Link, Route, Routes} from "react-router-dom"; | ||
import {GraphViewer} from "./graph/GraphViewer"; | ||
|
||
function NavBar() { | ||
return ( | ||
<div className="navbar"> | ||
<Link to={"/graph"}>Graph Viewer</Link> | ||
</div> | ||
); | ||
} | ||
import { GraphViewer } from "./graph/GraphViewer"; | ||
import React from "react"; | ||
import { ServiceContextProvider } from "./service/ServiceContextProvider"; | ||
|
||
export function App() { | ||
// Create actual routes if/when more functionality is added to the application | ||
return ( | ||
<HashRouter> | ||
<Routes> | ||
<Route | ||
path="/" | ||
element={<GraphViewer/>} | ||
/> | ||
</Routes> | ||
</HashRouter> | ||
); | ||
return ( | ||
<ServiceContextProvider> | ||
<GraphViewer /> | ||
</ServiceContextProvider> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from "react"; | ||
|
||
interface NdjsonFileUploadComponentProps { | ||
onFileLoaded: (data: Generator<any, void, unknown>) => void; | ||
} | ||
|
||
const NdjsonFileUploadComponent: React.FC<NdjsonFileUploadComponentProps> = ({ | ||
onFileLoaded, | ||
}: NdjsonFileUploadComponentProps) => { | ||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
const file = event.target.files?.[0]; | ||
if (file) { | ||
const reader = new FileReader(); | ||
reader.onload = (e) => { | ||
const text = e.target?.result; | ||
if (typeof text === "string") { | ||
// Create a generator for NDJSON parsing | ||
const parseNDJSON = function* ( | ||
input: string, | ||
): Generator<any, void, unknown> { | ||
const lines = input.split("\n"); | ||
for (const line of lines) { | ||
if (line.trim()) { | ||
try { | ||
yield JSON.parse(line); | ||
} catch (error) { | ||
console.error("Invalid JSON line:", line, error); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
try { | ||
// Test if the file is a single JSON object | ||
JSON.parse(text); // Throws if it's not a single JSON | ||
alert("This file is a standard JSON file. NDJSON is expected."); | ||
} catch { | ||
// If not, assume it's NDJSON and pass the generator | ||
onFileLoaded(parseNDJSON(text)); | ||
} | ||
} | ||
}; | ||
reader.readAsText(file); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<input type="file" onChange={handleFileChange} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NdjsonFileUploadComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
export abstract class DocService { | ||
abstract getDocData(): Map<string, Doc>; | ||
|
||
getDoc(id: string): Doc | undefined { | ||
return this.getDocData().get(id); | ||
} | ||
|
||
getDocs(ids: string[]): Doc[] { | ||
return ids | ||
.map((id) => this.getDoc(id)) | ||
.filter((v): v is Doc => v !== undefined); | ||
} | ||
} | ||
|
||
export interface Doc { | ||
id: string; | ||
text: string; | ||
timestamp: string; | ||
} | ||
|
||
export class SampleDocService extends DocService { | ||
readonly docData: Map<string, Doc> = new Map( | ||
[ | ||
{ | ||
id: "1", | ||
text: "sample text 1", | ||
timestamp: "", | ||
}, | ||
{ | ||
id: "2", | ||
text: "sample text 1", | ||
timestamp: "", | ||
}, | ||
{ | ||
id: "3", | ||
text: "sample text 1", | ||
timestamp: "", | ||
}, | ||
].map((d) => [d.id, d]), | ||
); | ||
|
||
getDocData(): Map<string, Doc> { | ||
return this.docData; | ||
} | ||
|
||
getDoc(id: string): Doc | undefined { | ||
return this.docData.get(id); | ||
} | ||
} | ||
|
||
export class FileDocService extends DocService { | ||
readonly docData: Map<string, Doc>; | ||
|
||
getDocData(): Map<string, Doc> { | ||
return this.docData; | ||
} | ||
|
||
constructor(docData: Doc[]) { | ||
super(); | ||
this.docData = new Map( | ||
docData.map((d) => [ | ||
d.id, | ||
{ | ||
id: d.id, | ||
text: d.text, | ||
timestamp: d.timestamp, | ||
}, | ||
]), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.