mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 15:07:33 +08:00
display all data in statistics & analysis and hide percentages with values below zero
This commit is contained in:
@@ -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, '<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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user