diff --git a/src/components/QueryVisualization/QueryGraph/QueryGraph.module.scss b/src/components/QueryVisualization/QueryGraph/QueryGraph.module.scss new file mode 100644 index 0000000..c3cc5fc --- /dev/null +++ b/src/components/QueryVisualization/QueryGraph/QueryGraph.module.scss @@ -0,0 +1,11 @@ +#graph-container { + height: 400px; + + position: relative; + + .recenter-button { + position: absolute; + top: 0.5rem; + left: 0.5rem; + } +} \ No newline at end of file diff --git a/src/components/QueryVisualization/QueryGraph/QueryGraph.tsx b/src/components/QueryVisualization/QueryGraph/QueryGraph.tsx index b69f30e..e48c042 100644 --- a/src/components/QueryVisualization/QueryGraph/QueryGraph.tsx +++ b/src/components/QueryVisualization/QueryGraph/QueryGraph.tsx @@ -1,17 +1,20 @@ // Copyright (c) 2024 Massachusetts Institute of Technology // SPDX-License-Identifier: MIT -import {useMemo} from "react"; +import {useMemo, useRef} from "react"; import Graphin, {Components, LegendChildrenProps} from "@antv/graphin"; import '@antv/graphin/dist/index.css'; -import { Title } from '@mantine/core'; +import { ActionIcon, Button, Title } from '@mantine/core'; import { useAppSelector } from "redux/store.ts"; import { parseSparqlQuery } from "utils/parseSparqlQuery.ts"; import { transformTripleQueryToGraphin } from "utils/transformTripleDataToGraphin.ts"; import { useQueryGetIDTableEntitiesFromQuery } from "utils/knowledgeBase/getEntityData.ts"; +import { IconFocus } from "@tabler/icons-react"; + +import styles from "./QueryGraph.module.scss" const { Legend } = Components; @@ -26,19 +29,32 @@ export const QueryGraph = () => { return transformTripleQueryToGraphin(semanticTriples, idTableEntities||undefined); }, [queryValue, idTableEntities]); + const graphRef = useRef(null) + const center = () => { + if(graphRef.current) { + const graph = graphRef.current.graph; + graph.fitView(); // Re-centers and fits graph to view + } + } + + if(queryGraphData.nodes.length===0) return null return (
Query Structure Graph -
- +
+ {(renderProps: LegendChildrenProps) => { return ; }} + + center()}> + +
)