Skip to content

Commit a54f124

Browse files
committed
added zoom and pan for d3 node tree graph
1 parent e8c0d02 commit a54f124

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/app/components/Chart.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class Chart extends Component {
4242
.append('svg') // chartContainer is now pointing to svg
4343
.attr('width', width)
4444
.attr('height', height);
45+
46+
svg.call(d3.zoom()
47+
.on("zoom", function () {
48+
svg.attr("transform", d3.event.transform)
49+
}))
50+
.append("g")
4551

4652
let g = chartContainer
4753
.append("g")
@@ -116,6 +122,7 @@ class Chart extends Component {
116122
.on('mouseover', function (d) {
117123
// without JSON.stringify, data will display as object Object
118124
// console.log('d.data --> ', JSON.stringify(d.data))
125+
let displayedState;
119126
tip.show(JSON.stringify(d.data.stateSnapshot), this)
120127
})
121128
.on('mouseout', tip.hide)

src/app/styles/components/d3graph.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ body {
44
background-color: black;
55
}
66

7+
.node {
8+
cursor: pointer;
9+
}
10+
711
/* this represents leaf nodes aka nodes with no children */
812
.node circle {
913
fill: #5249f7;
@@ -45,16 +49,17 @@ body {
4549
color: #320a5c;
4650
border-radius: 4px;
4751
font-size: 15px;
48-
width: 200px;
52+
width: 300px;
53+
overflow-wrap: break-word;
4954
font-family: "Overpass Mono", monospace;
5055
}
5156

5257
/* Creates a small triangle extender for the tooltip */
5358
.d3-tip:after {
5459
box-sizing: border-box;
55-
/* display: inline; */
60+
display: inline;
5661
font-size: 15px;
57-
width: 200px;
62+
width: 100%;
5863
line-height: 1;
5964
color: #9cf4df;
6065
content: "\25BC";

0 commit comments

Comments
 (0)