@@ -9,7 +9,6 @@ import KeyboardArrowUpIcon from '@material-ui/icons/KeyboardArrowUp';
9
9
import KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown' ;
10
10
import { addDays , format } from 'date-fns' ;
11
11
12
- const SCALING_FACTOR = 5 ;
13
12
const MAX_SCALE = 4 ;
14
13
15
14
const useStyles = makeStyles ( theme => ( {
@@ -38,6 +37,13 @@ const useStyles = makeStyles(theme => ({
38
37
} ,
39
38
} ,
40
39
root : {
40
+ overflow : 'hidden' ,
41
+ 'align-items' : 'flex-end !important' ,
42
+ 'flex-direction' : 'column !important' ,
43
+ display : 'flex !important' ,
44
+ '& .react-calendar-heatmap' : {
45
+ minHeight : 140 ,
46
+ } ,
41
47
'& svg' : {
42
48
background : '#fff' ,
43
49
@@ -128,15 +134,25 @@ function Legend({ count }) {
128
134
) ;
129
135
}
130
136
131
- function scaleColor ( count ) {
132
- return Math . max ( Math . min ( Math . round ( count / SCALING_FACTOR ) , MAX_SCALE ) , 0 ) ;
137
+ function scaleColor ( count , maxContribution ) {
138
+ const varingScalingFactor =
139
+ maxContribution . count < 10
140
+ ? 10 / MAX_SCALE
141
+ : maxContribution . count / MAX_SCALE ;
142
+ return Math . max (
143
+ Math . min ( Math . ceil ( count / varingScalingFactor ) , MAX_SCALE ) ,
144
+ 0
145
+ ) ;
133
146
}
134
147
135
148
export default function ContributionChart ( { startDate, endDate, data } ) {
136
149
const [ showPlot , setShowPlot ] = useState ( true ) ;
137
150
const classes = useStyles ( { showPlot } ) ;
138
151
const firstDay = new Date ( startDate ) ;
139
152
const total = data . reduce ( ( sum , value ) => sum + value . count , 0 ) ;
153
+ const maxContribution = data . reduce ( ( prev , current ) => {
154
+ return prev . count > current . count ? prev : current ;
155
+ } ) ;
140
156
141
157
return (
142
158
< Card >
@@ -170,7 +186,7 @@ export default function ContributionChart({ startDate, endDate, data }) {
170
186
if ( ! value ) {
171
187
return classes . colorCofacts0 ;
172
188
}
173
- const scale = scaleColor ( value . count ) ;
189
+ const scale = scaleColor ( value . count , maxContribution ) ;
174
190
return classes [ `colorCofacts${ scale } ` ] ;
175
191
} }
176
192
transformDayElement = { ( element , value , index ) => {
0 commit comments