Skip to content

Commit 3fcbbdd

Browse files
committed
Test update svg width on window resize
1 parent ba1cdcc commit 3fcbbdd

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

src/_App/BotAnalysis/Networks/Section.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import Card from 'react-bootstrap/Card'
77
//import Table from 'react-bootstrap/Table'
88

99
//import TreeGraph from "./Graph1"
10-
import NetworkGraph from "./Graph2"
11-
//import NewGraph from "./Graph3"
10+
//import NetworkGraph from "./Graph2"
11+
import TestGraph from "./TestGraph"
1212

1313
export default function BotNetworks() {
1414
return (
@@ -23,8 +23,19 @@ export default function BotNetworks() {
2323
</Card.Text>
2424

2525

26+
<TestGraph/>
27+
28+
{/*
2629
<NetworkGraph/>
2730
31+
*/}
32+
33+
34+
35+
36+
37+
38+
2839
{/*
2940
<Card.Text>
3041
Prototype tree graph (for a uni-directional network with discrete "levels"):
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)