Skip to content

Commit a1d799b

Browse files
committed
add corrected MaxContribution
1 parent c650642 commit a1d799b

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

components/ContributionChart.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ function Legend({ count }) {
134134
);
135135
}
136136

137-
function scaleColor(count) {
138-
const varingScalingFactor = count < 10 ? 10 / MAX_SCALE : count / MAX_SCALE;
137+
function scaleColor(count, maxContribution) {
138+
const varingScalingFactor =
139+
count < 10 ? 10 / MAX_SCALE : maxContribution.count / MAX_SCALE;
139140
return Math.max(
140141
Math.min(Math.ceil(count / varingScalingFactor), MAX_SCALE),
141142
0
@@ -147,6 +148,9 @@ export default function ContributionChart({ startDate, endDate, data }) {
147148
const classes = useStyles({ showPlot });
148149
const firstDay = new Date(startDate);
149150
const total = data.reduce((sum, value) => sum + value.count, 0);
151+
const maxContribution = data.reduce((prev, current) => {
152+
return prev.count > current.count ? prev : current;
153+
});
150154

151155
return (
152156
<Card>
@@ -180,7 +184,7 @@ export default function ContributionChart({ startDate, endDate, data }) {
180184
if (!value) {
181185
return classes.colorCofacts0;
182186
}
183-
const scale = scaleColor(value.count);
187+
const scale = scaleColor(value.count, maxContribution);
184188
return classes[`colorCofacts${scale}`];
185189
}}
186190
transformDayElement={(element, value, index) => {

components/__snapshots__/ContributionChart.stories.storyshot

+16-16
Original file line numberDiff line numberDiff line change
@@ -3186,7 +3186,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
31863186
>
31873187
<rect
31883188
aria-describedby={null}
3189-
className="makeStyles-colorCofacts4"
3189+
className="makeStyles-colorCofacts2"
31903190
height={10}
31913191
key="7"
31923192
onBlur={[Function]}
@@ -4698,7 +4698,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
46984698
>
46994699
<rect
47004700
aria-describedby={null}
4701-
className="makeStyles-colorCofacts4"
4701+
className="makeStyles-colorCofacts2"
47024702
height={10}
47034703
key="45"
47044704
onBlur={[Function]}
@@ -4899,7 +4899,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
48994899
>
49004900
<rect
49014901
aria-describedby={null}
4902-
className="makeStyles-colorCofacts4"
4902+
className="makeStyles-colorCofacts2"
49034903
height={10}
49044904
key="50"
49054905
onBlur={[Function]}
@@ -6813,7 +6813,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
68136813
>
68146814
<rect
68156815
aria-describedby={null}
6816-
className="makeStyles-colorCofacts4"
6816+
className="makeStyles-colorCofacts2"
68176817
height={10}
68186818
key="98"
68196819
onBlur={[Function]}
@@ -7689,7 +7689,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
76897689
>
76907690
<rect
76917691
aria-describedby={null}
7692-
className="makeStyles-colorCofacts4"
7692+
className="makeStyles-colorCofacts2"
76937693
height={10}
76947694
key="120"
76957695
onBlur={[Function]}
@@ -8208,7 +8208,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
82088208
>
82098209
<rect
82108210
aria-describedby={null}
8211-
className="makeStyles-colorCofacts4"
8211+
className="makeStyles-colorCofacts3"
82128212
height={10}
82138213
key="133"
82148214
onBlur={[Function]}
@@ -9000,7 +9000,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
90009000
>
90019001
<rect
90029002
aria-describedby={null}
9003-
className="makeStyles-colorCofacts4"
9003+
className="makeStyles-colorCofacts2"
90049004
height={10}
90059005
key="153"
90069006
onBlur={[Function]}
@@ -10200,7 +10200,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1020010200
>
1020110201
<rect
1020210202
aria-describedby={null}
10203-
className="makeStyles-colorCofacts4"
10203+
className="makeStyles-colorCofacts2"
1020410204
height={10}
1020510205
key="183"
1020610206
onBlur={[Function]}
@@ -10836,7 +10836,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1083610836
>
1083710837
<rect
1083810838
aria-describedby={null}
10839-
className="makeStyles-colorCofacts4"
10839+
className="makeStyles-colorCofacts2"
1084010840
height={10}
1084110841
key="199"
1084210842
onBlur={[Function]}
@@ -11556,7 +11556,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1155611556
>
1155711557
<rect
1155811558
aria-describedby={null}
11559-
className="makeStyles-colorCofacts4"
11559+
className="makeStyles-colorCofacts3"
1156011560
height={10}
1156111561
key="217"
1156211562
onBlur={[Function]}
@@ -12789,7 +12789,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1278912789
>
1279012790
<rect
1279112791
aria-describedby={null}
12792-
className="makeStyles-colorCofacts4"
12792+
className="makeStyles-colorCofacts3"
1279312793
height={10}
1279412794
key="248"
1279512795
onBlur={[Function]}
@@ -14022,7 +14022,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1402214022
>
1402314023
<rect
1402414024
aria-describedby={null}
14025-
className="makeStyles-colorCofacts4"
14025+
className="makeStyles-colorCofacts2"
1402614026
height={10}
1402714027
key="279"
1402814028
onBlur={[Function]}
@@ -14301,7 +14301,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1430114301
>
1430214302
<rect
1430314303
aria-describedby={null}
14304-
className="makeStyles-colorCofacts4"
14304+
className="makeStyles-colorCofacts2"
1430514305
height={10}
1430614306
key="286"
1430714307
onBlur={[Function]}
@@ -14580,7 +14580,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1458014580
>
1458114581
<rect
1458214582
aria-describedby={null}
14583-
className="makeStyles-colorCofacts4"
14583+
className="makeStyles-colorCofacts2"
1458414584
height={10}
1458514585
key="293"
1458614586
onBlur={[Function]}
@@ -16896,7 +16896,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1689616896
>
1689716897
<rect
1689816898
aria-describedby={null}
16899-
className="makeStyles-colorCofacts4"
16899+
className="makeStyles-colorCofacts2"
1690016900
height={10}
1690116901
key="351"
1690216902
onBlur={[Function]}
@@ -17415,7 +17415,7 @@ exports[`Storyshots ContributionChart Normal 1`] = `
1741517415
>
1741617416
<rect
1741717417
aria-describedby={null}
17418-
className="makeStyles-colorCofacts4"
17418+
className="makeStyles-colorCofacts2"
1741917419
height={10}
1742017420
key="364"
1742117421
onBlur={[Function]}

0 commit comments

Comments
 (0)