import React, { Component } from 'react' import Svg,{ G, Rect, Text, Circle, Line, Path } from 'react-native-svg' import styles from './styles' import config from './config' import { getOrCreateCycleDay } from '../../db' import cycleModule from '../../lib/cycle' import setUpFertilityStatusFunc from './nfp-lines' import { horizontalGrid } from './y-axis' import slowlog from 'react-native-slowlog' const getCycleDayNumber = cycleModule().getCycleDayNumber const label = styles.column.label export default class DayColumn extends Component { constructor(props) { super(props) this.getFhmAndLtlInfo = setUpFertilityStatusFunc() // slowlog(this, /.*/) } makeDayColumn(data, index) { const { dateString, y, temperature, temperatureExclude, bleeding, mucus } = data const cycleDayNumber = getCycleDayNumber(dateString) const dateLabel = dateString.split('-').slice(1).join('-') // const nfpLineInfo = this.getFhmAndLtlInfo(dateString, temperature) const nfpLineInfo = {} return ( this.passDateToDayView(dateString)}> {horizontalGrid} {nfpLineInfo.drawFhmLine ? : null} {cycleDayNumber} {dateLabel} {bleeding ? : null} {nfpLineInfo.drawLtlAt ? : null} {y ? this.drawDotAndLines(y, temperatureExclude, index) : null } {mucus ? : null} {y ? this.drawDotAndLines(y, temperatureExclude) : null} ) } drawDotAndLines(currY, exclude) { let lineToRight let lineToLeft function makeLine(otherColY, x, excludeLine) { const middleY = ((otherColY - currY) / 2) + currY const target = [x, middleY] const lineStyle = excludeLine ? styles.curveExcluded : styles.curve return } if (this.props.rightY) { const excludedLine = this.props.rightTemperatureExclude || exclude lineToRight = makeLine(this.props.rightY, config.columnWidth, excludedLine) } if (this.props.leftY) { const excludedLine = this.props.leftTemperatureExclude || exclude lineToLeft = makeLine(this.props.leftY, 0, excludedLine) } const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots return ( {lineToRight} {lineToLeft} ) } passDateToDayView(dateString) { const cycleDay = getOrCreateCycleDay(dateString) this.props.navigate('cycleDay', { cycleDay }) } shouldComponentUpdate(newProps) { return Object.keys(newProps).some(key => newProps[key] != this.props[key]) } render() { return ( {this.makeDayColumn(this.props.item, this.props.index)} ) } }