Add show all to time filter. Set default zoom out

This commit is contained in:
William Jeynes
2026-04-25 11:28:53 +01:00
parent 259f9aee0a
commit 0491a55bf6
2 changed files with 38 additions and 6 deletions
@@ -151,6 +151,12 @@ export function VizSmallConnected() {
fgRef.current.d3ReheatSimulation(); fgRef.current.d3ReheatSimulation();
}, [graphData]); }, [graphData]);
useEffect(() => {
if (fgRef.current) {
fgRef.current.zoom(0.01, 0);
}
}, []);
return ( return (
<div> <div>
<ForceGraph2D <ForceGraph2D
+32 -6
View File
@@ -134,7 +134,8 @@ function getConnectedComponents(nodes, links) {
export function VizTimeFilter() { export function VizTimeFilter() {
const fgRef = useRef(); const fgRef = useRef();
const [selectedNode, setSelectedNode] = useState(null); const [selectedNode, setSelectedNode] = useState(null);
const [inputDate, setInputDate] = useState(1682353753000); const [inputDate, setInputDate] = useState(1682353753000); //some time in 2023
const [showAll, setShowAll] = useState(false);
const parsedInputDate = useMemo(() => { const parsedInputDate = useMemo(() => {
const d = new Date(inputDate); const d = new Date(inputDate);
@@ -208,13 +209,19 @@ export function VizTimeFilter() {
const set = new Set(); const set = new Set();
graphData.nodes.forEach((n) => { graphData.nodes.forEach((n) => {
if (isNodeHighlighted(n, parsedInputDate)) { if (showAll || isNodeHighlighted(n, parsedInputDate)) {
set.add(n.id); set.add(n.id);
} }
}); });
return set; return set;
}, [graphData.nodes, parsedInputDate]); }, [graphData.nodes, parsedInputDate, showAll]);
useEffect(() => {
if (fgRef.current) {
fgRef.current.zoom(0.01, 0);
}
}, []);
return ( return (
<div> <div>
@@ -237,7 +244,6 @@ export function VizTimeFilter() {
return bothHighlighted ? "orange" : "rgba(0,0,0,0)"; return bothHighlighted ? "orange" : "rgba(0,0,0,0)";
}} }}
linkWidth={2.5} linkWidth={2.5}
onNodeClick={(node) => setSelectedNode(node)} onNodeClick={(node) => setSelectedNode(node)}
nodeCanvasObject={(node, ctx) => { nodeCanvasObject={(node, ctx) => {
const label = node.label; const label = node.label;
@@ -355,8 +361,28 @@ export function VizTimeFilter() {
}} }}
/> />
<div style={{ color: "white", fontSize: "12px", marginTop: "5px" }}> <div
{new Date(inputDate).toISOString().slice(0, 10)} (± 6 months window) style={{
color: "white",
fontSize: "12px",
marginTop: "5px",
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}}
>
<span>
{new Date(inputDate).toISOString().slice(0, 10)} (± 6 months window)
</span>
<label style={{ display: "flex", alignItems: "center", gap: "5px" }}>
<span>Show all</span>
<input
type="checkbox"
checked={showAll}
onChange={() => setShowAll(!showAll)}
/>
</label>
</div> </div>
</div> </div>
</div> </div>