Skip to content

Commit

Permalink
feat: variable bar number according to contributors number
Browse files Browse the repository at this point in the history
  • Loading branch information
tyn1998 committed Aug 13, 2023
1 parent 36ec44f commit 35dd841
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as echarts from 'echarts';
import type { EChartsOption, EChartsType } from 'echarts';

interface RacingBarProps {
height: number;
repoName: string;
data: any;
}
Expand Down Expand Up @@ -35,8 +34,8 @@ const option: EChartsOption = {
return `${value} {avatar${value.replaceAll('-', '')}|}`;
},
},
animationDuration: 300,
animationDurationUpdate: 300,
animationDuration: 0,
animationDurationUpdate: 200,
},
series: [
{
Expand Down Expand Up @@ -131,9 +130,41 @@ const play = (instance: EChartsType, data: any) => {
playNext();
};

const RacingBar = ({ height, data }: RacingBarProps): JSX.Element => {
/**
* Count the number of unique contributors in the data
*/
const countLongTermContributors = (data: any) => {
const contributors = new Map<string, number>();
Object.keys(data).forEach((month) => {
data[month].forEach((item: any[]) => {
if (contributors.has(item[0])) {
contributors.set(item[0], contributors.get(item[0])! + 1);
} else {
contributors.set(item[0], 0);
}
});
});
let count = 0;
contributors.forEach((value) => {
// only count contributors who have contributed more than 3 months
if (value >= 3) {
count++;
}
});
return count;
};

const RacingBar = ({ data }: RacingBarProps): JSX.Element => {
const divEL = useRef<HTMLDivElement>(null);

let height = 300;
const longTermContributorsCount = countLongTermContributors(data);
if (longTermContributorsCount >= 20) {
// @ts-ignore
option.yAxis.max = 20;
height = 600;
}

useEffect(() => {
if (!divEL.current) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const View = ({ currentRepo, repoActivityDetails }: Props): JSX.Element => {
<RacingBar
key={replay}
repoName={currentRepo}
height={300}
data={repoActivityDetails}
/>
</div>
Expand Down

0 comments on commit 35dd841

Please sign in to comment.