Skip to content

Commit

Permalink
Custop Tooltip for bar graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mridul2820 committed Jan 21, 2022
1 parent 429207e commit c8cf654
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
5 changes: 3 additions & 2 deletions components/graphs/MostForked.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { truncate } from 'lodash';
import React from 'react'
import { truncate } from 'lodash';
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import CustomTooltip from '../reuse/CustomTooltip';

const MostForked = ({ repos }) => {
const sortByFork = repos.slice(0).sort((a, b) => (a.forkCount > b.forkCount ? -1 : 1)).slice(0, 4)
Expand Down Expand Up @@ -43,7 +44,7 @@ const MostForked = ({ repos }) => {
width={24}
tickFormatter={tickFork}
/>
<Tooltip />
<Tooltip content={<CustomTooltip />} />
<Bar dataKey="forkCount" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
Expand Down
6 changes: 4 additions & 2 deletions components/graphs/MostStar.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { truncate } from 'lodash';
import React from 'react'
import { truncate } from 'lodash';
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import CustomTooltip from '../reuse/CustomTooltip';

const MostStar = ({ repos }) => {
const sortByFork = repos.slice(0).sort((a, b) => (a.stargazerCount > b.stargazerCount ? -1 : 1)).slice(0, 4)
Expand Down Expand Up @@ -43,7 +44,8 @@ const MostStar = ({ repos }) => {
width={24}
tickFormatter={tickFork}
/>
<Tooltip />
<Tooltip content={<CustomTooltip />} />

<Bar dataKey="stargazerCount" fill="#82ca9d" />
</BarChart>
</ResponsiveContainer>
Expand Down
23 changes: 23 additions & 0 deletions components/reuse/CustomTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';

const CustomTooltip = ({ active, payload }) => {

if (active && payload && payload.length) {
return (
<div className="custom-tooltip backdrop-blur-sm shadow-sm bg-slate-50 p-2">
<p className="flex gap-3">
<span>Repository : </span>
<span className="font-semibold">{payload[0].payload.name}</span>
</p>

<p className="flex gap-3">
<span>Star Count : </span>
<span className="font-semibold">{payload[0].value}</span>
</p>
</div>
);
}
return null;
};

export default CustomTooltip;

1 comment on commit c8cf654

@vercel
Copy link

@vercel vercel bot commented on c8cf654 Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.