From 00d2c4bd1361c6c7cf18734981d6e98a1e86074f Mon Sep 17 00:00:00 2001 From: BooshPC Date: Wed, 5 Feb 2025 19:34:42 -0500 Subject: [PATCH] Tooltip --- observablehq.config.js | 2 +- src/index.md | 146 +++++++++++++++++++++++++++++++++-------- 2 files changed, 121 insertions(+), 27 deletions(-) diff --git a/observablehq.config.js b/observablehq.config.js index ed1d0ba..0d672b3 100644 --- a/observablehq.config.js +++ b/observablehq.config.js @@ -17,7 +17,7 @@ export default { // ], // Content to add to the head of the page, e.g. for a favicon: - head: '', + head: '', // The path to the source root. root: "src", diff --git a/src/index.md b/src/index.md index f1a3a52..9dbf08e 100644 --- a/src/index.md +++ b/src/index.md @@ -109,7 +109,11 @@ function oddsPlot(d, {width} = {}) { .attr("width", width) .attr("height", height) .attr("viewBox", [0, 0, width, height]) - .attr("style", "max-width: 100%; height: auto; background-color: black;"); + .attr("style", "max-width: 100%; height: auto; background-color: black;") + .on("mousemove", function(event, d) + { + //hideToolTip(); + }); @@ -144,10 +148,16 @@ function oddsPlot(d, {width} = {}) { ) .html((d) => buildDualSquare(d, blockWidth, blockHeight)) .on("mouseover", function(event, d){ - infoTextContainer.html("game!") - const destX = x(d.year)-blockWidth/2; - const destY = y(d); - showTooltip(destX, destY); + event.stopPropagation(); + const blockPos = d3.select(event.target.parentNode).attr("transform"); + infoTextContainer.html(buildToolTip(d)) + if(event.clientX+400>window.innerWidth) + { + infoTextContainer.attr("transform","translate(-400,0)"); + }else{ + infoTextContainer.attr("transform","translate(0,0)"); + } + showTooltip(blockPos); }) .on("mouseout", function(event, d){ hideToolTip(); @@ -156,28 +166,23 @@ function oddsPlot(d, {width} = {}) { const infoBox = svg.append("g") .attr("class", "info-box") - .attr("x", 5) - .attr("y", 5) - .attr("transform", `translate(-1000,-1000)`) - - - const infoRect = infoBox.append("rect"); + .attr("transform", `translate(-1000,1000)`) + .attr("opacity",1) + .attr("width", 420) const infoTextContainer = infoBox.append("g") .attr("fill", "white") - .attr("dy", 20) - .attr("width", 120) + .attr("width", 420) - function showTooltip(x,y) + function showTooltip(transform) { - infoBox.attr("transform", `translate(${x}, ${y})`); - infoBox.transition().delay(100).duration(500).ease(d3.easeBackOut).attr("opacity",1) + infoBox.attr("transform", `${transform}`) + infoBox.attr("opacity", 1); } function hideToolTip() { - infoBox.transition().duration(500).ease(d3.easeBackOut).attr("opacity",0) - .transition().delay(500).attr("transform", "translate(-1000,-1000)") + infoBox.attr("opacity",0) } @@ -262,22 +267,111 @@ function buildDualSquare(d, width, height) { ``` ```js -function buildToolTip() +function buildToolTip(d) { + const weekString = d.week ? `Week ${d.week}` : "Playoffs"; + const awayTeam = d.at ? d.und : `${d.fav} (-${d.spread})`; + const homeTeam = d.at ? `${d.fav} (-${d.spread})` : d.und; + const ou_text = d.ou ? `
OU ${d.ou}
` : "" + + const toolTipHTML = ` + +
+
${formatDate(d.date)} (${weekString})
+
${d.sF}
 - 
${d.sU}
+
${awayTeam}
 @ 
${homeTeam}
+ ${ou_text} +
+
+ ` + return toolTipHTML; } ``` + +
+
${teamSelect}${viewSelect}
+
Legend
+
+
+
${resize((width) => oddsPlot(oddsfile, {width}))}
+
+ -
-
${teamSelect}
-
-
-
${resize((width) => oddsPlot(oddsfile, {width}))}
-
\ No newline at end of file + .info-box + { + pointer-events: none; + } + + #tool-tip-container + { + color: white; + background-color: black; + border: 3px solid white; + padding: 15px; + text-align: center; + display: flex; + flex-direction: row; + justify-content: center; + flex-wrap: wrap; + row-gap: 10px; + + } + + #tool-tip-container .tip-item + { + flex-basis: 140px; + } + + #tool-tip-container .tip-item-small + { + flex-basis: 25px; + text-align: center; + padding: 0px 3px; + } + + #tool-tip-container .tip-item-full + { + flex-basis:100%; + } + + #tool-tip-container .tip-text-left, #tool-tip-container .tip-text-right + { + text-wrap: nowrap; + } + + #tool-tip-container .tip-text-left + { + text-align: right; + } + + #tool-tip-container .tip-text-right + { + text-align: left; + } + + .score + { + padding: 10px; + border: 2px white; + } + + .lexend-400 { + font-family: "Lexend", serif; + font-optical-sizing: auto; + font-weight: 400; + font-style: normal; + } + .lexend-200 { + font-family: "Lexend", serif; + font-optical-sizing: auto; + font-weight: 200; + font-style: normal; + } + \ No newline at end of file