Last active
March 3, 2022 12:47
-
-
Save tsukhu/5b792e7c1c64b4420d5c94431b1bb2d8 to your computer and use it in GitHub Desktop.
Nivo Charts with remix.run
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
import { LoaderFunction, useLoaderData } from "remix"; | |
import useResizeObserver from "use-resize-observer"; | |
import MyResponsiveAreaBump from "~/components/charts/AreaBump"; | |
import MyResponsiveBarCanvas from "~/components/charts/BarCanvas"; | |
import MyResponsiveChordCanvas from "~/components/charts/ChordCanvas"; | |
import MyResponsiveNetworkCanvas from "~/components/charts/NetworkCanvas"; | |
export const loader: LoaderFunction = async ({ params }) => { | |
let result = await Promise.all([ | |
fetch("http://localhost:3100/bar"), | |
fetch("http://localhost:3100/areaBump"), | |
fetch("http://localhost:3100/chord"), | |
fetch("http://localhost:3100/network"), | |
]); | |
let bar = await result[0].json(); | |
let areaBump = await result[1].json(); | |
let chord = await result[2].json(); | |
let network = await result[3].json(); | |
return { bar, areaBump, chord, network }; | |
}; | |
const ProjectsContent: React.FC = () => { | |
const data = useLoaderData(); | |
const { ref, width, height } = useResizeObserver<HTMLDivElement>(); | |
return ( | |
<div className="grid gap-4 space-x-1 grid-cols-1 lg:grid-cols-2 w-full h-full grid-rows-4 lg:grid-rows-2"> | |
<div className="flex flex-col w-full h-full" ref={ref}> | |
<MyResponsiveBarCanvas data={data.bar} width={width} height={height} /> | |
</div> | |
<div className="flex flex-col w-full h-full"> | |
<MyResponsiveAreaBump | |
data={data.areaBump} | |
width={width} | |
height={height} | |
/> | |
</div> | |
<div className="flex flex-col w-full h-full"> | |
<MyResponsiveChordCanvas | |
data={data.chord} | |
width={width} | |
height={height} | |
/> | |
</div> | |
<div className="flex flex-col w-full h-full"> | |
<MyResponsiveNetworkCanvas | |
data={data.network} | |
width={width} | |
height={height} | |
/> | |
</div> | |
</div> | |
); | |
}; | |
export default ProjectsContent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment