Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add chart date type settings for trend analysis
Browse files Browse the repository at this point in the history
mayswind committed May 26, 2024
1 parent 5eca777 commit e90cb69
Showing 16 changed files with 439 additions and 183 deletions.
112 changes: 99 additions & 13 deletions src/consts/datetime.js
Original file line number Diff line number Diff line change
@@ -166,54 +166,139 @@ const allShortTimeFormatArray = [
allShortTimeFormat.HHMMA
];

const allDateRangeScenes = {
Normal: 0,
TrendAnalysis: 1
};

const allDateRanges = {
All: {
type: 0,
name: 'All'
name: 'All',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
},
Today: {
type: 1,
name: 'Today'
name: 'Today',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
Yesterday: {
type: 2,
name: 'Yesterday'
name: 'Yesterday',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastSevenDays: {
type: 3,
name: 'Recent 7 days'
name: 'Recent 7 days',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastThirtyDays: {
type: 4,
name: 'Recent 30 days'
name: 'Recent 30 days',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisWeek: {
type: 5,
name: 'This week'
name: 'This week',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastWeek: {
type: 6,
name: 'Last week'
name: 'Last week',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisMonth: {
type: 7,
name: 'This month'
name: 'This month',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastMonth: {
type: 8,
name: 'Last month'
name: 'Last month',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
ThisYear: {
type: 9,
name: 'This year'
name: 'This year',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
LastYear: {
type: 10,
name: 'Last year'
name: 'Last year',
availableScenes: {
[allDateRangeScenes.Normal]: true
}
},
RecentTwelveMonths: {
type: 101,
name: 'Recent 12 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentTwentyFourMonths: {
type: 102,
name: 'Recent 24 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentThirtySixMonths: {
type: 103,
name: 'Recent 36 months',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentTwoYears: {
type: 104,
name: 'Recent 2 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentThreeYears: {
type: 105,
name: 'Recent 3 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
RecentFiveYears: {
type: 106,
name: 'Recent 5 years',
availableScenes: {
[allDateRangeScenes.TrendAnalysis]: true
}
},
Custom: {
type: 11,
name: 'Custom Date'
type: 255,
name: 'Custom Date',
availableScenes: {
[allDateRangeScenes.Normal]: true,
[allDateRangeScenes.TrendAnalysis]: true
}
}
};

@@ -238,6 +323,7 @@ export default {
allLongTimeFormatArray: allLongTimeFormatArray,
allShortTimeFormat: allShortTimeFormat,
allShortTimeFormatArray: allShortTimeFormatArray,
allDateRangeScenes: allDateRangeScenes,
allDateRanges: allDateRanges,
defaultFirstDayOfWeek: defaultFirstDayOfWeek,
defaultLongDateFormat: defaultLongDateFormat,
3 changes: 2 additions & 1 deletion src/consts/statistics.js
Original file line number Diff line number Diff line change
@@ -144,7 +144,8 @@ export default {
defaultTrendChartType: defaultTrendChartType,
allChartDataTypes: allChartDataTypes,
defaultChartDataType: defaultChartDataType,
defaultDataRangeType: datetime.allDateRanges.ThisMonth.type,
defaultCategoricalChartDataRangeType: datetime.allDateRanges.ThisMonth.type,
defaultTrendChartDataRangeType: datetime.allDateRanges.RecentTwelveMonths.type,
allSortingTypes: allSortingTypes,
allSortingTypesArray: allSortingTypesArray,
defaultSortingType: defaultSortingType,
14 changes: 14 additions & 0 deletions src/lib/common.js
Original file line number Diff line number Diff line change
@@ -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;
25 changes: 24 additions & 1 deletion src/lib/datetime.js
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 6 additions & 2 deletions src/lib/i18n.js
Original file line number Diff line number Diff line change
@@ -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),
27 changes: 18 additions & 9 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
@@ -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');
}
6 changes: 6 additions & 0 deletions src/locales/en.js
Original file line number Diff line number Diff line change
@@ -759,6 +759,12 @@ export default {
'Last month': 'Last month',
'This year': 'This year',
'Last year': 'Last year',
'Recent 12 months': 'Recent 12 months',
'Recent 24 months': 'Recent 24 months',
'Recent 36 months': 'Recent 36 months',
'Recent 2 years': 'Recent 2 years',
'Recent 3 years': 'Recent 3 years',
'Recent 5 years': 'Recent 5 years',
'Custom Date': 'Custom Date',
'Start Time': 'Start Time',
'End Time': 'End Time',
6 changes: 6 additions & 0 deletions src/locales/zh_Hans.js
Original file line number Diff line number Diff line change
@@ -759,6 +759,12 @@ export default {
'Last month': '上月',
'This year': '今年',
'Last year': '去年',
'Recent 12 months': '最近12个月',
'Recent 24 months': '最近24个月',
'Recent 36 months': '最近36个月',
'Recent 2 years': '最近2年',
'Recent 3 years': '最近3年',
'Recent 5 years': '最近5年',
'Custom Date': '自定义日期',
'Start Time': '开始时间',
'End Time': '结束时间',
Loading

0 comments on commit e90cb69

Please sign in to comment.