display all data in statistics & analysis and hide percentages with values below zero

This commit is contained in:
MaysWind
2026-01-16 01:20:29 +08:00
parent 83a34ae322
commit e304f4d3fa
9 changed files with 67 additions and 51 deletions
+16 -10
View File
@@ -13,8 +13,9 @@ export interface CommonPieChartDataItem {
name: string;
displayName: string;
value: number;
actualValue: number;
percent: number;
actualPercent: number;
paintPercent: number;
color: ColorStyleValue;
sourceItem: Record<string, unknown>;
displayPercent?: string;
@@ -30,7 +31,6 @@ export interface CommonPieChartProps {
percentField?: string;
colorField?: string;
hiddenField?: string;
minValidPercent?: number;
amountValue?: boolean;
defaultCurrency?: string;
showValue?: boolean;
@@ -55,32 +55,38 @@ export function usePieChartBase(props: CommonPieChartProps) {
}
const validItems: CommonPieChartDataItem[] = [];
let accumulatedPaintPercent: number = 0;
for (const item of props.items) {
const value = item[props.valueField];
const percent = props.percentField ? item[props.percentField] : -1;
if (isNumber(value) && value > 0 &&
(!props.hiddenField || !item[props.hiddenField]) &&
(!props.minValidPercent || value / totalValidValue > props.minValidPercent)) {
if (isNumber(value) &&
(!props.hiddenField || !item[props.hiddenField])) {
const finalItem: CommonPieChartDataItem = {
id: (props.idField && item[props.idField]) ? item[props.idField] as string : item[props.nameField] as string,
name: (props.idField && item[props.idField]) ? item[props.idField] as string : item[props.nameField] as string,
displayName: item[props.nameField] as string,
value: value,
percent: (isNumber(percent) && percent >= 0) ? percent : (value / totalValidValue * 100),
actualPercent: value / totalValidValue,
value: value > 0 ? value : 0,
actualValue: value,
percent: (isNumber(percent) && percent >= 0) ? percent : (value > 0 ? value / totalValidValue * 100 : 0),
paintPercent: value > 0 ? value / totalValidValue : 0,
color: getDisplayColor((props.colorField && item[props.colorField]) ? item[props.colorField] as ColorValue : DEFAULT_CHART_COLORS[validItems.length % DEFAULT_CHART_COLORS.length]),
sourceItem: item
};
finalItem.displayPercent = formatPercentToLocalizedNumerals(finalItem.percent, 2, '&lt;0.01');
finalItem.displayValue = props.amountValue ? formatAmountToLocalizedNumeralsWithCurrency(finalItem.value, props.defaultCurrency) : finalItem.value.toString();
accumulatedPaintPercent += finalItem.paintPercent;
finalItem.displayPercent = formatPercentToLocalizedNumerals(finalItem.percent, 2, '<0.01');
finalItem.displayValue = props.amountValue ? formatAmountToLocalizedNumeralsWithCurrency(value, props.defaultCurrency) : value.toString();
validItems.push(finalItem);
}
}
if (validItems.length > 0) {
validItems[validItems.length - 1]!.paintPercent += 1 - accumulatedPaintPercent;
}
return validItems;
});