// PricingChart.jsx
import React, { useState } from 'react';
import { useScrollToTop } from '../hooks/useScrollToTop';
import '../styles/PricingChart.css';
const ChartLegend = ({ onLegendClick, highlightedBarTypes }) => {
return (
onLegendClick('input')}
style={{ cursor: 'pointer', opacity: highlightedBarTypes.input ? 1 : 0.5 }}
>
Input Price
onLegendClick('output')}
style={{ cursor: 'pointer', opacity: highlightedBarTypes.output ? 1 : 0.5 }}
>
Output Price
);
};
const ChartBar = ({ price, type, maxPrice, highlighted }) => {
const getBarHeight = () => {
return (price / maxPrice) * 300;
};
return (
{price}
);
};
const ProviderColumn = ({ provider, maxPrice, highlightedBarTypes }) => (
{provider.name}
);
const YAxis = ({ maxPrice }) => {
const numberOfTicks = 5;
const tickValues = [];
for (let i = 0; i <= numberOfTicks; i++) {
const value = ((maxPrice / numberOfTicks) * i).toFixed(2);
tickValues.push(value);
}
return (
{tickValues.reverse().map((value, index) => (
{value}
))}
);
};
const GridLines = () => (
{[...Array(5)].map((_, index) => (
))}
);
const PricingChart = ({ data }) => {
useScrollToTop();
const [highlightedBarTypes, setHighlightedBarTypes] = useState({
input: true,
output: true,
});
const handleLegendClick = (barType) => {
setHighlightedBarTypes((prevState) => ({
...prevState,
[barType]: !prevState[barType],
}));
};
const getMaxPrice = () => {
const prices = data.providers.flatMap((provider) => [
provider.inputPrice,
provider.outputPrice,
]);
return Math.max(...prices);
};
const maxPrice = getMaxPrice();
return (
{data.title}
{data.subtitle}
{data.providers.map((provider) => (
))}
);
};
export default PricingChart;