Skip to content

Commit

Permalink
Update child width based on container width
Browse files Browse the repository at this point in the history
  • Loading branch information
s2t2 committed Nov 2, 2020
1 parent b797fd4 commit 12ebcf5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/_App/BotAnalysis/Networks/TestGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Spinner from '../../Spinner'

function MyGraph(props){
var height = props.height || 500
var width = props.width || window.innerWidth * 0.75 // todo:use container ref instead
//var data = props.data
var width = props.width || 300 // todo: use container ref instead

return <span>
<p>Height: {height} Width: {width}</p>
<svg height={height} width={width} style={{border:"1px solid black"}}></svg>
Expand Down Expand Up @@ -49,7 +49,10 @@ export default class NetworkGraph extends PureComponent {
componentDidMount(){
console.log("COMPONENT DID MOUNT")
window.addEventListener("resize", this.handleResize)
this.setState({parsedResponse:"abc123"})
//const width = this.containerRef.current.clientWidth
this.setState({parsedResponse:"abc123",
//width: width
})
}

componentWillUnmount() {
Expand All @@ -58,7 +61,8 @@ export default class NetworkGraph extends PureComponent {
}

handleResize(event){
const width = window.innerWidth * 0.75 // todo:use container ref instead
const width = this.containerRef.current.clientWidth // window.innerWidth * 0.75
//const width = this.containerRef.current.width
console.log("RESIZED THE WINDOW!!", width)
this.setState({width: width})
}
Expand Down

0 comments on commit 12ebcf5

Please sign in to comment.