simulate click in javascript (outside the window too..)












2















I'm trying to simulate clicks dynamically, i already did it for three indented tree with this function :



document.onmousemove = function(e) {
cursorX = e.pageX;
cursorY = e.pageY;
}

function ret_vw(v) {
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
return (v * w) / 100;
}

function simulateClick(x, y) {
var s = d3.select(document.elementFromPoint(x, y));
s.on("click")(s.datum());
}

function multiple_click() {
//onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}
if (cursorX >= ret_vw(15.25) && cursorX < ret_vw(42)) {
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(43.25) && cursorX < ret_vw(70.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(71.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX - ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else
console.log("no , cursorX = " + cursorX + " , cursorY = " + cursorY + " vw = " + ret_vw(15.25));
}


And it works for this below, if i click on one, it will click on the two others idented three :



(Without Click)



enter image description here



(With Click)



enter image description here



But i got two problem, if i push one of the indented tree outside of the window, it will not work, and secondly, i need to do it dynamically because i will not always have 3 indented three (i can have like two, four, five idented tree...)



Here is the picture for the case where my function multiple_click will not work (tree outside the window..) :



enter image description here



Thanks for the help guys !



(source of the idented tree with d3.js : https://bl.ocks.org/mbostock/1093025)










share|improve this question

























  • What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

    – Shushan
    Nov 26 '18 at 9:52











  • I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

    – Zahreddine Laidi
    Nov 26 '18 at 10:01






  • 1





    Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

    – Dominic
    Nov 26 '18 at 10:02











  • When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

    – Zahreddine Laidi
    Nov 26 '18 at 10:06
















2















I'm trying to simulate clicks dynamically, i already did it for three indented tree with this function :



document.onmousemove = function(e) {
cursorX = e.pageX;
cursorY = e.pageY;
}

function ret_vw(v) {
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
return (v * w) / 100;
}

function simulateClick(x, y) {
var s = d3.select(document.elementFromPoint(x, y));
s.on("click")(s.datum());
}

function multiple_click() {
//onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}
if (cursorX >= ret_vw(15.25) && cursorX < ret_vw(42)) {
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(43.25) && cursorX < ret_vw(70.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(71.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX - ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else
console.log("no , cursorX = " + cursorX + " , cursorY = " + cursorY + " vw = " + ret_vw(15.25));
}


And it works for this below, if i click on one, it will click on the two others idented three :



(Without Click)



enter image description here



(With Click)



enter image description here



But i got two problem, if i push one of the indented tree outside of the window, it will not work, and secondly, i need to do it dynamically because i will not always have 3 indented three (i can have like two, four, five idented tree...)



Here is the picture for the case where my function multiple_click will not work (tree outside the window..) :



enter image description here



Thanks for the help guys !



(source of the idented tree with d3.js : https://bl.ocks.org/mbostock/1093025)










share|improve this question

























  • What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

    – Shushan
    Nov 26 '18 at 9:52











  • I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

    – Zahreddine Laidi
    Nov 26 '18 at 10:01






  • 1





    Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

    – Dominic
    Nov 26 '18 at 10:02











  • When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

    – Zahreddine Laidi
    Nov 26 '18 at 10:06














2












2








2








I'm trying to simulate clicks dynamically, i already did it for three indented tree with this function :



document.onmousemove = function(e) {
cursorX = e.pageX;
cursorY = e.pageY;
}

function ret_vw(v) {
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
return (v * w) / 100;
}

function simulateClick(x, y) {
var s = d3.select(document.elementFromPoint(x, y));
s.on("click")(s.datum());
}

function multiple_click() {
//onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}
if (cursorX >= ret_vw(15.25) && cursorX < ret_vw(42)) {
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(43.25) && cursorX < ret_vw(70.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(71.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX - ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else
console.log("no , cursorX = " + cursorX + " , cursorY = " + cursorY + " vw = " + ret_vw(15.25));
}


And it works for this below, if i click on one, it will click on the two others idented three :



(Without Click)



enter image description here



(With Click)



enter image description here



But i got two problem, if i push one of the indented tree outside of the window, it will not work, and secondly, i need to do it dynamically because i will not always have 3 indented three (i can have like two, four, five idented tree...)



Here is the picture for the case where my function multiple_click will not work (tree outside the window..) :



enter image description here



Thanks for the help guys !



(source of the idented tree with d3.js : https://bl.ocks.org/mbostock/1093025)










share|improve this question
















I'm trying to simulate clicks dynamically, i already did it for three indented tree with this function :



document.onmousemove = function(e) {
cursorX = e.pageX;
cursorY = e.pageY;
}

function ret_vw(v) {
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
return (v * w) / 100;
}

function simulateClick(x, y) {
var s = d3.select(document.elementFromPoint(x, y));
s.on("click")(s.datum());
}

function multiple_click() {
//onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}
if (cursorX >= ret_vw(15.25) && cursorX < ret_vw(42)) {
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(43.25) && cursorX < ret_vw(70.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX + ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
}
else if (cursorX >= ret_vw(71.25)) {
simulateClick(cursorX - ret_vw(28) - window.pageXOffset, cursorY - window.pageYOffset);
simulateClick(cursorX - ret_vw(56) - window.pageXOffset, cursorY - window.pageYOffset);
}
else
console.log("no , cursorX = " + cursorX + " , cursorY = " + cursorY + " vw = " + ret_vw(15.25));
}


And it works for this below, if i click on one, it will click on the two others idented three :



(Without Click)



enter image description here



(With Click)



enter image description here



But i got two problem, if i push one of the indented tree outside of the window, it will not work, and secondly, i need to do it dynamically because i will not always have 3 indented three (i can have like two, four, five idented tree...)



Here is the picture for the case where my function multiple_click will not work (tree outside the window..) :



enter image description here



Thanks for the help guys !



(source of the idented tree with d3.js : https://bl.ocks.org/mbostock/1093025)







javascript html






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 10:07







Zahreddine Laidi

















asked Nov 26 '18 at 9:45









Zahreddine LaidiZahreddine Laidi

13612




13612













  • What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

    – Shushan
    Nov 26 '18 at 9:52











  • I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

    – Zahreddine Laidi
    Nov 26 '18 at 10:01






  • 1





    Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

    – Dominic
    Nov 26 '18 at 10:02











  • When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

    – Zahreddine Laidi
    Nov 26 '18 at 10:06



















  • What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

    – Shushan
    Nov 26 '18 at 9:52











  • I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

    – Zahreddine Laidi
    Nov 26 '18 at 10:01






  • 1





    Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

    – Dominic
    Nov 26 '18 at 10:02











  • When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

    – Zahreddine Laidi
    Nov 26 '18 at 10:06

















What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

– Shushan
Nov 26 '18 at 9:52





What is the click supposed to do? If you're relying on on-screen click it might be problematic. Can you share the code that the click causes?

– Shushan
Nov 26 '18 at 9:52













I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

– Zahreddine Laidi
Nov 26 '18 at 10:01





I added a picture to see the difference (without click and with), and added at the end the source of the idented tree. Hope it helps you to solve my problem :) @Shushan

– Zahreddine Laidi
Nov 26 '18 at 10:01




1




1





Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

– Dominic
Nov 26 '18 at 10:02





Why are you driving this from a click rather than having control of your app and e.g. calling a function to do it, do you not have access to the code? Is this for functional tests?

– Dominic
Nov 26 '18 at 10:02













When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

– Zahreddine Laidi
Nov 26 '18 at 10:06





When i click on one idented tree, i need to click to all others idented tree as well, so this is why i'm simulating the others click only when the user already clicked on one idented tree, and it's actually my code, but it's to long to show you everything (1k lines of code..) @Dominic

– Zahreddine Laidi
Nov 26 '18 at 10:06












1 Answer
1






active

oldest

votes


















1














I would suggest that instead of using mouse events to trigger the click - which eventually calls this click function:



function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}


You would make a new mouseClick function which replaces the current one which happens on mouse click.
This calls the current click function for all matching items. This is the concept:



function mouseClick(d) {
// Assuming you have multiple roots (example only has root)

for (root in roots) {
// Find d in the current root (by name?)
matching_d = ...

click(matching_d)
}
}





share|improve this answer
























  • Thank you, this helped me to finaly find a solution, well done !

    – Zahreddine Laidi
    Nov 26 '18 at 10:54











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478370%2fsimulate-click-in-javascript-outside-the-window-too%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I would suggest that instead of using mouse events to trigger the click - which eventually calls this click function:



function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}


You would make a new mouseClick function which replaces the current one which happens on mouse click.
This calls the current click function for all matching items. This is the concept:



function mouseClick(d) {
// Assuming you have multiple roots (example only has root)

for (root in roots) {
// Find d in the current root (by name?)
matching_d = ...

click(matching_d)
}
}





share|improve this answer
























  • Thank you, this helped me to finaly find a solution, well done !

    – Zahreddine Laidi
    Nov 26 '18 at 10:54
















1














I would suggest that instead of using mouse events to trigger the click - which eventually calls this click function:



function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}


You would make a new mouseClick function which replaces the current one which happens on mouse click.
This calls the current click function for all matching items. This is the concept:



function mouseClick(d) {
// Assuming you have multiple roots (example only has root)

for (root in roots) {
// Find d in the current root (by name?)
matching_d = ...

click(matching_d)
}
}





share|improve this answer
























  • Thank you, this helped me to finaly find a solution, well done !

    – Zahreddine Laidi
    Nov 26 '18 at 10:54














1












1








1







I would suggest that instead of using mouse events to trigger the click - which eventually calls this click function:



function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}


You would make a new mouseClick function which replaces the current one which happens on mouse click.
This calls the current click function for all matching items. This is the concept:



function mouseClick(d) {
// Assuming you have multiple roots (example only has root)

for (root in roots) {
// Find d in the current root (by name?)
matching_d = ...

click(matching_d)
}
}





share|improve this answer













I would suggest that instead of using mouse events to trigger the click - which eventually calls this click function:



function click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}


You would make a new mouseClick function which replaces the current one which happens on mouse click.
This calls the current click function for all matching items. This is the concept:



function mouseClick(d) {
// Assuming you have multiple roots (example only has root)

for (root in roots) {
// Find d in the current root (by name?)
matching_d = ...

click(matching_d)
}
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 26 '18 at 10:16









ShushanShushan

1,1171814




1,1171814













  • Thank you, this helped me to finaly find a solution, well done !

    – Zahreddine Laidi
    Nov 26 '18 at 10:54



















  • Thank you, this helped me to finaly find a solution, well done !

    – Zahreddine Laidi
    Nov 26 '18 at 10:54

















Thank you, this helped me to finaly find a solution, well done !

– Zahreddine Laidi
Nov 26 '18 at 10:54





Thank you, this helped me to finaly find a solution, well done !

– Zahreddine Laidi
Nov 26 '18 at 10:54




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478370%2fsimulate-click-in-javascript-outside-the-window-too%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)