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 ? `