Skip to content

Commit

Permalink
feat: implemented hover and highlight contribution graph (#1404)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakrudrapaul authored Jul 24, 2023
1 parent 35cfd22 commit 0453370
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/hooks/useContributorPullRequestsChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from "react";
import getPullRequestsToDays from "lib/utils/get-prs-to-days";
import { RepoList } from "components/molecules/CardRepoList/card-repo-list";
import { getAvatarByUsername } from "lib/utils/github";
import getFormattedTooltipValue from "lib/utils/get-formatted-tooltip-value";
import useContributorPullRequests from "./api/useContributorPullRequests";

const useContributorPullRequestsChart = (contributor: string, topic: string, repoIds: number[] = [], range = 30) => {
Expand Down Expand Up @@ -42,6 +43,10 @@ const useContributorPullRequestsChart = (contributor: string, topic: string, rep
},
},
],
tooltip: {
trigger: "axis",
formatter: getFormattedTooltipValue,
},
};

const [chart, setChart] = useState(lineChart);
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/get-formatted-tooltip-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type TooltipParams = {
name: string;
value: number;
};
const getFormattedTooltipValue = (params: Array<TooltipParams>) => {
const currentParam = params[0];
const daysAgo = parseInt(currentParam.name) > 1 ? currentParam.name + " days ago" : currentParam.name + " day ago";
const prCount = currentParam.value > 1 ? currentParam.value + " PRs" : currentParam.value + " PR";
return `${daysAgo} <br/> ${prCount}`;
};

export default getFormattedTooltipValue;
3 changes: 3 additions & 0 deletions stories/molecules/card-line-chart.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const testOptions = {
color: "#FFB74D",
opacity: 0.6,
},
tooltip: {
trigger: "axis",
},
},
],
};
Expand Down

0 comments on commit 0453370

Please sign in to comment.