-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
83 lines (77 loc) · 2.21 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { useEffect, useState } from "react";
import {Treemap} from "d3plus-react";
function App() {
const [data, setData] = useState([]);
const [limit, setLimit] = useState(100);
const [includePeopleTopics, setIncludePeopleTopics] = useState(false);
useEffect(() => {
fetch(`https://www.sefaria.org/api/topics?limit=${limit}`)
.then((res) => res.json())
.then((res) => {
if (res) {
const filteredData = res
.filter((topic) => includePeopleTopics || !(topic.subclass && topic.subclass === "person"))
.map((topic) => ({
title: topic.primaryTitle?.en,
numSources: topic.numSources
}));
setData(filteredData);
}
})
.catch((err) => console.error(err));
}, [limit, includePeopleTopics]);
return (
<>
<h1>Sefaria Topics Data-Viz</h1>
<div className="controls">
<h4 className="centered">Controls</h4>
<div>
<span>Adjust the number of topics queried from the API: </span>
<input
type="range"
min="100"
max="5000"
value={limit}
step="100"
onChange={(e) => setLimit(Number(e.target.value))}
/>
<span>{limit}</span>
</div>
<div>
<label>
<input
type="checkbox"
checked={includePeopleTopics}
onChange={() => setIncludePeopleTopics(!includePeopleTopics)}
/>
Include People Topics
</label>
</div>
</div>
<div className="viz">
{data.length > 0 ? (
<Treemap config={{
data: data,
groupBy: "title",
sum: "numSources",
height: 400,
width: 1200,
shapeConfig: {
label: d => {
return [d.title];
},
},
tooltipConfig: {
tbody: (d) => [
["Linked Sources:", d.numSources]
]
},
}} />
) : (
<p>Loading...</p>
)}
</div>
</>
);
}
export default App;