1- import React from 'react' ;
1+ import React , { useMemo } from 'react' ;
22import { v4 } from 'uuid' ;
33import {
44 getNumberOfDots ,
5- getContainerWidth ,
65 getStyles ,
76 hasOverlapping
87} from './utils/utils' ;
98import {
109 Elements ,
1110 DEFAULT_COLUMNS ,
12- DEFAULT_ROWS
13- } from "./constants" ;
11+ DEFAULT_ROWS ,
12+ DEFAULT_ROW_WIDTH ,
13+ DEFAULT_ROW_GAP
14+ } from './constants' ;
1415import { ChartProps , DataPointType } from './types' ;
1516import classes from './styles.module.scss' ;
1617
@@ -20,18 +21,22 @@ const Chart = (props: ChartProps) : JSX.Element => {
2021 styles,
2122 data,
2223 overlappingValues,
23- total
24+ total,
25+ width
2426 } = props ;
2527 const {
2628 rows = DEFAULT_ROWS ,
2729 columns = DEFAULT_COLUMNS
2830 } = dimensions ;
2931
32+ const dotWidth = useMemo (
33+ ( ) => ( width ? width / columns - DEFAULT_ROW_GAP : DEFAULT_ROW_WIDTH ) ,
34+ [ width ]
35+ ) ;
3036 return (
3137 < div
3238 className = { classes . dotsContainer }
3339 style = { {
34- width : `${ getContainerWidth ( columns ) } rem` ,
3540 ...getStyles ( Elements . DotsContainer , styles )
3641 } }
3742 >
@@ -43,16 +48,22 @@ const Chart = (props: ChartProps) : JSX.Element => {
4348 < div
4449 className = { classes . eachDot }
4550 style = { {
46- backgroundImage : `linear-gradient(to right, ${ data [ rowIndex - 1 ] . color } 20%, ${ dataItem ?. color } 50%)` ,
47- ...( getStyles ( Elements . Dot , styles ) )
51+ backgroundImage : `linear-gradient(to right, ${
52+ data [ rowIndex - 1 ] . color
53+ } 20%, ${ dataItem ?. color } 50%)`,
54+ width : `${ dotWidth } px` ,
55+ height : `${ dotWidth } px` ,
56+ ...getStyles ( Elements . Dot , styles )
4857 } }
4958 />
5059 ) ) || (
5160 < div
5261 className = { classes . eachDot }
5362 style = { {
5463 backgroundColor : dataItem ?. color ,
55- ...( getStyles ( Elements . Dot , styles ) )
64+ width : `${ dotWidth } px` ,
65+ height : `${ dotWidth } px` ,
66+ ...getStyles ( Elements . Dot , styles )
5667 } }
5768 key = { v4 ( ) }
5869 id = { `each-category-${ rowIndex } -${ columnIndex } ` }
@@ -63,6 +74,6 @@ const Chart = (props: ChartProps) : JSX.Element => {
6374 </ React . Fragment >
6475 ) ) }
6576 </ div >
66- )
77+ ) ;
6778} ;
68- export default Chart ;
79+ export default Chart ;
0 commit comments