|
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +import React, { PureComponent, createRef} from 'react' //createRef, useState, useEffect, useRef |
| 7 | +//import * as d3 from 'd3' |
| 8 | + |
| 9 | +import Card from 'react-bootstrap/Card' |
| 10 | +//import Row from 'react-bootstrap/Row' |
| 11 | +//import Col from 'react-bootstrap/Col' |
| 12 | + |
| 13 | +import Spinner from '../../Spinner' |
| 14 | + |
| 15 | +function MyGraph(props){ |
| 16 | + var height = props.height || 500 |
| 17 | + var width = props.width || 900 |
| 18 | + //var data = props.data |
| 19 | + return <span> |
| 20 | + <p>Height: {height} Width: {width}</p> |
| 21 | + <svg height={height} width={width} style={{border:"1px solid black"}}></svg> |
| 22 | + </span> |
| 23 | +} |
| 24 | + |
| 25 | +export default class NetworkGraph extends PureComponent { |
| 26 | + constructor(props) { |
| 27 | + super(props) |
| 28 | + this.state = {parsedResponse: null, windowSize:""} |
| 29 | + this.containerRef = createRef() |
| 30 | + this.handleResize = this.handleResize.bind(this) |
| 31 | + } |
| 32 | + |
| 33 | + render() { |
| 34 | + return ( |
| 35 | + <Card style={{marginBottom:0}}> |
| 36 | + <Card.Body> |
| 37 | + {!this.state.parsedResponse ? |
| 38 | + <Spinner/> : |
| 39 | + |
| 40 | + <div ref={this.containerRef}> |
| 41 | + <MyGraph width={this.state.windowSize * 0.5}/> |
| 42 | + </div> |
| 43 | + } |
| 44 | + </Card.Body> |
| 45 | + </Card> |
| 46 | + ) |
| 47 | + } |
| 48 | + |
| 49 | + componentDidMount(){ |
| 50 | + console.log("COMPONENT DID MOUNT") |
| 51 | + window.addEventListener("resize", this.handleResize) |
| 52 | + this.setState({parsedResponse:"abc123"}) |
| 53 | + } |
| 54 | + |
| 55 | + componentWillUnmount() { |
| 56 | + console.log("COMPONENT WILL UNMOUNT") |
| 57 | + window.removeEventListener("resize", this.handleResize); |
| 58 | + } |
| 59 | + |
| 60 | + handleResize(event){ |
| 61 | + const windowSize = window.innerWidth // todo:use container ref instead |
| 62 | + console.log("RESIZED THE WINDOW!!", windowSize) |
| 63 | + this.setState({windowSize: windowSize}) |
| 64 | + } |
| 65 | + |
| 66 | + componentDidUpdate(){ |
| 67 | + //console.log("COMPONENT DID UPDATE") |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments