Fix graphs tooltip position
This commit is contained in:
parent
3701abe06a
commit
9c3473e6b4
@ -257,7 +257,7 @@ export function renderButtons(
|
|||||||
.attr("width", xButton.bandwidth())
|
.attr("width", xButton.bandwidth())
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", (event: MouseEvent, d: Datum) => {
|
.on("mousemove", (event: MouseEvent, d: Datum) => {
|
||||||
const [x, y] = pointer(event);
|
const [x, y] = pointer(event, document.body);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
@ -208,7 +208,7 @@ export function renderCalendar(
|
|||||||
.attr("x", (d) => x(d.weekNumber + 1)!)
|
.attr("x", (d) => x(d.weekNumber + 1)!)
|
||||||
.attr("y", (d) => bounds.marginTop + d.weekDay * height)
|
.attr("y", (d) => bounds.marginTop + d.weekDay * height)
|
||||||
.on("mousemove", (event: MouseEvent, d: DayDatum) => {
|
.on("mousemove", (event: MouseEvent, d: DayDatum) => {
|
||||||
const [x, y] = pointer(event);
|
const [x, y] = pointer(event, document.body);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip)
|
.on("mouseout", hideTooltip)
|
||||||
|
@ -170,7 +170,7 @@ export function histogramGraph(
|
|||||||
.attr("width", ([bin]) => barWidth(bin))
|
.attr("width", ([bin]) => barWidth(bin))
|
||||||
.attr("height", () => y(0) - y(yMax))
|
.attr("height", () => y(0) - y(yMax))
|
||||||
.on("mousemove", (event: MouseEvent, [bin, area]) => {
|
.on("mousemove", (event: MouseEvent, [bin, area]) => {
|
||||||
const [x, y] = pointer(event);
|
const [x, y] = pointer(event, document.body);
|
||||||
const pct = data.showArea ? (area / data.total) * 100 : 0;
|
const pct = data.showArea ? (area / data.total) * 100 : 0;
|
||||||
showTooltip(data.hoverText(bin, area, pct), x, y);
|
showTooltip(data.hoverText(bin, area, pct), x, y);
|
||||||
})
|
})
|
||||||
|
@ -205,7 +205,7 @@ export function renderHours(
|
|||||||
.attr("width", x.bandwidth())
|
.attr("width", x.bandwidth())
|
||||||
.attr("height", () => y(0)! - y(yMax!)!)
|
.attr("height", () => y(0)! - y(yMax!)!)
|
||||||
.on("mousemove", (event: MouseEvent, d: Hour) => {
|
.on("mousemove", (event: MouseEvent, d: Hour) => {
|
||||||
const [x, y] = pointer(event);
|
const [x, y] = pointer(event, document.body);
|
||||||
showTooltip(tooltipText(d), x, y);
|
showTooltip(tooltipText(d), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
@ -376,7 +376,7 @@ export function renderReviews(
|
|||||||
.attr("width", ([bin]) => barWidth(bin))
|
.attr("width", ([bin]) => barWidth(bin))
|
||||||
.attr("height", () => y(0) - y(yMax))
|
.attr("height", () => y(0) - y(yMax))
|
||||||
.on("mousemove", (event: MouseEvent, [bin, area]): void => {
|
.on("mousemove", (event: MouseEvent, [bin, area]): void => {
|
||||||
const [x, y] = pointer(event);
|
const [x, y] = pointer(event, document.body);
|
||||||
showTooltip(tooltipText(bin as any, area), x, y);
|
showTooltip(tooltipText(bin as any, area), x, y);
|
||||||
})
|
})
|
||||||
.on("mouseout", hideTooltip);
|
.on("mouseout", hideTooltip);
|
||||||
|
@ -3,14 +3,11 @@
|
|||||||
|
|
||||||
import throttle from "lodash.throttle";
|
import throttle from "lodash.throttle";
|
||||||
|
|
||||||
let tooltipDiv: HTMLDivElement | null = null;
|
const tooltipDiv: HTMLDivElement = document.createElement("div");
|
||||||
|
tooltipDiv.className = "graph-tooltip";
|
||||||
|
document.body.appendChild(tooltipDiv);
|
||||||
|
|
||||||
function showTooltipInner(msg: string, x: number, y: number): void {
|
function showTooltipInner(msg: string, x: number, y: number): void {
|
||||||
if (!tooltipDiv) {
|
|
||||||
tooltipDiv = document.createElement("div");
|
|
||||||
tooltipDiv.className = "graph-tooltip";
|
|
||||||
document.body.appendChild(tooltipDiv);
|
|
||||||
}
|
|
||||||
tooltipDiv.innerHTML = msg;
|
tooltipDiv.innerHTML = msg;
|
||||||
|
|
||||||
// move tooltip away from edge as user approaches right side
|
// move tooltip away from edge as user approaches right side
|
||||||
@ -18,8 +15,11 @@ function showTooltipInner(msg: string, x: number, y: number): void {
|
|||||||
tooltipDiv.clientWidth * 1.2 * (x / document.body.clientWidth)
|
tooltipDiv.clientWidth * 1.2 * (x / document.body.clientWidth)
|
||||||
);
|
);
|
||||||
|
|
||||||
tooltipDiv.style.left = `${x + 40 - shiftLeftAmount}px`;
|
const adjustedX = x + 40 - shiftLeftAmount;
|
||||||
tooltipDiv.style.top = `${y + 40}px`;
|
const adjustedY = y + 40;
|
||||||
|
|
||||||
|
tooltipDiv.style.left = `${adjustedX}px`;
|
||||||
|
tooltipDiv.style.top = `${adjustedY}px`;
|
||||||
tooltipDiv.style.opacity = "1";
|
tooltipDiv.style.opacity = "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +27,5 @@ export const showTooltip = throttle(showTooltipInner, 16);
|
|||||||
|
|
||||||
export function hideTooltip(): void {
|
export function hideTooltip(): void {
|
||||||
showTooltip.cancel();
|
showTooltip.cancel();
|
||||||
if (tooltipDiv) {
|
tooltipDiv.style.opacity = "0";
|
||||||
tooltipDiv.style.opacity = "0";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user