182 lines
5.2 KiB
JavaScript
182 lines
5.2 KiB
JavaScript
import React, { Component } from 'react'
|
|
import {
|
|
Text, View, TouchableOpacity
|
|
} from 'react-native'
|
|
import Icon from 'react-native-vector-icons/Entypo'
|
|
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
|
|
const getFhmAndLtlInfo = setUpFertilityStatusFunc()
|
|
|
|
export default class DayColumn extends Component {
|
|
constructor(props) {
|
|
super(props)
|
|
//slowlog(this, /.*/, {threshold: 30})
|
|
}
|
|
makeDayColumn(data, index) {
|
|
const {
|
|
dateString,
|
|
y,
|
|
temperature,
|
|
temperatureExclude,
|
|
bleeding,
|
|
mucus
|
|
} = data
|
|
const cycleDayNumber = getCycleDayNumber(dateString)
|
|
const shortDate = dateString.split('-').slice(1).join('-')
|
|
const nfpLineInfo = getFhmAndLtlInfo(dateString, temperature)
|
|
|
|
//TODO move these so they are visible
|
|
const cycleDayLabel = (
|
|
<Text {...label.number} y={config.cycleDayNumberRowY}>
|
|
{cycleDayNumber}
|
|
</Text>)
|
|
const dateLabel = (
|
|
<Text {...label.date} y={config.dateRowY}>
|
|
{shortDate}
|
|
</Text>
|
|
)
|
|
const columnElements = []
|
|
if (bleeding) {
|
|
columnElements.push(
|
|
<Icon
|
|
name='drop'
|
|
position='absolute'
|
|
top = {10}
|
|
left = {20}
|
|
size={30}
|
|
color='#900'
|
|
style={{ marginTop: 20 }}
|
|
/>
|
|
)
|
|
}
|
|
columnElements.push(cycleDayLabel, dateLabel, horizontalGrid)
|
|
// {nfpLineInfo.drawFhmLine ?
|
|
// <Line
|
|
// x1={0 + styles.nfpLine.strokeWidth / 2}
|
|
// y1="20"
|
|
// x2={0 + styles.nfpLine.strokeWidth / 2}
|
|
// y2={config.chartHeight - 20}
|
|
// {...styles.nfpLine}
|
|
// /> : null}
|
|
// />)
|
|
|
|
// <Path {...styles.bleedingIcon}
|
|
// d="M15 3
|
|
// Q16.5 6.8 25 18
|
|
// A12.8 12.8 0 1 1 5 18
|
|
// Q13.5 6.8 15 3z" />
|
|
// : null}
|
|
|
|
// {nfpLineInfo.drawLtlAt ?
|
|
// <Line
|
|
// x1="0"
|
|
// y1={nfpLineInfo.drawLtlAt}
|
|
// x2={config.columnWidth}
|
|
// y2={nfpLineInfo.drawLtlAt}
|
|
// {...styles.nfpLine}
|
|
// /> : null}
|
|
|
|
if (y) {
|
|
columnElements.push(...this.drawDotAndLine(y, temperatureExclude, index))
|
|
}
|
|
// {cycleDay && cycleDay.mucus ?
|
|
// <Circle
|
|
// {...styles.mucusIcon}
|
|
// fill={styles.mucusIconShades[cycleDay.mucus.value]}
|
|
// /> : null}
|
|
|
|
// {y ?
|
|
// this.drawDotAndLines(y, cycleDay.temperature.exclude, index)
|
|
// : null} */}
|
|
|
|
return React.createElement(
|
|
TouchableOpacity,
|
|
{
|
|
style: styles.column.rect,
|
|
key: index.toString(),
|
|
onPress: () => {
|
|
this.passDateToDayView(dateString)
|
|
},
|
|
activeOpacity: 0.,
|
|
|
|
},
|
|
columnElements
|
|
)
|
|
}
|
|
|
|
drawDotAndLine(currY, exclude) {
|
|
let lineToRight
|
|
let lineToLeft
|
|
|
|
function makeLine(leftY, rightY, leftX, excludeLine) {
|
|
const heightDiff = leftY - rightY
|
|
const angle = Math.atan2(config.columnWidth, heightDiff)
|
|
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
|
|
// hypotenuse
|
|
const h = (config.columnWidth / 2) / Math.cos(angle)
|
|
const neededDiff = Math.sin(Math.PI - (angle + Math.PI / 2)) * (h / 2)
|
|
const projectedX = leftX - ((h / 2) - neededDiff)
|
|
console.log(leftX)
|
|
console.log(projectedX)
|
|
|
|
return (<View
|
|
width={h}
|
|
position = 'absolute'
|
|
top={(leftY + rightY) / 2}
|
|
left={projectedX}
|
|
style={{
|
|
// the rotation by default rotates from the middle of the line,
|
|
// but we want the transform origin to be at its beginning
|
|
// react native doesn't have transformOrigin, so we do this manually
|
|
transform: [
|
|
{rotateZ: `${angle}rad`}
|
|
],
|
|
}}
|
|
{...lineStyle}
|
|
/>)
|
|
}
|
|
|
|
if (this.props.leftY) {
|
|
const middleY = ((this.props.leftY - currY) / 2) + currY
|
|
const excludedLine = this.props.leftTemperatureExclude || exclude
|
|
lineToLeft = makeLine(middleY, currY, 0, excludedLine)
|
|
}
|
|
if (this.props.rightY) {
|
|
const middleY = ((currY - this.props.rightY) / 2) + this.props.rightY
|
|
const excludedLine = this.props.rightTemperatureExclude || exclude
|
|
lineToRight = makeLine(currY, middleY, config.columnMiddle, excludedLine)
|
|
}
|
|
|
|
const dotStyle = exclude ? styles.curveDotsExcluded : styles.curveDots
|
|
const dot = (
|
|
<View
|
|
position='absolute'
|
|
top={currY - (dotStyle.height / 2)}
|
|
left={config.columnMiddle - (dotStyle.width / 2)}
|
|
style={dotStyle}
|
|
/>
|
|
)
|
|
return [lineToLeft, lineToRight, dot]
|
|
}
|
|
|
|
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)
|
|
}
|
|
} |