import { Chart, ChartAxis, ChartBar, ChartStack, ChartTooltip } from '@patternfly/react-charts/victory'; import { getResizeObserver } from '@patternfly/react-core'; import { useEffect, useRef, useState } from 'react'; interface Bar { x: string; y: number; } export const ChartStackMonthlyResponsive: React.FunctionComponent = () => { const containerRef = useRef(null); const observer = useRef(() => {}); const [width, setWidth] = useState(0); const handleResize = () => { if (containerRef.current && containerRef.current.clientWidth) { setWidth(containerRef.current.clientWidth); } }; const bars: Bar[] = []; for (let i = 1; i < 32; i++) { bars.push({ x: `Aug. ${i}`, y: Math.floor(Math.random() * 6) + 1 }); } const renderSocketBars = () => { const socketBars = bars.map((tick, index) => ({ key: index, x: tick.x, y: tick.y, name: 'Sockets', label: `${tick.x} Sockets: ${tick.y}` })); return } />; }; const renderCoresBars = () => { const coresBars = bars.map((tick, index) => ({ key: index, x: tick.x, y: tick.y, name: 'Cores', label: `${tick.x} Cores: ${tick.y}` })); return } />; }; const renderNodesBars = () => { const nodesBars = bars.map((tick, index) => ({ key: index, x: tick.x, y: tick.y, name: 'Nodes', label: `${tick.x} Nodes: ${tick.y}` })); return } />; }; const getTickValues = (offset = 2) => { const tickValues = []; for (let i = 1; i < 32; i++) { if (i % offset === 0) { tickValues.push(`Aug. ${i}`); } } return tickValues; }; useEffect(() => { observer.current = getResizeObserver(containerRef.current, handleResize); handleResize(); return () => { observer.current(); }; }, []); return (
{renderSocketBars()} {renderCoresBars()} {renderNodesBars()}
); };