Skip to content

Commit 224fb04

Browse files
Merge pull request #3 from wizeline/include-main-js
Removed script tag, added manually request and chart package
2 parents 7b6c163 + 31d0310 commit 224fb04

File tree

5 files changed

+2288
-2115
lines changed

5 files changed

+2288
-2115
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* eslint-disable no-unexpected-multiline */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
import { useEffect, useRef, useState } from 'react';
4+
import * as d3 from 'd3';
5+
6+
export type SunburstLeaf = {
7+
name: string;
8+
size: number;
9+
color: string;
10+
};
11+
12+
export type SunburstNode = {
13+
name: string;
14+
color: string;
15+
size: number;
16+
children: (SunburstNode | SunburstLeaf)[];
17+
};
18+
19+
interface SunburstElementProps {
20+
data: SunburstNode | undefined
21+
}
22+
23+
const SunburstChart = (props: SunburstElementProps) => {
24+
const { data } = props;
25+
const color = d3.scaleOrdinal(d3.schemeSet1);
26+
const chartRef = useRef<HTMLDivElement | null>(null);
27+
const [Sunburst, setSunburst] = useState<any | null>(null);
28+
29+
useEffect(() => {
30+
if (typeof window !== 'undefined') {
31+
import('sunburst-chart').then((module) => {
32+
setSunburst(module.default);
33+
});
34+
}
35+
}, []);
36+
37+
useEffect(() => {
38+
if (data && Sunburst) {
39+
const chart = Sunburst();
40+
chart.data(data)
41+
.label('name')
42+
.labelOrientation('angular')
43+
.maxLevels(10)
44+
.color((d: any, parent: any) => color(parent ? parent.data.name : null))
45+
.tooltipContent((d: any, node: any) => `Size: <i>${node.value}</i>`)
46+
(chartRef.current);
47+
}
48+
}, [data, Sunburst, color]);
49+
50+
return (
51+
<div ref={chartRef} className="mb-6"></div>
52+
);
53+
};
54+
55+
export default SunburstChart;

app/root.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function Layout({ children }: { children: React.ReactNode }) {
1414
<meta charSet="utf-8" />
1515
<meta name="viewport" content="width=device-width, initial-scale=1" />
1616
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
17-
<script id="gen-ai-map" data-boxid="chart-map" data-charttype="" src="https://gen-ai-tools-public.s3.amazonaws.com/assets/map.js"></script>
1817
<Meta />
1918
<Links />
2019
</head>

app/routes/_index.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { MetaFunction } from "@remix-run/node";
2+
import { useEffect, useState } from "react";
23
import HeaderMinimalist from "~/components/header/HeaderMinimalist";
4+
import SunburstChart from "~/components/sunburstChart/SunburstChart";
35

46
export const meta: MetaFunction = () => {
57
return [
@@ -9,10 +11,18 @@ export const meta: MetaFunction = () => {
911
};
1012

1113
export default function Index() {
14+
const [jsonData, setJsonData] = useState(null);
15+
16+
useEffect(() => {
17+
fetch('https://gen-ai-tools-public.s3.amazonaws.com/map-tree.json')
18+
.then(response => response.json())
19+
.then(data => setJsonData(data));
20+
}, [])
21+
1222
return (
1323
<div className="min-h-screen flex flex-col justify-between">
1424
<HeaderMinimalist />
15-
<div id="chart-map" className="mb-6"></div>
25+
{jsonData && <SunburstChart data={jsonData} />}
1626
</div>
1727
);
1828
}

0 commit comments

Comments
 (0)