diff --git a/components/chart/chart.js b/components/chart/chart.js index 03702c0..9598552 100644 --- a/components/chart/chart.js +++ b/components/chart/chart.js @@ -1,6 +1,5 @@ import React, { Component } from 'react' import { View, FlatList, ActivityIndicator } from 'react-native' -import { LocalDate } from 'js-joda' import AppLoadingView from '../app-loading' import YAxis from './y-axis' @@ -8,9 +7,10 @@ import nfpLines from './nfp-lines' import DayColumn from './day-column' import HorizontalGrid from './horizontal-grid' -import { getCycleDaysSortedByDate, getAmountOfCycleDays } from '../../db' +import { getCycleDaysSortedByDate } from '../../db' import nothingChanged from '../../db/db-unchanged' import { scaleObservable } from '../../local-storage' +import { makeColumnInfo } from '../helpers/chart' import config from '../../config' @@ -71,7 +71,7 @@ export default class CycleChart extends Component { this.chartSymptoms.push('temperature') } - const columnData = this.makeColumnInfo() + const columnData = makeColumnInfo() this.setState({ columns: columnData, chartHeight: height @@ -103,19 +103,6 @@ export default class CycleChart extends Component { this.removeObvListener() } - 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()) - } - render() { const { chartHeight, chartLoaded } = this.state return ( @@ -169,20 +156,3 @@ function LoadingMoreView(props) { ) } - -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, []) -} diff --git a/components/helpers/chart.js b/components/helpers/chart.js index 5e9926b..d59a55a 100644 --- a/components/helpers/chart.js +++ b/components/helpers/chart.js @@ -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, []) +} \ No newline at end of file