Commit 1ca62a44 authored by tom's avatar tom Committed by isstuev

show tooltip only after first draw

parent f0e5ad8d
...@@ -117,31 +117,38 @@ const ChartTooltip = ({ xScale, yScale, width, height, data, anchorEl, ...props ...@@ -117,31 +117,38 @@ const ChartTooltip = ({ xScale, yScale, width, height, data, anchorEl, ...props
drawLine(baseXPos); drawLine(baseXPos);
drawContent(baseXPos, baseYPos); drawContent(baseXPos, baseYPos);
} }
}, [ drawPoints, drawLine, drawContent ]); }, [ drawPoints, drawLine, drawContent ]);
React.useEffect(() => { React.useEffect(() => {
const anchorD3 = d3.select(anchorEl); const anchorD3 = d3.select(anchorEl);
const subscriptions: Array<string> = []; const subscriptions: Array<string> = [];
let isShown = false;
anchorD3 anchorD3
.on('touchmove.tooltip', (event: PointerEvent) => event.preventDefault()) // prevent scrolling .on('touchmove.tooltip', (event: PointerEvent) => event.preventDefault()) // prevent scrolling
.on('pointerenter.tooltip pointerdown.tooltip', (event: PointerEvent) => { .on('pointerenter.tooltip pointerdown.tooltip', (event: PointerEvent) => {
const newSubscriptions = trackPointer(event, { const newSubscriptions = trackPointer(event, {
start: () => {
d3.select(ref.current).attr('opacity', 1);
d3.select(ref.current)
.selectAll('.ChartTooltip__point')
.attr('opacity', 1);
},
move: (pointer) => { move: (pointer) => {
if (!pointer.point) {
return;
}
draw(pointer); draw(pointer);
if (!isShown) {
d3.select(ref.current).attr('opacity', 1);
d3.select(ref.current)
.selectAll('.ChartTooltip__point')
.attr('opacity', 1);
isShown = true;
}
}, },
out: () => { out: () => {
d3.select(ref.current).attr('opacity', 0); d3.select(ref.current).attr('opacity', 0);
isShown = false;
}, },
end: () => { end: () => {
d3.select(ref.current).attr('opacity', 0); d3.select(ref.current).attr('opacity', 0);
isShown = false;
}, },
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment