45c2b537f043cbfd70658e8f391bf816492e19d1 hiram Fri Oct 30 08:33:45 2020 -0700 last dirty checkin before moving this code to hgTracks.js refs #21980 diff --git src/hg/js/mouseOver.js src/hg/js/mouseOver.js index 38b3c01..1c8c46e 100644 --- src/hg/js/mouseOver.js +++ src/hg/js/mouseOver.js @@ -1,245 +1,327 @@ // One single top-level object variable to hold all other global variables var mapData = {}; // mapData.spans{} - key name is track name, value is an array of // objects: {x1, x2, value} // mapData.visible - keep track of window visible or not, value: true|false // shouldn't need to do this here, the window knows if it // is visible or not, just ask it for status // mapData.tracks{} - tracks that came in with mapBoxes, key is track name // value is the number of boxes (for debugging) // ========================================================================= // intersect the point with the rectangle, where rect corners are x1,y1 x2,y2 // ========================================================================= // function intersectPointRectangle(x,y, rect) { // var answer = true; // if (x <= rect.x1 || x > rect.x2) { answer = false; } // else if (y <= rect.y1 || y > rect.y2) { answer = false; } // return answer; // } +function dbgShowTracks() { +var dbgMsg = "
. . . mouse in target.id: " + evt.target.id + "(" + trackName + ")[" + foundIdx + "]='" + valP + "' spansLength: " + lengthSpansArray + " at " + offLeft + "," + offTop + ", evX,Y: " + evX + "," + evY + "
"; // $('#eventRects').html(msg); if (windowUp) { // the window should become visible popUpVisible(); } else { // the window should disappear popUpDisappear(); } // window visible/not visible } // ========================================================================= // receiveData() callback for successful JSON request, receives incoming JSON // data and gets it into global variables for use here. // The incoming 'arr' is a a set of objects where the object key name is // the track name, used here as an array reference: arr[trackName] // (currently only one object per json file, one file for each track, // this may change to have multiple tracks in one json file.) // The value associated with each track name // is an array of span definitions, where each element in the array is a // mapBox definition object: // {x1:n, x2:n, value:s} // where n is an integer in the range: 0..width, // and s is the value string to display // Will need to get them sorted on x1 for efficient searching as // they accumulate in the local data structure here. // ========================================================================= function receiveData(arr) { if (typeof mapData.spans === 'undefined') { mapData.spans = {}; // get this object started first time mapData.tracks = {}; } mapData.visible = false; for (var trackName in arr) { // alert("receiving data for " + trackName); mapData.spans[trackName] = []; // start array // add a 'mousemove' and 'mouseout' event listener to each track // display object var objectName = "td_data_" + trackName; var objectId = document.getElementById(objectName); + if (! objectId) { return; } // not sure why objects are not found objectId.addEventListener('mousemove', mouseInTrackImage); objectId.addEventListener('mouseout', mouseLeftTrackImage); // would be nice to know when the window is scrolling in the browser so - // the text box could disappear + // the text box could disappear. These do not appear to work. + // Beware, onscroll event is continuous while scrolling. +// objectId.addEventListener('onscroll', mouseLeftTrackImage); // window.addEventListener('onscroll', mouseLeftTrackImage); var itemCount = 0; // just for monitoring purposes // save incoming x1,x2,v data into the mapData.spans[trackName][] array arr[trackName].forEach(function(box) { mapData.spans[trackName].push(box); ++itemCount}); mapData.tracks[trackName] = itemCount; // merely for debugging watch } +// dbgShowTracks(); // var msg = ". . . mouse at x,y: " + Math.floor(x) + "," + Math.floor(y); // $('#xyMouse').html(xyMouse); // } // function mouseMoving(x, y) function getMouseOverData() { + if (typeof(hgTracks) !== "undefined") { + if (typeof (hgTracks.trackDb) !== "undefined") { + for (var trackName in hgTracks.trackDb) { + var isWiggle = false; + var rec = hgTracks.trackDb[trackName]; + if (rec.type.includes("wig")) { isWiggle = true; } + if (rec.type.includes("bigWig")) { isWiggle = true; } + if (! isWiggle) { continue; } + var imgName = "img_data_" + trackName; + var imgElement = document.getElementById(imgName); + if (imgElement) { + var src = imgElement.src; + var jsonUrl = src.replace("hgt/hgt_", "hgt/" + trackName + "_"); + jsonUrl = jsonUrl.replace(".png", ".json"); + jsonUrl = jsonUrl.replace("https://hgwdev-hiram.gi.ucsc.edu", ""); + fetchMapData(jsonUrl); + } + } + } + } +dbgShowTracks(); // there could be a number of these mouseOver class elements // there is one for each track that has this mouseOver data - var x = document.getElementsByClassName("mouseOver"); - for (var i = 0; i < x.length; i++) { - var trashUrl = x[i].getAttribute('trashFile'); - fetchMapData(trashUrl); - } +// var x = document.getElementsByClassName("mouseOver"); +// for (var i = 0; i < x.length; i++) { +// var trashUrl = x[i].getAttribute('trashFile'); +// fetchMapData(trashUrl); +// } } -function getMousePos(evt) { - return { x: evt.clientX, y: evt.clientY }; -} +// function getMousePos(evt) { +// return { x: evt.clientX, y: evt.clientY }; +// } -function addMouseMonitor() { - window.addEventListener('load', function(evt) { - getMouseOverData(); - }, false); +// function addMouseMonitor() { +// window.addEventListener('load', function(evt) { +// getMouseOverData(); +// }, false); // window.addEventListener('mousemove', function(evt) { // var mousePos = getMousePos(evt); // mouseMoving(Math.floor(mousePos.x), Math.floor(mousePos.y)); // }, false); -} +// } -$('document').ready(addMouseMonitor()); +// $('document').ready(addMouseMonitor());