D3 React framework with pan and zoom functionality. Mouse click to create new point on graph
up vote
0
down vote
favorite
I am using a the d3 library to create a scatterplot graph in a React application. Specifically I am trying to select points on the graph and have done so by clicking the <Circle> elements. I would like to select them by clicking anywhere on the screen instead of on the <Circle> element.
Having trouble converting the mouse click coordinate from the pixel position to the position on the scatterplot. Have successfully captured the mouse click pixel coordinate but am having trouble converting it to the graph coordinate when the graph is moved via panning or zooming.
let x = nextProps.mouseCoords.x;
let y = nextProps.mouseCoords.y;
console.log(this.xScale.invert(x) + " " + this.yScale.invert(y));
^this logs coordinates that are not correct.
Here is the scale functionality.
this.xScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => x)])
.range([0, width]);
this.yScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => y)])
.range([0, height]);
if (zoomTransform && zoomType === "detail") {
this.xScale.domain(zoomTransform.rescaleX(this.xScale).domain());
this.yScale.domain(zoomTransform.rescaleY(this.yScale).domain());
}
Any help would be greatly appreciated.
reactjs d3.js graph zoom pan
New contributor
add a comment |
up vote
0
down vote
favorite
I am using a the d3 library to create a scatterplot graph in a React application. Specifically I am trying to select points on the graph and have done so by clicking the <Circle> elements. I would like to select them by clicking anywhere on the screen instead of on the <Circle> element.
Having trouble converting the mouse click coordinate from the pixel position to the position on the scatterplot. Have successfully captured the mouse click pixel coordinate but am having trouble converting it to the graph coordinate when the graph is moved via panning or zooming.
let x = nextProps.mouseCoords.x;
let y = nextProps.mouseCoords.y;
console.log(this.xScale.invert(x) + " " + this.yScale.invert(y));
^this logs coordinates that are not correct.
Here is the scale functionality.
this.xScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => x)])
.range([0, width]);
this.yScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => y)])
.range([0, height]);
if (zoomTransform && zoomType === "detail") {
this.xScale.domain(zoomTransform.rescaleX(this.xScale).domain());
this.yScale.domain(zoomTransform.rescaleY(this.yScale).domain());
}
Any help would be greatly appreciated.
reactjs d3.js graph zoom pan
New contributor
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using a the d3 library to create a scatterplot graph in a React application. Specifically I am trying to select points on the graph and have done so by clicking the <Circle> elements. I would like to select them by clicking anywhere on the screen instead of on the <Circle> element.
Having trouble converting the mouse click coordinate from the pixel position to the position on the scatterplot. Have successfully captured the mouse click pixel coordinate but am having trouble converting it to the graph coordinate when the graph is moved via panning or zooming.
let x = nextProps.mouseCoords.x;
let y = nextProps.mouseCoords.y;
console.log(this.xScale.invert(x) + " " + this.yScale.invert(y));
^this logs coordinates that are not correct.
Here is the scale functionality.
this.xScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => x)])
.range([0, width]);
this.yScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => y)])
.range([0, height]);
if (zoomTransform && zoomType === "detail") {
this.xScale.domain(zoomTransform.rescaleX(this.xScale).domain());
this.yScale.domain(zoomTransform.rescaleY(this.yScale).domain());
}
Any help would be greatly appreciated.
reactjs d3.js graph zoom pan
New contributor
I am using a the d3 library to create a scatterplot graph in a React application. Specifically I am trying to select points on the graph and have done so by clicking the <Circle> elements. I would like to select them by clicking anywhere on the screen instead of on the <Circle> element.
Having trouble converting the mouse click coordinate from the pixel position to the position on the scatterplot. Have successfully captured the mouse click pixel coordinate but am having trouble converting it to the graph coordinate when the graph is moved via panning or zooming.
let x = nextProps.mouseCoords.x;
let y = nextProps.mouseCoords.y;
console.log(this.xScale.invert(x) + " " + this.yScale.invert(y));
^this logs coordinates that are not correct.
Here is the scale functionality.
this.xScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => x)])
.range([0, width]);
this.yScale = d3.scaleLinear()
.domain([0, d3.max(data, ([x, y]) => y)])
.range([0, height]);
if (zoomTransform && zoomType === "detail") {
this.xScale.domain(zoomTransform.rescaleX(this.xScale).domain());
this.yScale.domain(zoomTransform.rescaleY(this.yScale).domain());
}
Any help would be greatly appreciated.
reactjs d3.js graph zoom pan
reactjs d3.js graph zoom pan
New contributor
New contributor
edited Nov 5 at 9:46
rioV8
3,3682210
3,3682210
New contributor
asked Nov 5 at 3:44
David Goode
1
1
New contributor
New contributor
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06
add a comment |
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
David Goode is a new contributor. Be nice, and check out our Code of Conduct.
David Goode is a new contributor. Be nice, and check out our Code of Conduct.
David Goode is a new contributor. Be nice, and check out our Code of Conduct.
David Goode 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%2f53148036%2fd3-react-framework-with-pan-and-zoom-functionality-mouse-click-to-create-new-po%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
Do you have your code on a sandbox or somewhere I can take a look?
– Louis345
Nov 6 at 19:06