How can I avoid d3.zoom translate on first zoom or pan?
up vote
0
down vote
favorite
I try to make an orgchart with zoom and paning. To do so I need to call .nodeSize which translate my "root" to (0,0). Then I re-translate it by width/2 and it's ok. But when I implement d3.zoom, my "root" go back to (0,0)... How can i avoid this behavior ?
Here is the code concerned :
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () {
svg.attr("transform", d3.event.transform);
}))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")");
Thanks for reading.
EDIT : I did a JSFiddle so you can try my current code. Don't pay attention to big traingles (I don't have them on my real project) =>
https://jsfiddle.net/rhz1n8m4/12/
d3.js
New contributor
add a comment |
up vote
0
down vote
favorite
I try to make an orgchart with zoom and paning. To do so I need to call .nodeSize which translate my "root" to (0,0). Then I re-translate it by width/2 and it's ok. But when I implement d3.zoom, my "root" go back to (0,0)... How can i avoid this behavior ?
Here is the code concerned :
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () {
svg.attr("transform", d3.event.transform);
}))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")");
Thanks for reading.
EDIT : I did a JSFiddle so you can try my current code. Don't pay attention to big traingles (I don't have them on my real project) =>
https://jsfiddle.net/rhz1n8m4/12/
d3.js
New contributor
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to make an orgchart with zoom and paning. To do so I need to call .nodeSize which translate my "root" to (0,0). Then I re-translate it by width/2 and it's ok. But when I implement d3.zoom, my "root" go back to (0,0)... How can i avoid this behavior ?
Here is the code concerned :
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () {
svg.attr("transform", d3.event.transform);
}))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")");
Thanks for reading.
EDIT : I did a JSFiddle so you can try my current code. Don't pay attention to big traingles (I don't have them on my real project) =>
https://jsfiddle.net/rhz1n8m4/12/
d3.js
New contributor
I try to make an orgchart with zoom and paning. To do so I need to call .nodeSize which translate my "root" to (0,0). Then I re-translate it by width/2 and it's ok. But when I implement d3.zoom, my "root" go back to (0,0)... How can i avoid this behavior ?
Here is the code concerned :
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () {
svg.attr("transform", d3.event.transform);
}))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")");
Thanks for reading.
EDIT : I did a JSFiddle so you can try my current code. Don't pay attention to big traingles (I don't have them on my real project) =>
https://jsfiddle.net/rhz1n8m4/12/
d3.js
d3.js
New contributor
New contributor
edited Nov 8 at 10:57
New contributor
asked Nov 8 at 9:59
Zoom
33
33
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Apply the zoom to a node below the width/2
transform.
Rename your vars to reflect what they contain: svg
does not contain the svg
element.
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () { svg.attr("transform", d3.event.transform); }))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")")
.append('g');
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Apply the zoom to a node below the width/2
transform.
Rename your vars to reflect what they contain: svg
does not contain the svg
element.
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () { svg.attr("transform", d3.event.transform); }))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")")
.append('g');
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
add a comment |
up vote
0
down vote
accepted
Apply the zoom to a node below the width/2
transform.
Rename your vars to reflect what they contain: svg
does not contain the svg
element.
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () { svg.attr("transform", d3.event.transform); }))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")")
.append('g');
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Apply the zoom to a node below the width/2
transform.
Rename your vars to reflect what they contain: svg
does not contain the svg
element.
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () { svg.attr("transform", d3.event.transform); }))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")")
.append('g');
Apply the zoom to a node below the width/2
transform.
Rename your vars to reflect what they contain: svg
does not contain the svg
element.
var svg = d3.select("#svg1").append("svg")
.attr("width", width)
.attr("height", height)
.call(d3.zoom().on("zoom", function () { svg.attr("transform", d3.event.transform); }))
.append('g').attr("transform","translate(" + width / 2 + "," + 0 + ")")
.append('g');
answered Nov 8 at 11:17
rioV8
3,4032210
3,4032210
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
add a comment |
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
THANK YOU! It works, I will analyse carefully why, I'm totally new to JavaScript AND D3. Thank you again for your time and your answer !
– Zoom
Nov 8 at 12:02
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
Just to be complete, this works BUT the center of the zoom seems to be translated by width/2 now. I will inestigate !
– Zoom
Nov 8 at 12:07
add a comment |
Zoom is a new contributor. Be nice, and check out our Code of Conduct.
Zoom is a new contributor. Be nice, and check out our Code of Conduct.
Zoom is a new contributor. Be nice, and check out our Code of Conduct.
Zoom is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53205333%2fhow-can-i-avoid-d3-zoom-translate-on-first-zoom-or-pan%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password