Skip to content

Commit f50067c

Browse files
authored
Merge pull request #90 from oslabs-beta/tooltiprollback
SSR logic fix and declaration files fix
2 parents b5075dd + 07ca036 commit f50067c

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@oslabs-beta/d3reactor",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Open-source charting library for creating performant, responsive data visualizations in React",
55
"main": "./dist/index.js",
6-
"types": "./dist/src/index.d.ts",
6+
"types": "./dist/types/src/index.d.ts",
77
"files": [
88
"dist/**/*"
99
],

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function App() {
4646
xAxisLabel="GDP per capita"
4747
yKey="Life expectancy"
4848
yGrid={true}
49-
yAxis="left"
49+
yAxis="right"
5050
yAxisLabel="Life Expectancy"
5151
/>
5252
<LineChart

src/components/Arc.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export const Arc = React.memo(
88
({
99
data,
1010
dataTestId = 'arc',
11-
key,
1211
fill = 'none',
1312
stroke,
1413
strokeWidth = '1px',
@@ -39,7 +38,7 @@ export const Arc = React.memo(
3938
}
4039
};
4140

42-
const onMouseLeave = (e: any) => {
41+
const onMouseLeave = () => {
4342
if (setTooltip) {
4443
setTooltip ? setTooltip(false) : null;
4544
}
@@ -54,7 +53,7 @@ export const Arc = React.memo(
5453
strokeWidth={strokeWidth}
5554
d={d}
5655
onMouseMove={(e) => onMouseMove(e)}
57-
onMouseLeave={(e) => onMouseLeave(e)}
56+
onMouseLeave={() => onMouseLeave()}
5857
/>
5958
);
6059
}

src/components/ListeningRect.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,21 @@ export default function ListeningRect({
4141
}) {
4242
const anchor = useRef(null);
4343

44-
const [scrollPosition, setScrollPosition] = useState(0);
44+
// const [scrollPosition, setScrollPosition] = useState(0);
4545

46-
const handleScroll = () => {
47-
const position = window.pageYOffset;
48-
setScrollPosition(position);
49-
};
46+
// const handleScroll = () => {
47+
// const position = window.pageYOffset;
48+
// setScrollPosition(position);
49+
// };
5050

51-
useEffect(() => {
52-
window.addEventListener('scroll', handleScroll, { passive: true });
51+
// useEffect(() => {
52+
// window.addEventListener('scroll', handleScroll, { passive: true });
53+
54+
// return () => {
55+
// window.removeEventListener('scroll', handleScroll);
56+
// };
57+
// }, []);
5358

54-
return () => {
55-
window.removeEventListener('scroll', handleScroll);
56-
};
57-
}, []);
5859
const tooltipState: toolTipState = {
5960
cursorX: 0,
6061
cursorY: 0,
@@ -123,7 +124,7 @@ export default function ListeningRect({
123124
}
124125

125126
tooltipState.distanceFromTop =
126-
tooltipState.cursorY + margin.top - scrollPosition;
127+
tooltipState.cursorY + margin.top;
127128
tooltipState.distanceFromRight =
128129
width - (margin.left + tooltipState.cursorX);
129130
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;

src/components/VoronoiCell.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ export const VoronoiCell = ({
1414
margin,
1515
}: VoronoiProps): JSX.Element => {
1616
const { width } = useWindowDimensions();
17-
const [scrollPosition, setScrollPosition] = useState(0);
17+
// const [scrollPosition, setScrollPosition] = useState(0);
1818

19-
const handleScroll = () => {
20-
const position = window.pageYOffset;
21-
setScrollPosition(position);
22-
};
19+
// const handleScroll = () => {
20+
// const position = window.pageYOffset;
21+
// setScrollPosition(position);
22+
// };
2323

24-
useEffect(() => {
25-
window.addEventListener('scroll', handleScroll, { passive: true });
24+
// useEffect(() => {
25+
// window.addEventListener('scroll', handleScroll, { passive: true });
2626

27-
return () => {
28-
window.removeEventListener('scroll', handleScroll);
29-
};
30-
}, []);
27+
// return () => {
28+
// window.removeEventListener('scroll', handleScroll);
29+
// };
30+
// }, []);
3131

3232
const tooltipState = {
3333
cursorX: 0,
@@ -49,7 +49,7 @@ export const VoronoiCell = ({
4949
};
5050

5151
tooltipState.distanceFromTop =
52-
tooltipState.cursorY + margin.top - scrollPosition;
52+
tooltipState.cursorY + margin.top;
5353
tooltipState.distanceFromRight =
5454
width - (margin.left + tooltipState.cursorX);
5555
tooltipState.distanceFromLeft = margin.left + tooltipState.cursorX;

src/hooks/useWindowDimensions.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { useState, useEffect } from 'react';
22

3-
function getWindowDimensions() {
4-
const { innerWidth: width, innerHeight: height } = window;
5-
return {
6-
width,
7-
height,
8-
};
9-
}
103

114
export default function useWindowDimensions() {
125
const [windowDimensions, setWindowDimensions] = useState(
13-
getWindowDimensions()
6+
{width: 0, height: 0}
147
);
158

169
useEffect(() => {
10+
function getWindowDimensions() {
11+
const { innerWidth: width, innerHeight: height } = window;
12+
return {
13+
width,
14+
height,
15+
};
16+
}
1717
function handleResize() {
1818
setWindowDimensions(getWindowDimensions());
1919
}
20+
handleResize()
2021

2122
window.addEventListener('resize', handleResize);
2223
return () => window.removeEventListener('resize', handleResize);

0 commit comments

Comments
 (0)