I have a d3.js visualization (v5 using promises) that I have been working on. Not the best at javascript, and maybe it's because I've been staring at the screen too long but I can't get this else statement to trigger for dblclick events.
// react to double click .on() event
function doubleclicked(d) {
if (d.fx == null & d.fy == null){
console.log("d.fx and d.fy are null, fixing point");
d.fx = d.x;
d.fy = d.y;
d3.select(this).select("text").transition()
.duration(750)
.attr("x", 22)
.style("stroke", "black")
.style("font", "10px sans-serif")
.style("font-weight", "normal")
.style("weight", "normal")
.style("pointer-events", "none");
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 16)
.style("stroke-width", "1.5px")
.style("fill","light gray")
.style("stroke","black");
} else{
console.log('whyyyy wont this work');
// you can set null, or delete d.fx, delete d.fy keys
d.fx = null;
d.fy = null;
d3.select(this).select("text").transition()
.duration(750)
.attr("x", 22)
.style("stroke", "blue")
.style("stroke-width", ".5px")
.style("font", "20px sans-serif");
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 16);};
};
Per the documentation and SO link here I am able to successfully set the node to a fixed position (if statement executes). But I am unable to get the else statement to trigger, and I'm sure it's something stupid I am overlooking. Does anyone have any ideas?
I have added my drag funcs as I feel it has something to do with that.
function dragstarted(d) {
console.log('drag start');
if (!d3.event.active) force.alphaTarget(0.3).restart();
d.fx = d.x;
d.fy = d.y;
};
function dragged(d) {
console.log('drag mid');
d.fx = d3.event.x;
d.fy = d3.event.y;
};
function dragended(d) {
console.log('drag end');
if (!d3.event.active) force.alphaTarget(0);
if (d.fx == null && d.fy ==null){
d.fx = d.x;
d.fy = d.y;
}
else{
d.fx = null;
d.fy = null;
}