|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | + |
| 4 | +export default function CompactDebugPanel(props) { |
| 5 | + const { data, title, color } = props; |
| 6 | + |
| 7 | + if (!data || data.length === 0) { |
| 8 | + return ( |
| 9 | + <div className="bg-black bg-opacity-30 rounded-lg p-3 border border-gray-600 border-opacity-30"> |
| 10 | + <div className="flex items-center space-x-2 mb-2"> |
| 11 | + <div className="w-2 h-2 bg-gray-500 rounded-full" /> |
| 12 | + <span className="text-white font-medium text-sm">{title}</span> |
| 13 | + </div> |
| 14 | + <p className="text-gray-400 text-xs">No data</p> |
| 15 | + </div> |
| 16 | + ); |
| 17 | + } |
| 18 | + |
| 19 | + const highest = Math.max(...data); |
| 20 | + const lowest = Math.min(...data); |
| 21 | + const average = data.reduce((a, b) => a + b, 0) / data.length; |
| 22 | + const latest = data[data.length - 1]; |
| 23 | + |
| 24 | + // Create mini sparkline |
| 25 | + const sparklinePoints = data.slice(-120); // Last 120 points (show more history) |
| 26 | + const sparklineMax = Math.max(...sparklinePoints); |
| 27 | + const sparklineMin = Math.min(...sparklinePoints); |
| 28 | + const sparklineRange = sparklineMax - sparklineMin || 1; |
| 29 | + |
| 30 | + const sparklinePath = sparklinePoints.map((value, index) => { |
| 31 | + const x = (index / Math.max(sparklinePoints.length - 1, 1)) * 90 + 5; // Keep 5% margin on sides |
| 32 | + const y = 90 - ((value - sparklineMin) / sparklineRange) * 80 + 5; // Keep 5% margin on top/bottom |
| 33 | + return `${index === 0 ? 'M' : 'L'} ${x} ${y}`; |
| 34 | + }).join(' '); |
| 35 | + |
| 36 | + return ( |
| 37 | + <div className="bg-black bg-opacity-30 rounded-lg p-3 border border-gray-600 border-opacity-30"> |
| 38 | + {/* Header */} |
| 39 | + <div className="flex items-center justify-between mb-2"> |
| 40 | + <div className="flex items-center space-x-2"> |
| 41 | + <div className="w-2 h-2 rounded-full" style={{ backgroundColor: color }} /> |
| 42 | + <span className="text-white font-medium text-sm">{title}</span> |
| 43 | + </div> |
| 44 | + <span className="text-gray-300 font-mono text-xs"> |
| 45 | + {typeof latest === 'number' ? latest.toFixed(2) : latest} |
| 46 | + </span> |
| 47 | + </div> |
| 48 | + |
| 49 | + {/* Mini Sparkline */} |
| 50 | + <div className="mb-3 overflow-hidden"> |
| 51 | + <svg |
| 52 | + width="100%" |
| 53 | + height="64" |
| 54 | + viewBox="0 0 100 100" |
| 55 | + className="block w-full h-16" |
| 56 | + preserveAspectRatio="none" |
| 57 | + > |
| 58 | + <path |
| 59 | + d={sparklinePath} |
| 60 | + fill="none" |
| 61 | + stroke={color} |
| 62 | + strokeWidth="2" |
| 63 | + vectorEffect="non-scaling-stroke" |
| 64 | + /> |
| 65 | + </svg> |
| 66 | + </div> |
| 67 | + |
| 68 | + {/* Stats Grid */} |
| 69 | + <div className="grid grid-cols-2 gap-2 text-xs"> |
| 70 | + <div className="flex justify-between"> |
| 71 | + <span className="text-gray-400">Max:</span> |
| 72 | + <span className="text-white font-mono"> |
| 73 | + {typeof highest === 'number' ? highest.toFixed(2) : highest} |
| 74 | + </span> |
| 75 | + </div> |
| 76 | + <div className="flex justify-between"> |
| 77 | + <span className="text-gray-400">Min:</span> |
| 78 | + <span className="text-white font-mono"> |
| 79 | + {typeof lowest === 'number' ? lowest.toFixed(2) : lowest} |
| 80 | + </span> |
| 81 | + </div> |
| 82 | + <div className="flex justify-between"> |
| 83 | + <span className="text-gray-400">Avg:</span> |
| 84 | + <span className="text-white font-mono"> |
| 85 | + {typeof average === 'number' ? average.toFixed(2) : average} |
| 86 | + </span> |
| 87 | + </div> |
| 88 | + <div className="flex justify-between"> |
| 89 | + <span className="text-gray-400">Pts:</span> |
| 90 | + <span className="text-white font-mono">{data.length}</span> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + ); |
| 95 | +} |
| 96 | + |
| 97 | +CompactDebugPanel.propTypes = { |
| 98 | + title: PropTypes.string.isRequired, |
| 99 | + data: PropTypes.array.isRequired, |
| 100 | + color: PropTypes.string, |
| 101 | +}; |
| 102 | + |
| 103 | +CompactDebugPanel.defaultProps = { |
| 104 | + color: '#3B82F6', |
| 105 | +}; |
0 commit comments