I followed the Data Visualization example pretty closely to get this up:
The problem I’m having is that, when I move my mouse from node to node, the box flickers.
The frame rate of the screen cast is pretty low, so I’m not sure if it’s obvious, but the flickering happens 0:04
There’s no flicker if
- I move my mouse slowly
- my mouse is moving from bottom up
The flicker happens only when I’m moving my mouse from a higher node to a lower node
Here’s part of my code involving the mouse over box
myDiagram.mouseOver = function(e) {
var doc = e.documentPoint;
var list = myDiagram.findObjectsNear(
doc,
100,
null,
function(x) { return x instanceof go.Node; });
var closest = null;
var closestDist = 999999999;
var itr = list.iterator;
while (itr.next()) {
var val = itr.value;
var dist = doc.distanceSquaredPoint(val.getDocumentPoint(go.Spot.Center));
if (dist < closestDist) {
closestDist = dist;
closest = val;
}
}
highlightNode(e, closest);
};
var infoBoxH = document.getElementById("infoBoxHolder");
infoBoxH.addEventListener("mousemove", function() {
var box = document.getElementById("infoBoxHolder");
box.style.left = parseInt(box.style.left) + "px";
box.style.top = parseInt(box.style.top) + 30 + "px";
}, false);
var infoBox = document.getElementById("infoBox");
var diagramDiv = document.getElementById("myDiagram");
// Make sure the infoBox is hidden when the mouse is not over the Diagram
diagramDiv.addEventListener("mouseout", function(e) {
if (lastStroked !== null) lastStroked.stroke = null;
lastStroked = null;
if (document.elementFromPoint(e.clientX, e.clientY) === infoBox) {
var box = document.getElementById("infoBoxHolder");
box.style.left = parseInt(box.style.left) + "px";
box.style.top = parseInt(box.style.top) + 30 + "px";
} else {
infoBoxH.innerHTML = "";
}
}, false);
function highlightNode(e, node) {
if (node !== null) {
var shape = node.findObject("backgroundLayer");
if (shape != null) {
shape.stroke = "grey";
}
if (lastStroked !== null && lastStroked !== shape) lastStroked.stroke = null;
lastStroked = shape;
updateInfoBox(e.viewPoint, node.data);
} else {
if (lastStroked !== null) lastStroked.stroke = null;
lastStroked = null;
document.getElementById("infoBoxHolder").innerHTML = "";
}
}
All of which are very similar to http://www.gojs.net/latest/samples/dataVisualization.html as I followed the example very closely.
How can I prevent the flickering?
The flickering is way more intense than it appears on the screen cast.