Skip to content

Commit

Permalink
bar chart improments
Browse files Browse the repository at this point in the history
  • Loading branch information
vishvamsinh28 committed Aug 9, 2023
1 parent 7830729 commit 4eb000b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
52 changes: 49 additions & 3 deletions components/FinancialSummary/BarChartComponent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
import React, { useState, useEffect } from 'react'
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts'
import ExpensesLink from './ExpensesLinkObject'

const CustomTooltip = ({ active, payload }) => {
if (active && payload && payload.length) {
const data = payload[0].payload;
const tooltipStyle = {
backgroundColor: 'rgba(255, 255, 255, 0.9)',
border: '1px solid #ccc',
padding: '10px',
boxShadow: '0px 2px 4px rgba(0, 0, 0, 0.1)',
borderRadius: '4px',
};
const labelStyle = {
fontSize: '14px',
fontWeight: 'bold',
marginBottom: '5px',
};
const amountStyle = {
fontSize: '12px',
color: '#555',
};

return (
<div className="custom-tooltip" style={tooltipStyle}>
<p className="tooltip-label" style={labelStyle}>{data.Category}</p>
<p className="tooltip-amount" style={amountStyle}>${data.Amount.toFixed(2)}</p>
</div>
);
}
return null;
};



const BarChartComponent = ({ data }) => {
// State for selected filters
Expand Down Expand Up @@ -108,12 +141,25 @@ const BarChartComponent = ({ data }) => {
{/* Recharts BarChart */}
<BarChart width={barWidth} height={barHeight} data={chartData}>
<CartesianGrid strokeDasharray="3 3" />
{windowWidth > 900 ? <XAxis dataKey="Category" /> : null}
<YAxis />
<Tooltip />
<Tooltip content={<CustomTooltip />} />
<Legend />
<Bar dataKey="Amount" fill="rgba(123,93,211,1)" />
<Bar
dataKey="Amount"
fill="rgba(123,93,211,1)"
onClick={(data) => {
// Get the category from the clicked bar's payload
const category = data.payload.Category;
// Replace the URL with the external website URL you want to open
const matchedLinkObject = ExpensesLink.find(obj => obj.category === category)
if (matchedLinkObject) {
// Extract the link from the matched object and open it in a new tab/window
window.open(matchedLinkObject.link, '_blank');
};
}}
/>
</BarChart>

</div>
</div>
);
Expand Down
26 changes: 26 additions & 0 deletions components/FinancialSummary/ExpensesLinkObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const ExpensesLink = [
{
category: "AsyncAPI Ambassador",
link: "https://github.com/orgs/asyncapi/discussions/425"
}, {
category: "Google Season of Docs 2022",
link: "https://github.com/orgs/asyncapi/discussions/303"
}, {
category: "AsyncAPI Mentorship 2022",
link: "https://github.com/orgs/asyncapi/discussions/284"
}, {
category: "AsyncAPI Webstore",
link: "https://github.com/orgs/asyncapi/discussions/710"
}, {
category: "AsyncAPI Bounty",
link: "https://github.com/orgs/asyncapi/discussions/541"
}, {
category: "3rd Party Services",
link: "https://github.com/orgs/asyncapi/discussions/295"
}, {
category: "Community Manager Salary",
link: "https://github.com/orgs/asyncapi/discussions/515"
}
]

export default ExpensesLink

0 comments on commit 4eb000b

Please sign in to comment.