import { NumberFormatter } from 'arm-common'; import { HBox, VBox } from 'arm-core-layouts'; import p from 'prop-types'; import React, { useMemo } from 'react'; import { colors } from '../Am5.jsx'; const classNamePrefix = 'armu_ai_chatbot-pie-chart-legend'; export default function PieChartLegend(props) { const { data, xAxis, yAxis, enableTotal } = props; const total = useMemo(() => { if (enableTotal && data?.length) { return data.reduce((total, item) => total + (item[yAxis] || 0), 0); } return null; },[data, enableTotal]); if (!data || !data?.length) return null; return ( {data.map((item, index) => ( {item[xAxis]} {NumberFormatter.percent(item[yAxis])} ))} {total && ( <> Total {NumberFormatter.percent(total)} )} ); } PieChartLegend.defaultProps = { className: '', children: null } PieChartLegend.propTypes = { className: p.string, children: p.node }