add chart date type settings for trend analysis

This commit is contained in:
MaysWind
2024-05-27 00:50:50 +08:00
parent 5eca777891
commit f041e7cb7d
16 changed files with 446 additions and 190 deletions
+14
View File
@@ -26,6 +26,20 @@ export function isBoolean(val) {
return typeof(val) === 'boolean';
}
export function isYearMonth(val) {
if (typeof(val) !== 'string') {
return false;
}
const items = val.split('-');
if (items.length !== 2) {
return false;
}
return isNumber(items[0]) && isNumber(items[1]);
}
export function isEquals(obj1, obj2) {
if (obj1 === obj2) {
return true;
+24 -1
View File
@@ -298,7 +298,7 @@ export function getShiftedDateRange(minTime, maxTime, scale) {
};
}
export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDayOfWeek) {
export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDayOfWeek, scene) {
const newDateRange = getShiftedDateRange(minTime, maxTime, scale);
let newDateType = dateTimeConstants.allDateRanges.Custom.type;
@@ -308,6 +308,11 @@ export function getShiftedDateRangeAndDateType(minTime, maxTime, scale, firstDay
}
const dateRangeType = dateTimeConstants.allDateRanges[dateRangeField];
if (!dateRangeType.availableScenes[scene]) {
continue;
}
const dateRange = getDateRangeByDateType(dateRangeType.type, firstDayOfWeek);
if (dateRange && dateRange.minTime === newDateRange.minTime && dateRange.maxTime === newDateRange.maxTime) {
@@ -360,6 +365,24 @@ export function getDateRangeByDateType(dateType, firstDayOfWeek) {
} else if (dateType === dateTimeConstants.allDateRanges.LastYear.type) { // Last year
maxTime = getUnixTimeBeforeUnixTime(getThisYearLastUnixTime(), 1, 'years');
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 1, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwelveMonths.type) { // Recent 12 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 11, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwentyFourMonths.type) { // Recent 24 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 23, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentThirtySixMonths.type) { // Recent 36 months
maxTime = getThisMonthLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisMonthFirstUnixTime(), 35, 'months');
} else if (dateType === dateTimeConstants.allDateRanges.RecentTwoYears.type) { // Recent 2 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 1, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentThreeYears.type) { // Recent 3 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 2, 'years');
} else if (dateType === dateTimeConstants.allDateRanges.RecentFiveYears.type) { // Recent 5 years
maxTime = getThisYearLastUnixTime();
minTime = getUnixTimeBeforeUnixTime(getThisYearFirstUnixTime(), 4, 'years');
} else {
return null;
}
+6 -2
View File
@@ -655,7 +655,7 @@ function getAllWeekDays(translateFn) {
return allWeekDays;
}
function getAllDateRanges(includeCustom, translateFn) {
function getAllDateRanges(scene, includeCustom, translateFn) {
const allDateRanges = [];
for (let dateRangeField in datetime.allDateRanges) {
@@ -665,6 +665,10 @@ function getAllDateRanges(includeCustom, translateFn) {
const dateRangeType = datetime.allDateRanges[dateRangeField];
if (!dateRangeType.availableScenes[scene]) {
continue;
}
if (includeCustom || dateRangeType.type !== datetime.allDateRanges.Custom.type) {
allDateRanges.push({
type: dateRangeType.type,
@@ -1376,7 +1380,7 @@ export function i18nFunctions(i18nGlobal) {
getTimezoneDifferenceDisplayText: (utcOffset) => getTimezoneDifferenceDisplayText(utcOffset, i18nGlobal.t),
getAllCurrencies: () => getAllCurrencies(i18nGlobal.t),
getAllWeekDays: () => getAllWeekDays(i18nGlobal.t),
getAllDateRanges: (includeCustom) => getAllDateRanges(includeCustom, i18nGlobal.t),
getAllDateRanges: (scene, includeCustom) => getAllDateRanges(scene, includeCustom, i18nGlobal.t),
getAllRecentMonthDateRanges: (userStore, includeAll, includeCustom) => getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, i18nGlobal.t),
getDateRangeDisplayName: (userStore, dateType, startTime, endTime) => getDateRangeDisplayName(userStore, dateType, startTime, endTime, i18nGlobal.t),
getAllTimezoneTypesUsedForStatistics: (currentTimezone) => getAllTimezoneTypesUsedForStatistics(currentTimezone, i18nGlobal.t),
+18 -9
View File
@@ -22,13 +22,14 @@ const defaultSettings = {
showAccountBalance: true,
statistics: {
defaultChartDataType: statisticsConstants.defaultChartDataType,
defaultDataRangeType: statisticsConstants.defaultDataRangeType,
defaultTimezoneType: timezoneConstants.defaultTimezoneTypesUsedForStatistics,
defaultAccountFilter: {},
defaultTransactionCategoryFilter: {},
defaultSortingType: statisticsConstants.defaultSortingType,
defaultCategoricalChartType: statisticsConstants.defaultCategoricalChartType,
defaultCategoricalChartDataRangeType: statisticsConstants.defaultCategoricalChartDataRangeType,
defaultTrendChartType: statisticsConstants.defaultTrendChartType,
defaultTrendChartDataRangeType: statisticsConstants.defaultTrendChartDataRangeType,
},
animate: true
};
@@ -230,10 +231,6 @@ export function setStatisticsDefaultChartDataType(value) {
setSubOption('statistics', 'defaultChartDataType', value);
}
export function getStatisticsDefaultDateRange() {
return getSubOption('statistics', 'defaultDataRangeType');
}
export function getStatisticsDefaultTimezoneType() {
return getSubOption('statistics', 'defaultTimezoneType');
}
@@ -242,10 +239,6 @@ export function setStatisticsDefaultTimezoneType(value) {
setSubOption('statistics', 'defaultTimezoneType', value);
}
export function setStatisticsDefaultDateRange(value) {
setSubOption('statistics', 'defaultDataRangeType', value);
}
export function getStatisticsDefaultAccountFilter() {
return getSubOption('statistics', 'defaultAccountFilter');
}
@@ -278,6 +271,14 @@ export function setStatisticsDefaultCategoricalChartType(value) {
setSubOption('statistics', 'defaultCategoricalChartType', value);
}
export function getStatisticsDefaultCategoricalChartDataRange() {
return getSubOption('statistics', 'defaultCategoricalChartDataRangeType');
}
export function setStatisticsDefaultCategoricalChartDataRange(value) {
setSubOption('statistics', 'defaultCategoricalChartDataRangeType', value);
}
export function getStatisticsDefaultTrendChartType() {
return getSubOption('statistics', 'defaultTrendChartType');
}
@@ -286,6 +287,14 @@ export function setStatisticsDefaultTrendChartType(value) {
setSubOption('statistics', 'defaultTrendChartType', value);
}
export function getStatisticsDefaultTrendChartDataRange() {
return getSubOption('statistics', 'defaultTrendChartDataRangeType');
}
export function setStatisticsDefaultTrendChartDataRange(value) {
setSubOption('statistics', 'defaultTrendChartDataRangeType', value);
}
export function isEnableAnimate() {
return getOption('animate');
}