2024-10-17 11:57:38 +00:00
|
|
|
import QtQml 2.15
|
2022-10-28 17:17:16 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
2024-10-17 11:57:38 +00:00
|
|
|
QtObject {
|
2022-10-28 17:17:16 +00:00
|
|
|
id: root
|
|
|
|
|
|
|
|
// @see src/app_service/service/token/async_tasks.nim BalanceHistoryTimeInterval
|
|
|
|
enum TimeRange {
|
|
|
|
Weekly = 0,
|
|
|
|
Monthly,
|
|
|
|
HalfYearly,
|
|
|
|
Yearly,
|
|
|
|
All
|
|
|
|
}
|
|
|
|
|
|
|
|
readonly property var timeRangeTabsModel: [
|
2024-10-17 12:41:42 +00:00
|
|
|
{text: qsTr("7D"), enabled: true, timeRange: ChartDataBase.TimeRange.Weekly, timeIndex: 0},
|
|
|
|
{text: qsTr("1M"), enabled: true, timeRange: ChartDataBase.TimeRange.Monthly, timeIndex: 1},
|
|
|
|
{text: qsTr("6M"), enabled: true, timeRange: ChartDataBase.TimeRange.HalfYearly, timeIndex: 2},
|
|
|
|
{text: qsTr("1Y"), enabled: true, timeRange: ChartDataBase.TimeRange.Yearly, timeIndex: 3},
|
|
|
|
{text: qsTr("ALL"), enabled: true, timeRange: ChartDataBase.TimeRange.All, timeIndex: 4}]
|
2022-10-28 17:17:16 +00:00
|
|
|
|
|
|
|
property var weeklyData: []
|
|
|
|
property var monthlyData: []
|
|
|
|
property var halfYearlyData: []
|
|
|
|
property var yearlyData: []
|
|
|
|
property var allData: []
|
|
|
|
|
|
|
|
property var weeklyTimeRange: []
|
|
|
|
property var monthlyTimeRange: []
|
|
|
|
property var halfYearlyTimeRange: []
|
|
|
|
property var yearlyTimeRange: []
|
|
|
|
property var allTimeRange: []
|
|
|
|
|
|
|
|
property int monthlyMaxTicks: monthlyTimeRange.length/d.hoursInADay
|
|
|
|
property int weeklyMaxTicks: weeklyTimeRange.length/d.hoursInADay
|
|
|
|
property int halfYearlyMaxTicks: halfYearlyTimeRange.length/d.avgLengthOfMonth
|
|
|
|
property int yearlyMaxTicks: yearlyTimeRange.length/d.avgLengthOfMonth
|
|
|
|
property int allTimeRangeTicks: 0
|
|
|
|
|
|
|
|
// BEWARE that timeRange, dataRange and maxTicks properties are coupled with the timeRangeTabsModel order through
|
|
|
|
// indexing. See StatusChartPanel.timeRangeTabBarIndex
|
|
|
|
readonly property var timeRange: [
|
|
|
|
{'7D': weeklyTimeRange},
|
|
|
|
{'1M': monthlyTimeRange},
|
|
|
|
{'6M': halfYearlyTimeRange},
|
|
|
|
{'1Y': yearlyTimeRange},
|
|
|
|
{'ALL': allTimeRange}
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var dataRange: [
|
|
|
|
{'7D': weeklyData},
|
|
|
|
{'1M': monthlyData},
|
|
|
|
{'6M': halfYearlyData},
|
|
|
|
{'1Y': yearlyData},
|
|
|
|
{'ALL': allData}
|
|
|
|
]
|
|
|
|
|
|
|
|
readonly property var maxTicks: [
|
|
|
|
{'7D': weeklyMaxTicks},
|
|
|
|
{'1M': monthlyMaxTicks},
|
|
|
|
{'6M': halfYearlyMaxTicks},
|
|
|
|
{'1Y': yearlyMaxTicks},
|
|
|
|
{'ALL': allTimeRangeTicks}
|
|
|
|
]
|
|
|
|
|
|
|
|
/// \timeRange is the time range of the data that was updated
|
2022-11-15 21:48:59 +00:00
|
|
|
signal newDataReady(string address, string tokenSymbol, string currencySymbol, int timeRange)
|
2022-10-28 17:17:16 +00:00
|
|
|
|
|
|
|
function timeRangeEnumToStr(enumVal) {
|
2022-11-15 21:48:59 +00:00
|
|
|
return d.timeRangeEnumToPropertiesMap.get(enumVal).text
|
|
|
|
}
|
|
|
|
function timeRangeEnumToTimeIndex(enumVal) {
|
|
|
|
return d.timeRangeEnumToPropertiesMap.get(enumVal).timeIndex
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
function timeRangeStrToEnum(str) {
|
|
|
|
return d.timeRangeStrToEnumMap.get(str)
|
|
|
|
}
|
|
|
|
|
2024-10-17 11:57:38 +00:00
|
|
|
readonly property QtObject _d: QtObject {
|
2022-10-28 17:17:16 +00:00
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int hoursInADay: 24
|
|
|
|
readonly property int avgLengthOfMonth: 30
|
2022-11-15 21:48:59 +00:00
|
|
|
property var timeRangeEnumToPropertiesMap: null
|
2022-10-28 17:17:16 +00:00
|
|
|
property var timeRangeStrToEnumMap: null
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2022-11-15 21:48:59 +00:00
|
|
|
if(d.timeRangeEnumToPropertiesMap === null) {
|
|
|
|
d.timeRangeEnumToPropertiesMap = new Map()
|
2022-10-28 17:17:16 +00:00
|
|
|
for (const x of timeRangeTabsModel) {
|
2022-11-15 21:48:59 +00:00
|
|
|
d.timeRangeEnumToPropertiesMap.set(x.timeRange, x)
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
d.timeRangeStrToEnumMap = new Map()
|
2022-11-15 21:48:59 +00:00
|
|
|
for (const x of d.timeRangeEnumToPropertiesMap.entries()) {
|
2022-10-28 17:17:16 +00:00
|
|
|
let key = x[0]
|
|
|
|
let val = x[1]
|
2022-11-15 21:48:59 +00:00
|
|
|
d.timeRangeStrToEnumMap.set(val.text, key)
|
2022-10-28 17:17:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-10-17 11:57:38 +00:00
|
|
|
}
|