Skip to content

Commit

Permalink
Merge pull request #90 from oslabs-beta/tooltiprollback
Browse files Browse the repository at this point in the history
SSR logic fix and declaration files fix
  • Loading branch information
eric-mulhern committed Jan 29, 2022
2 parents b5075dd + 07ca036 commit f50067c
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 38 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@oslabs-beta/d3reactor",
"version": "0.0.7",
"version": "0.0.8",
"description": "Open-source charting library for creating performant, responsive data visualizations in React",
"main": "./dist/index.js",
"types": "./dist/src/index.d.ts",
"types": "./dist/types/src/index.d.ts",
"files": [
"dist/**/*"
],
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function App() {
xAxisLabel="GDP per capita"
yKey="Life expectancy"
yGrid={true}
yAxis="left"
yAxis="right"
yAxisLabel="Life Expectancy"
/>
<LineChart
Expand Down
5 changes: 2 additions & 3 deletions src/components/Arc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const Arc = React.memo(
({
data,
dataTestId = 'arc',
key,
fill = 'none',
stroke,
strokeWidth = '1px',
Expand Down Expand Up @@ -39,7 +38,7 @@ export const Arc = React.memo(
}
};

const onMouseLeave = (e: any) => {
const onMouseLeave = () => {
if (setTooltip) {
setTooltip ? setTooltip(false) : null;
}
Expand All @@ -54,7 +53,7 @@ export const Arc = React.memo(
strokeWidth={strokeWidth}
d={d}
onMouseMove={(e) => onMouseMove(e)}
onMouseLeave={(e) => onMouseLeave(e)}
onMouseLeave={() => onMouseLeave()}
/>
);
}
Expand Down
25 changes: 13 additions & 12 deletions src/components/ListeningRect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ export default function ListeningRect({
}) {
const anchor = useRef(null);

const [scrollPosition, setScrollPosition] = useState(0);
// const [scrollPosition, setScrollPosition] = useState(0);

const handleScroll = () => {
const position = window.pageYOffset;
setScrollPosition(position);
};
// const handleScroll = () => {
// const position = window.pageYOffset;
// setScrollPosition(position);
// };

useEffect(() => {
window.addEventListener('scroll', handleScroll, { passive: true });
// useEffect(() => {
// window.addEventListener('scroll', handleScroll, { passive: true });

// return () => {
// window.removeEventListener('scroll', handleScroll);
// };
// }, []);

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
const tooltipState: toolTipState = {
cursorX: 0,
cursorY: 0,
Expand Down Expand Up @@ -123,7 +124,7 @@ export default function ListeningRect({
}

tooltipState.distanceFromTop =
tooltipState.cursorY + margin.top - scrollPosition;
tooltipState.cursorY + margin.top;
tooltipState.distanceFromRight =
width - (margin.left + tooltipState.cursorX);
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;
Expand Down
24 changes: 12 additions & 12 deletions src/components/VoronoiCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ export const VoronoiCell = ({
margin,
}: VoronoiProps): JSX.Element => {
const { width } = useWindowDimensions();
const [scrollPosition, setScrollPosition] = useState(0);
// const [scrollPosition, setScrollPosition] = useState(0);

const handleScroll = () => {
const position = window.pageYOffset;
setScrollPosition(position);
};
// const handleScroll = () => {
// const position = window.pageYOffset;
// setScrollPosition(position);
// };

useEffect(() => {
window.addEventListener('scroll', handleScroll, { passive: true });
// useEffect(() => {
// window.addEventListener('scroll', handleScroll, { passive: true });

return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);
// return () => {
// window.removeEventListener('scroll', handleScroll);
// };
// }, []);

const tooltipState = {
cursorX: 0,
Expand All @@ -49,7 +49,7 @@ export const VoronoiCell = ({
};

tooltipState.distanceFromTop =
tooltipState.cursorY + margin.top - scrollPosition;
tooltipState.cursorY + margin.top;
tooltipState.distanceFromRight =
width - (margin.left + tooltipState.cursorX);
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;
Expand Down
17 changes: 9 additions & 8 deletions src/hooks/useWindowDimensions.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import { useState, useEffect } from 'react';

function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height,
};
}

export default function useWindowDimensions() {
const [windowDimensions, setWindowDimensions] = useState(
getWindowDimensions()
{width: 0, height: 0}
);

useEffect(() => {
function getWindowDimensions() {
const { innerWidth: width, innerHeight: height } = window;
return {
width,
height,
};
}
function handleResize() {
setWindowDimensions(getWindowDimensions());
}
handleResize()

window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
Expand Down

0 comments on commit f50067c

Please sign in to comment.