Skip to content

Commit 039ab47

Browse files
author
Robert Crocker
committed
Removed dependancy on the window object form the Arc.
1 parent fa8b76f commit 039ab47

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ function App() {
1919
data={fruit}
2020
label="label"
2121
value="value"
22-
legend="top-right"
22+
legend="top-left"
2323
outerRadius={240}
24-
legendLabel="fruit"
2524
pieLabel={true}
2625
/>
2726
<BarChart

src/charts/PieChart/PieChart.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ export default function PieChart({
268268
d={arcGenerator(d)}
269269
id={`arc- + ${i}`}
270270
setTooltip={setTooltip}
271+
margin={margin}
272+
cWidth={cWidth}
271273
/>
272274
{pieLabel && (
273275
<PieLabel

src/components/Arc.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22

33
import { ArcProps } from '../../types';
4-
import useWindowDimensions from '../hooks/useWindowDimensions';
54

65
export const Arc = React.memo(
76
({
@@ -12,8 +11,9 @@ export const Arc = React.memo(
1211
strokeWidth = '1px',
1312
d,
1413
setTooltip,
14+
margin,
15+
cWidth,
1516
}: ArcProps): JSX.Element => {
16-
const { width } = useWindowDimensions();
1717

1818
let tooltipState = {
1919
cursorX: 0,
@@ -29,7 +29,7 @@ export const Arc = React.memo(
2929
cursorX: e.pageX,
3030
cursorY: e.pageY,
3131
distanceFromTop: e.clientY,
32-
distanceFromRight: width - e.pageX,
32+
distanceFromRight: (margin.left + cWidth + margin.right) - cWidth,
3333
distanceFromLeft: e.pageX,
3434
data,
3535
};

types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ export interface ArcProps {
345345
id?: string | number;
346346
cellCenter?: { cx: number; cy: number; tooltipData: Data };
347347
setTooltip?: React.Dispatch<any>;
348+
margin: Margin;
349+
cWidth: number;
348350
}
349351

350352
// eslint-disable-next-line import/export

0 commit comments

Comments
 (0)