Skip to content

Commit 12ebcf5

Browse files
committed
Update child width based on container width
1 parent b797fd4 commit 12ebcf5

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/_App/BotAnalysis/Networks/TestGraph.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import Spinner from '../../Spinner'
1414

1515
function MyGraph(props){
1616
var height = props.height || 500
17-
var width = props.width || window.innerWidth * 0.75 // todo:use container ref instead
18-
//var data = props.data
17+
var width = props.width || 300 // todo: use container ref instead
18+
1919
return <span>
2020
<p>Height: {height} Width: {width}</p>
2121
<svg height={height} width={width} style={{border:"1px solid black"}}></svg>
@@ -49,7 +49,10 @@ export default class NetworkGraph extends PureComponent {
4949
componentDidMount(){
5050
console.log("COMPONENT DID MOUNT")
5151
window.addEventListener("resize", this.handleResize)
52-
this.setState({parsedResponse:"abc123"})
52+
//const width = this.containerRef.current.clientWidth
53+
this.setState({parsedResponse:"abc123",
54+
//width: width
55+
})
5356
}
5457

5558
componentWillUnmount() {
@@ -58,7 +61,8 @@ export default class NetworkGraph extends PureComponent {
5861
}
5962

6063
handleResize(event){
61-
const width = window.innerWidth * 0.75 // todo:use container ref instead
64+
const width = this.containerRef.current.clientWidth // window.innerWidth * 0.75
65+
//const width = this.containerRef.current.width
6266
console.log("RESIZED THE WINDOW!!", width)
6367
this.setState({width: width})
6468
}

0 commit comments

Comments
 (0)