1
1
// Copyright (c) 2024 Massachusetts Institute of Technology
2
2
// SPDX-License-Identifier: MIT
3
3
4
- import { useMemo } from "react" ;
4
+ import { useMemo , useRef } from "react" ;
5
5
6
6
import Graphin , { Components , LegendChildrenProps } from "@antv/graphin" ;
7
7
import '@antv/graphin/dist/index.css' ;
8
- import { Title } from '@mantine/core' ;
8
+ import { ActionIcon , Button , Title } from '@mantine/core' ;
9
9
10
10
import { useAppSelector } from "redux/store.ts" ;
11
11
12
12
import { parseSparqlQuery } from "utils/parseSparqlQuery.ts" ;
13
13
import { transformTripleQueryToGraphin } from "utils/transformTripleDataToGraphin.ts" ;
14
14
import { useQueryGetIDTableEntitiesFromQuery } from "utils/knowledgeBase/getEntityData.ts" ;
15
+ import { IconFocus } from "@tabler/icons-react" ;
16
+
17
+ import styles from "./QueryGraph.module.scss"
15
18
16
19
const { Legend } = Components ;
17
20
@@ -26,19 +29,32 @@ export const QueryGraph = () => {
26
29
return transformTripleQueryToGraphin ( semanticTriples , idTableEntities || undefined ) ;
27
30
} , [ queryValue , idTableEntities ] ) ;
28
31
32
+ const graphRef = useRef < Graphin > ( null )
33
+ const center = ( ) => {
34
+ if ( graphRef . current ) {
35
+ const graph = graphRef . current . graph ;
36
+ graph . fitView ( ) ; // Re-centers and fits graph to view
37
+ }
38
+ }
39
+
40
+
29
41
if ( queryGraphData . nodes . length === 0 ) return null
30
42
31
43
return (
32
44
< div >
33
45
< Title style = { { color :"white" , marginLeft : 13 , marginBottom : 7 , marginTop : 7 , padding : 1 } } order = { 4 } > Query Structure Graph</ Title >
34
- < div style = { { height : '400px' } } >
35
- < Graphin data = { queryGraphData } layout = { { type : 'dagre' , rankdir : 'LR' } } style = { { minHeight : "unset" } } >
46
+ < div id = { styles [ "graph-container" ] } >
47
+ < Graphin data = { queryGraphData } ref = { graphRef } layout = { { type : 'dagre' , rankdir : 'LR' } } style = { { minHeight : "unset" } } >
36
48
< Legend bindType = "node" sortKey = "data.type" >
37
49
{ ( renderProps : LegendChildrenProps ) => {
38
50
return < Legend . Node { ...renderProps } /> ;
39
51
} }
40
52
</ Legend >
41
53
</ Graphin >
54
+
55
+ < ActionIcon className = { styles [ "recenter-button" ] } size = "sm" variant = "filled" aria-label = "Center" onClick = { ( ) => center ( ) } >
56
+ < IconFocus />
57
+ </ ActionIcon >
42
58
</ div >
43
59
</ div >
44
60
)
0 commit comments