mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
code refactor
This commit is contained in:
@@ -10,7 +10,6 @@ type CategoricalChartTypeName = 'Pie' | 'Bar';
|
||||
|
||||
export class CategoricalChartType implements TypeAndName {
|
||||
private static readonly allInstances: CategoricalChartType[] = [];
|
||||
private static readonly allInstancesByTypeName: Record<string, CategoricalChartType> = {};
|
||||
|
||||
public static readonly Pie = new CategoricalChartType(0, 'Pie', 'Pie Chart');
|
||||
public static readonly Bar = new CategoricalChartType(1, 'Bar', 'Bar Chart');
|
||||
@@ -27,23 +26,17 @@ export class CategoricalChartType implements TypeAndName {
|
||||
this.name = name;
|
||||
|
||||
CategoricalChartType.allInstances.push(this);
|
||||
CategoricalChartType.allInstancesByTypeName[typeName] = this;
|
||||
}
|
||||
|
||||
public static values(): CategoricalChartType[] {
|
||||
return CategoricalChartType.allInstances;
|
||||
}
|
||||
|
||||
public static all(): Record<CategoricalChartTypeName, CategoricalChartType> {
|
||||
return CategoricalChartType.allInstancesByTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
type TrendChartTypeName = 'Area' | 'Column';
|
||||
|
||||
export class TrendChartType implements TypeAndName {
|
||||
private static readonly allInstances: TrendChartType[] = [];
|
||||
private static readonly allInstancesByTypeName: Record<string, TrendChartType> = {};
|
||||
|
||||
public static readonly Area = new TrendChartType(0, 'Area', 'Area Chart');
|
||||
public static readonly Column = new TrendChartType(1, 'Column', 'Column Chart');
|
||||
@@ -60,16 +53,11 @@ export class TrendChartType implements TypeAndName {
|
||||
this.name = name;
|
||||
|
||||
TrendChartType.allInstances.push(this);
|
||||
TrendChartType.allInstancesByTypeName[typeName] = this;
|
||||
}
|
||||
|
||||
public static values(): TrendChartType[] {
|
||||
return TrendChartType.allInstances;
|
||||
}
|
||||
|
||||
public static all(): Record<TrendChartTypeName, TrendChartType> {
|
||||
return TrendChartType.allInstancesByTypeName;
|
||||
}
|
||||
}
|
||||
|
||||
type ChartDataTypeName = 'ExpenseByAccount' | 'ExpenseByPrimaryCategory' | 'ExpenseBySecondaryCategory' | 'IncomeByAccount' | 'IncomeByPrimaryCategory' | 'IncomeBySecondaryCategory' | 'AccountTotalAssets' | 'AccountTotalLiabilities' | 'TotalExpense' | 'TotalIncome' | 'TotalBalance';
|
||||
@@ -77,7 +65,6 @@ type ChartDataTypeName = 'ExpenseByAccount' | 'ExpenseByPrimaryCategory' | 'Expe
|
||||
export class ChartDataType implements TypeAndName {
|
||||
private static readonly allInstances: ChartDataType[] = [];
|
||||
private static readonly allInstancesByType: Record<number, ChartDataType> = {};
|
||||
private static readonly allInstancesByTypeName: Record<string, ChartDataType> = {};
|
||||
|
||||
public static readonly ExpenseByAccount = new ChartDataType(0, 'ExpenseByAccount', 'Expense By Account', StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.TrendAnalysis);
|
||||
public static readonly ExpenseByPrimaryCategory = new ChartDataType(1, 'ExpenseByPrimaryCategory', 'Expense By Primary Category', StatisticsAnalysisType.CategoricalAnalysis, StatisticsAnalysisType.TrendAnalysis);
|
||||
@@ -112,7 +99,6 @@ export class ChartDataType implements TypeAndName {
|
||||
|
||||
ChartDataType.allInstances.push(this);
|
||||
ChartDataType.allInstancesByType[type] = this;
|
||||
ChartDataType.allInstancesByTypeName[typeName] = this;
|
||||
}
|
||||
|
||||
public isAvailableAnalysisType(analysisType: StatisticsAnalysisType): boolean {
|
||||
@@ -135,10 +121,6 @@ export class ChartDataType implements TypeAndName {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static all(): Record<ChartDataTypeName, ChartDataType> {
|
||||
return ChartDataType.allInstancesByTypeName;
|
||||
}
|
||||
|
||||
public static valueOf(type: number): ChartDataType | undefined {
|
||||
return ChartDataType.allInstancesByType[type];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user