-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2fe4fa8
commit e2a685c
Showing
18 changed files
with
950 additions
and
44 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
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
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,22 @@ | ||
import type { DSVRowArray } from "d3-dsv"; | ||
|
||
import Heading from "../shared/Heading"; | ||
|
||
import DataTable from "./DataTable"; | ||
import DataUpload from "./DataUpload"; | ||
|
||
interface Props { | ||
data: unknown | DSVRowArray; | ||
setData: (data: unknown | DSVRowArray) => void; | ||
} | ||
|
||
const DataPanel: React.FC<Props> = ({ data, setData }) => { | ||
return ( | ||
<div className="stack stack-sm basis-1/3 px-3 py-2"> | ||
<Heading className="self-start">Data</Heading> | ||
{data ? <DataTable data={data} /> : <DataUpload setData={setData} />} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DataPanel; |
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,11 @@ | ||
import type { DSVRowArray } from "d3-dsv"; | ||
|
||
interface Props { | ||
data: unknown | DSVRowArray; | ||
} | ||
|
||
const DataTable: React.FC<Props> = () => { | ||
return <p>We have some data!</p>; | ||
}; | ||
|
||
export default DataTable; |
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,81 @@ | ||
import * as React from "react"; | ||
import { DSVRowArray, csvParse } from "d3-dsv"; | ||
|
||
interface Props { | ||
setData: (data: unknown | DSVRowArray) => void; | ||
} | ||
|
||
const DataUpload: React.FC<Props> = ({ setData }) => { | ||
const onChange = React.useCallback( | ||
(event: React.ChangeEvent<HTMLInputElement>) => { | ||
if (event.target.files?.length) { | ||
const type = event.target.files[0].type; | ||
const reader = new FileReader(); | ||
|
||
reader.onload = (theFile) => { | ||
if ( | ||
theFile.target?.result && | ||
typeof theFile.target.result === "string" | ||
) { | ||
switch (type) { | ||
case "application/json": | ||
setData(JSON.parse(theFile.target.result)); | ||
break; | ||
case "text/csv": | ||
setData(csvParse(theFile.target.result)); | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
reader.readAsText(event.target.files[0]); | ||
} | ||
}, | ||
[] | ||
); | ||
|
||
return ( | ||
<div className="flex h-full flex-col items-center justify-center border border-dashed border-slate-500"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="16" | ||
height="16" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
stroke-width="2" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
> | ||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path> | ||
<polyline points="17 8 12 3 7 8"></polyline> | ||
<line x1="12" y1="3" x2="12" y2="15"></line> | ||
</svg> | ||
<p className="mt-2 text-sm"> | ||
Upload a{" "} | ||
<label className="relative cursor-pointer border-b border-dotted border-primary text-primary"> | ||
<input | ||
type="file" | ||
accept=".csv, .json" | ||
className="absolute h-full w-full opacity-[0.0001]" | ||
onChange={onChange} | ||
/> | ||
CSV | ||
</label>{" "} | ||
or{" "} | ||
<label className="relative cursor-pointer border-b border-dotted border-primary text-primary"> | ||
<input | ||
type="file" | ||
accept=".csv, .json" | ||
className="absolute h-full w-full opacity-[0.0001]" | ||
onChange={onChange} | ||
/> | ||
JSON | ||
</label>{" "} | ||
file. | ||
</p> | ||
</div> | ||
); | ||
}; | ||
|
||
export default DataUpload; |
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,42 @@ | ||
import * as React from "react"; | ||
import { EditorView, basicSetup } from "codemirror"; | ||
import { javascript } from "@codemirror/lang-javascript"; | ||
|
||
import Heading from "../shared/Heading"; | ||
import { formatProgram } from "../../utils/formatters"; | ||
|
||
interface Props { | ||
program: string; | ||
} | ||
|
||
const ProgramEditor: React.FC<Props> = ({ program }) => { | ||
const editorRef = React.useRef<HTMLDivElement>(null); | ||
|
||
React.useEffect(() => { | ||
const editor = new EditorView({ | ||
extensions: [basicSetup, javascript()], | ||
parent: editorRef.current!, | ||
doc: formatProgram(program), | ||
}); | ||
|
||
return () => { | ||
editor.destroy(); | ||
}; | ||
}, [program]); | ||
|
||
return ( | ||
<div className="stack stack-sm relative basis-1/3 border-b border-slate-500 px-3 py-2 lg:border-b-0 lg:border-r"> | ||
<Heading className="self-start">Program</Heading> | ||
{program ? ( | ||
<div | ||
ref={editorRef} | ||
className="-mx-3 h-full bg-white text-xs text-black" | ||
/> | ||
) : ( | ||
<p>Waiting for visualization selection...</p> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProgramEditor; |
Oops, something went wrong.
e2a685c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
reviz – ./
reviz-git-main-parkerziegler.vercel.app
reviz-parkerziegler.vercel.app
reviz.vercel.app