Skip to content

Commit

Permalink
added graph recenter button
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Li committed Jan 29, 2025
1 parent 93b70bf commit d51616d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#graph-container {
height: 400px;

position: relative;

.recenter-button {
position: absolute;
top: 0.5rem;
left: 0.5rem;
}
}
24 changes: 20 additions & 4 deletions src/components/QueryVisualization/QueryGraph/QueryGraph.tsx
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 8 in src/components/QueryVisualization/QueryGraph/QueryGraph.tsx

View workflow job for this annotation

GitHub Actions / deploy

'Button' is declared but its value is never read.

Check failure on line 8 in src/components/QueryVisualization/QueryGraph/QueryGraph.tsx

View workflow job for this annotation

GitHub Actions / deploy

'Button' is declared but its value is never read.

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;

Expand All @@ -26,19 +29,32 @@ export const QueryGraph = () => {
return transformTripleQueryToGraphin(semanticTriples, idTableEntities||undefined);
}, [queryValue, idTableEntities]);

const graphRef = useRef<Graphin>(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 (
<div>
<Title style={{color:"white", marginLeft: 13, marginBottom: 7, marginTop: 7, padding: 1}} order={4}>Query Structure Graph</Title>
<div style={{height: '400px'}}>
<Graphin data={queryGraphData} layout={{type: 'dagre', rankdir: 'LR'}} style={{minHeight: "unset"}}>
<div id={styles["graph-container"]}>
<Graphin data={queryGraphData} ref={graphRef} layout={{type: 'dagre', rankdir: 'LR'}} style={{minHeight: "unset"}}>
<Legend bindType="node" sortKey="data.type">
{(renderProps: LegendChildrenProps) => {
return <Legend.Node {...renderProps} />;
}}
</Legend>
</Graphin>

<ActionIcon className={styles["recenter-button"]} size="sm" variant="filled" aria-label="Center" onClick={() => center()}>
<IconFocus/>
</ActionIcon>
</div>
</div>
)
Expand Down

0 comments on commit d51616d

Please sign in to comment.