// src/components/Legend.tsx import React from 'react'; interface LegendProps { getColor: (count: number) => string; maxCount: number; } const Legend: React.FC = ({ getColor, maxCount }) => { // Dynamically generate grades based on the maxCount of the current dataset const grades = [ 1, Math.round(maxCount / 5), Math.round(maxCount / 2.5), Math.round(maxCount / 1.5), maxCount ]; // Remove duplicates and filter out zero or invalid numbers, then sort const uniqueGrades = [...new Set(grades)].filter(g => g > 0).sort((a,b) => a-b); if (uniqueGrades.length > 1 && uniqueGrades[1] <= 1) { uniqueGrades.shift(); // remove the '1' if the next step is too close } return ( <>

Count

{uniqueGrades.map((grade, index) => { const from = grade; const to = uniqueGrades[index + 1]; return (
{from}{to ? `–${to - 1}` : '+'}
); })}
); }; export default Legend;