Skip to content

Commit 0af843d

Browse files
author
Robert Crocker
committed
Removed scroll listenter logic to quickly resolve the performance issues. The tootlip will now adjust its vertical position based on how close you are to the top of the chart instead of the top of the screen.
1 parent b5dc78f commit 0af843d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/components/ListeningRect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useRef } from 'react';
1+
import React, { useRef } from 'react';
22
import * as d3 from 'd3';
33
import {
44
Margin,
@@ -155,7 +155,7 @@ export default function ListeningRect({
155155
}
156156
}
157157

158-
tooltipState.distanceFromTop = tooltipState.cursorY + margin.top;
158+
tooltipState.distanceFromTop = yScale(closestYValue) + margin.top;
159159
tooltipState.distanceFromRight =
160160
width - (margin.left + tooltipState.cursorX);
161161
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;

src/components/VoronoiCell.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/restrict-plus-operands */
2-
import React, { useState, useEffect } from 'react';
2+
import React from 'react';
33
import { VoronoiProps } from '../../types';
44
import useWindowDimensions from '../hooks/useWindowDimensions';
55

@@ -14,6 +14,10 @@ export const VoronoiCell = ({
1414
margin,
1515
}: VoronoiProps): JSX.Element => {
1616
const { width } = useWindowDimensions();
17+
18+
// The code below was commented out because of the performance issues we ran
19+
// into when charts are taking in large data sets
20+
// TODO: Figure out how to performantly use scroll to improve the performance.
1721
// const [scrollPosition, setScrollPosition] = useState(0);
1822

1923
// const handleScroll = () => {
@@ -48,7 +52,7 @@ export const VoronoiCell = ({
4852
data,
4953
};
5054

51-
tooltipState.distanceFromTop = tooltipState.cursorY + margin.top;
55+
tooltipState.distanceFromTop = cellCenter.cy + margin.top;
5256
tooltipState.distanceFromRight =
5357
width - (margin.left + tooltipState.cursorX);
5458
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;

0 commit comments

Comments
 (0)