/** * Simple Bar Chart Component * Lightweight bar chart for displaying data */ import React from "react"; import { __ } from "../../lib/i18n"; interface BarData { label: string; value: number; color?: string; } interface SimpleBarChartProps { data: BarData[]; title: string; height?: number; showValues?: boolean; } /** * Simple Bar Chart Component */ export const SimpleBarChart: React.FC = ({ data, title, height = 200, showValues = true, }) => { if (!data || data.length === 0) { return (
{__("No data available", "yatra")}
); } const maxValue = Math.max(...data.map((d) => d.value), 1); const chartHeight = height - 60; const defaultColors = ["#3b82f6", "#10b981", "#f59e0b", "#ef4444", "#8b5cf6"]; return (
{title && (

{title}

)}
{data.map((item, index) => { const ratio = item.value / maxValue; // Height in pixels relative to chartHeight, with a strong minimum for non-zero values const barPixelHeight = item.value > 0 ? Math.max(ratio * chartHeight, 24) : 0; const color = item.color || defaultColors[index % defaultColors.length]; return (
0 ? "24px" : "4px", }} title={`${item.label}: ${item.value}`} > {showValues && item.value > 0 && ( {item.value} )}
{item.label}
); })}
); }; export default SimpleBarChart;