// Copyright 2017-2026 @pezkuwi/react-components authors & contributors // SPDX-License-Identifier: Apache-2.0 import React from 'react'; import { styled } from '@pezkuwi/react-components'; interface PieChartProps { data: { label: string; value: number; color: string }[]; } const Container = styled.div` display: flex; align-items: center; `; const GraphContainer = styled.div` position: relative; `; const LegendContainer = styled.div` display: flex; flex-direction: column; margin-left: 20px; `; const LegendItem = styled.div` display: flex; align-items: center; margin-bottom: 10px; `; const ColorBox = styled.div<{ color: string }>` width: 20px; height: 20px; background-color: ${(props: { color: string }) => props.color}; margin-right: 10px; `; function UsageBar ({ data }: PieChartProps): React.ReactElement { const radius = 50; const strokeWidth = 15; const circumference = 2 * Math.PI * radius; const total = data.reduce((acc, item) => acc + item.value, 0); let cumulativeOffset = 0; if (!total) { return <>; } return ( {data.map((item, index) => { const percentage = (item.value / total) * 100; const dashArray = (percentage / 100) * circumference; const dashOffset = (cumulativeOffset / 100) * circumference; cumulativeOffset += percentage; return ( {`${item.label}: ${percentage.toFixed(2)}%`} ); })} {data.map((item, index) => ( {`${item.label}: ${((item.value / total) * 100).toFixed(2)}%`} ))} ); } export default React.memo(UsageBar);