Move calculations functions to helpers file
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import { LocalDate } from 'js-joda'
|
||||
|
||||
import { scaleObservable, unitObservable } from '../../local-storage'
|
||||
import { getCycleDay } from '../../db'
|
||||
import { getCycleDay, getAmountOfCycleDays } from '../../db'
|
||||
|
||||
import config from '../../config'
|
||||
|
||||
//YAxis helpers
|
||||
|
||||
export function normalizeToScale(temp, columnHeight) {
|
||||
const scale = scaleObservable.value
|
||||
const valueRelativeToScale = (scale.max - temp) / (scale.max - scale.min)
|
||||
@@ -70,6 +72,8 @@ export function getTickList(columnHeight) {
|
||||
})
|
||||
}
|
||||
|
||||
//DayColumn helpers
|
||||
|
||||
export function isSymptomDataComplete(symptom, dateString) {
|
||||
const cycleDayData = getCycleDay(dateString)
|
||||
const symptomData = cycleDayData[symptom]
|
||||
@@ -162,3 +166,35 @@ export const symptomColorMethods = {
|
||||
return colorIndex
|
||||
}
|
||||
}
|
||||
|
||||
// Chart helpers
|
||||
|
||||
export function makeColumnInfo() {
|
||||
let amountOfCycleDays = getAmountOfCycleDays()
|
||||
// if there's not much data yet, we want to show at least 30 days on the chart
|
||||
if (amountOfCycleDays < 30) {
|
||||
amountOfCycleDays = 30
|
||||
} else {
|
||||
// we don't want the chart to end abruptly before the first data day
|
||||
amountOfCycleDays += 5
|
||||
}
|
||||
const localDates = getTodayAndPreviousDays(amountOfCycleDays)
|
||||
return localDates.map(localDate => localDate.toString())
|
||||
}
|
||||
|
||||
function getTodayAndPreviousDays(n) {
|
||||
const today = LocalDate.now()
|
||||
const targetDate = today.minusDays(n)
|
||||
|
||||
function getDaysInRange(currDate, range) {
|
||||
if (currDate.isBefore(targetDate)) {
|
||||
return range
|
||||
} else {
|
||||
range.push(currDate)
|
||||
const next = currDate.minusDays(1)
|
||||
return getDaysInRange(next, range)
|
||||
}
|
||||
}
|
||||
|
||||
return getDaysInRange(today, [])
|
||||
}
|
||||
Reference in New Issue
Block a user