|
| 1 | +const DELAY = 250; //Sets how long it takes for tooltips to appear in ms |
| 2 | +const OPACITY = .9; //Sets oppacity of tool-tip background; |
| 3 | +const tips = new Map(); |
| 4 | +tips.set("json-button", "Import plot, metadata, and settings"); |
| 5 | +tips.set("json-download", "Export uploaded files, metadata, and settings"); |
| 6 | +tips.set("tsv-download","Export metadata table and plot settings"); |
| 7 | +tips.set("import-metadata-button", "Import metadata with API key and email"); |
| 8 | +tips.set("load-composite-button", "Load multiple id's from one '.out' file (Under development)"); |
| 9 | +tips.set("lock-axes-label", "Prevent axes limits from changing"); |
| 10 | +tips.set("lock-axes-checkbox", "Prevent axes limits from changing"); |
| 11 | +tips.set("autoscale-axes-button", "Scales x and y axes to fit plot"); |
| 12 | +tips.set("color-trace-checkbox", "Toggle outline on plot"); |
| 13 | +tips.set("autoscale-composites-button", "Sets scale of each composite to 1 / (#of IDs)"); |
| 14 | +tips.set("reset-plot-button", "Clear settings, metadata, and uploaded files"); |
| 15 | +tips.set("enable-tooltips-label", "Turn these tooltips on or off"); |
| 16 | +tips.set("enable-tooltips-checkbox", "Turn these tooltips on or off"); |
| 17 | +tips.set("x-axis-inputs-label", "Change the x axis limits"); |
| 18 | +tips.set("xmin-text", "Change x axis minimum"); |
| 19 | +tips.set("xmax-text", "Change x axis maximum"); |
| 20 | +tips.set("y-axis-inputs-label", "Change the y axis limits") |
| 21 | +tips.set("ymin-text", "Change y axis minimum"); |
| 22 | +tips.set("ymax-text", "Change y axis maximum"); |
| 23 | + |
| 24 | +tips.set("settings-dropdown", "Use preset style settings"); |
| 25 | +tips.set("opacity-label", "Change opacity of shading for all composites"); |
| 26 | +tips.set("opacity-text", "Change opacity of shading for all composites"); |
| 27 | +tips.set("smoothing-label", "Change smoothing on plot for all composites"); |
| 28 | +tips.set("smoothing-text", "Change smoothing on plot for all composites"); |
| 29 | +tips.set("shift-label", "Shift all strands back or forth"); |
| 30 | +tips.set("shift-text", "Shift all strands back or forth"); |
| 31 | +tips.set("combined-label", "Combine forward and reverse strands"); |
| 32 | +tips.set("combined-checkbox", "Combine forward and reverse strands"); |
| 33 | +tips.set("seperate-color-label", "Toggle seperate color to forward and reverse strands"); |
| 34 | +tips.set("separate-color-checkbox", "Toggle seperate color to forward and reverse strands"); |
| 35 | +tips.set("color-trace-label", "Toggle outline on graph"); |
| 36 | +tips.set("color-trace-checkbox", "Toggle outline on graph"); |
| 37 | +tips.set("tooltip-label", "Enable coordinate tooltip"); |
| 38 | +tips.set("tooltip-checkbox", "Enable coordinate tooltip"); |
| 39 | +tips.set("show-legend-label", "Show colors legend for composites"); |
| 40 | +tips.set("show-legend-checkbox", "Show colors legend for composites"); |
| 41 | +tips.set("download-svg-button", "Download plot, labels, and legend as SVG"); |
| 42 | + |
| 43 | +tips.set("main-plot-title", "Click to change this label"); |
| 44 | +tips.set("main-plot-xlabel", "Click to change this label"); |
| 45 | +tips.set("main-plot-ylabel", "Click to change this label"); |
| 46 | + |
| 47 | +var tooltip_shown = false; |
| 48 | +id = ""; |
| 49 | + |
| 50 | +window.addEventListener('mousemove', e => { |
| 51 | + element = document.elementFromPoint(e.clientX, e.clientY); |
| 52 | + console.log(element.id); |
| 53 | + if (element != null) |
| 54 | + { |
| 55 | + id = element.id.toString(); |
| 56 | + } |
| 57 | + if (tips.has(id) && document.getElementById("enable-tooltips-checkbox").checked && !tooltip_shown){ |
| 58 | + tooltip_shown = true; |
| 59 | + makeToolTip(id, e); |
| 60 | + //Delete the tooltip when mouse leaves element |
| 61 | + d3.select("#" + id).on("mouseout", function() { |
| 62 | + d3.select("#tooltip").remove(); |
| 63 | + tooltip_shown = false; |
| 64 | + }); |
| 65 | + } |
| 66 | +},{passive: true}) |
| 67 | + |
| 68 | +function makeToolTip(id, e) |
| 69 | +{ |
| 70 | + //Create invisible tooltip |
| 71 | + let message = tips.get(id); |
| 72 | + let button = document.getElementById(id).getBoundingClientRect(); |
| 73 | + let visible = false; |
| 74 | + d3.select("body") |
| 75 | + .append("div") |
| 76 | + .attr("id", "tooltip") |
| 77 | + .style("position", "absolute") |
| 78 | + .style("top", parseFloat(button.bottom + 5) +"px") |
| 79 | + .style("z-index", "999") |
| 80 | + .style("background-color", "rgba(255, 255, 255, " + OPACITY + ")") |
| 81 | + .style("visibility", "hidden") |
| 82 | + .style("inline-size", "150px") |
| 83 | + .style("overflow-wrap", "break-word") |
| 84 | + .style("text-align", "center") |
| 85 | + .text(message) |
| 86 | + .style("color", "black") |
| 87 | + .style("font-size", "80%") |
| 88 | + .style("opacity", "1") |
| 89 | + .append("svg") |
| 90 | + .attr("width", "12px") |
| 91 | + .attr("height", "10px") |
| 92 | + .attr("baseProfile", "full") |
| 93 | + .attr("viewBox", "0 0 32 32") |
| 94 | + .attr("version", "1.1") |
| 95 | + .attr("xmlns", "http://www.w3.org/2000/svg") |
| 96 | + .style("position", "absolute") |
| 97 | + .style("top","-7px") |
| 98 | + .style("left",parseFloat(document.getElementById("tooltip").getBoundingClientRect().width / 2) - 6 + "px") |
| 99 | + .append("path") |
| 100 | + .attr("d", "M 1 24 L 16 1 L 31 24") |
| 101 | + .attr("fill", "rgba(255, 255, 255, 0.9)") |
| 102 | + .attr("stroke", "rgba(255, 255, 255, 0.9)") |
| 103 | + .attr("stroke-width", 2); |
| 104 | + //If mouse is still over element after DELAY make tooltip visible |
| 105 | + setTimeout(() => { |
| 106 | + if ($("#"+ id + ":hover").length !== 0 && !visible) { |
| 107 | + let mouseX = e.clientX; |
| 108 | + visible = true; |
| 109 | + d3.select("#tooltip") |
| 110 | + .style("left", parseFloat(mouseX - document.getElementById("tooltip").getBoundingClientRect().width / 2) + "px") |
| 111 | + .style("visibility", "visible"); |
| 112 | + } |
| 113 | + }, DELAY); |
| 114 | + //Delete the tooltip when mouse leaves element before the time has passed |
| 115 | + d3.select("#" + id).on("mouseout", function() { |
| 116 | + d3.select("#tooltip").remove(); |
| 117 | + tooltip_shown = false; |
| 118 | + }); |
| 119 | +} |
0 commit comments