Skip to content

Commit

Permalink
fix: Update dot layout on dimension change
Browse files Browse the repository at this point in the history
  • Loading branch information
anjuca154 committed Dec 7, 2023
1 parent 6c0f8e3 commit 55c7655
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/lib/dot-matrix/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Chart = (props: ChartProps): JSX.Element => {

const dotWidth = useMemo(
() => (width ? width / columns - spaceBetweenDots : DEFAULT_DOT_WIDTH),
[width]
[width, columns, spaceBetweenDots]
);

return (
Expand Down
5 changes: 4 additions & 1 deletion src/lib/dot-matrix/DotMatrix.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const DotMatrix = (props: DotMatrixPropType): JSX.Element => {

const width = useChartContainerWidth("dots-container", [
showLegend,
legendPosition
legendPosition,
dimensions.rows,
dimensions.columns,
spaceBetweenDots
]);

const [dotsToBeMapped, totalDots, fractionalDots] = useDotMatrix(
Expand Down
6 changes: 1 addition & 5 deletions src/lib/dot-matrix/custom-hooks/useChartContainerWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ import { findContainerWidth } from "../utils/utils";

const useChartContainerWidth = (
id: string,
dependencyArray: Array<boolean | string>
dependencyArray: Array<boolean | string | number | undefined>
): number => {
const [width, setWidth] = useState<number>(DEFAULT_DOT_CONTAINER_WIDTH);

useEffect(() => {
updateContainerWidth();
}, []);

useEffect(() => {
updateContainerWidth();
}, [...dependencyArray]);
Expand Down

0 comments on commit 55c7655

Please sign in to comment.