Skip to content

Commit ec8664a

Browse files
committed
able to zoom in out on d3
1 parent d5f1708 commit ec8664a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/app/components/Chart.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Chart extends Component {
3535
duration=0;
3636

3737
var margin = {top: 20, right: 120, bottom: 20, left: 120},
38-
width = 960 - margin.right - margin.left,
38+
width = 800 - margin.right - margin.left,
3939
height = 800 - margin.top - margin.bottom;
4040

4141
var i = 0;
@@ -49,6 +49,9 @@ class Chart extends Component {
4949
var svg = d3.select(this.refs.anchor).append("svg")
5050
.attr("width", width + margin.right + margin.left)
5151
.attr("height", height + margin.top + margin.bottom)
52+
.call(d3.behavior.zoom().on("zoom", function () {
53+
svg.attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")")
54+
}))
5255
.append("g")
5356
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
5457

@@ -215,7 +218,7 @@ class Chart extends Component {
215218
}
216219

217220
render() {
218-
return <div ref="anchor" className="d3Container" width="100%" />;
221+
return <div ref="anchor" className="d3Container" />;
219222
}
220223
}
221224

src/app/styles/components/_d3Tree.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.d3Container{
2-
display: flex;
3-
align-items: center;
4-
justify-content: center;
2+
overflow: scroll;
3+
height: 100%;
4+
width: 100%;
55
}
66

77
.node {
@@ -12,7 +12,6 @@
1212
fill: #fff;
1313
stroke: black;
1414
stroke-width: 2px;
15-
1615
}
1716

1817
.node text {

0 commit comments

Comments
 (0)