-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphComponent.tsx
43 lines (36 loc) · 1.07 KB
/
GraphComponent.tsx
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
import React from 'react'
import {GraphProps, GraphState} from 'typedecls/ReactPropsAndStates'
import {ClassElementNames} from 'appConstants'
import { Vertex } from 'typedecls/D3Types'
export default class GraphComponent extends React.Component<GraphProps, GraphState> {
ref!: SVGSVGElement
constructor(props: GraphProps) {
super(props)
this.state = {
data: this.props.loadData()
}
}
componentDidMount() {
this.props.graphFactory.create(this.ref, this.props, this.state)
this.props.setSearchCallbackFunction(this.searchCallback.bind(this))
}
componentDidUpdate() {
this.props.graphFactory.update(this.ref, this.props, this.state)
}
componentWillUnmount() {
this.props.graphFactory.destroy(this.ref)
}
searchCallback(allVertices: Vertex[], searchTerm: string) {
this.props.graphFactory.searchStrategy.search(allVertices, searchTerm)
}
render() {
return (
<svg
className={ClassElementNames.graphContainerClassName}
ref={(ref: SVGSVGElement) => {
this.ref = ref
}}
/>
)
}
}