every symptom has its own row
This commit is contained in:
@@ -28,7 +28,6 @@ export default class CycleChart extends Component {
|
|||||||
|
|
||||||
onLayout = ({ nativeEvent }) => {
|
onLayout = ({ nativeEvent }) => {
|
||||||
if (this.state.chartHeight) return
|
if (this.state.chartHeight) return
|
||||||
|
|
||||||
const height = nativeEvent.layout.height
|
const height = nativeEvent.layout.height
|
||||||
this.setState({ chartHeight: height })
|
this.setState({ chartHeight: height })
|
||||||
this.reCalculateChartInfo = () => {
|
this.reCalculateChartInfo = () => {
|
||||||
@@ -61,11 +60,38 @@ export default class CycleChart extends Component {
|
|||||||
jsDate.getDate()
|
jsDate.getDate()
|
||||||
).toString()
|
).toString()
|
||||||
})
|
})
|
||||||
|
const chartSymptoms = [
|
||||||
|
'bleeding',
|
||||||
|
'temperature',
|
||||||
|
'mucus',
|
||||||
|
'cervix',
|
||||||
|
'sex',
|
||||||
|
'desire',
|
||||||
|
'pain',
|
||||||
|
'note'
|
||||||
|
].filter((symptomName) => {
|
||||||
|
return cycleDaysSortedByDate.some(cycleDay => cycleDay[symptomName])
|
||||||
|
})
|
||||||
|
|
||||||
const columns = xAxisDates.map(dateString => {
|
const columns = xAxisDates.map(dateString => {
|
||||||
const cycleDay = getCycleDay(dateString)
|
const cycleDay = getCycleDay(dateString)
|
||||||
const symptoms = ['temperature', 'mucus', 'bleeding'].reduce((acc, symptom) => {
|
const symptoms = chartSymptoms.reduce((acc, symptom) => {
|
||||||
|
if (symptom === 'bleeding' ||
|
||||||
|
symptom === 'temperature' ||
|
||||||
|
symptom === 'mucus' ||
|
||||||
|
symptom === 'desire' ||
|
||||||
|
symptom === 'note'
|
||||||
|
) {
|
||||||
acc[symptom] = cycleDay && cycleDay[symptom] && cycleDay[symptom].value
|
acc[symptom] = cycleDay && cycleDay[symptom] && cycleDay[symptom].value
|
||||||
|
} else if (symptom === 'cervix') {
|
||||||
|
acc[symptom] = cycleDay && cycleDay['cervix'] && (cycleDay['cervix'].opening + cycleDay['cervix'].firmness)
|
||||||
|
} else if (symptom === 'sex') {
|
||||||
|
// solo = 1 + partner = 2
|
||||||
|
acc[symptom] = cycleDay && cycleDay['sex'] && (cycleDay['sex'].solo + cycleDay['sex'].partner)
|
||||||
|
} else if (symptom === 'pain') {
|
||||||
|
// is any pain documented?
|
||||||
|
acc[symptom] = cycleDay && cycleDay['pain'] && Object.values(cycleDay['pain']).some(x => x === true)
|
||||||
|
}
|
||||||
acc[`${symptom}Exclude`] = cycleDay && cycleDay[symptom] && cycleDay[symptom].exclude
|
acc[`${symptom}Exclude`] = cycleDay && cycleDay[symptom] && cycleDay[symptom].exclude
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
@@ -75,7 +101,7 @@ export default class CycleChart extends Component {
|
|||||||
return {
|
return {
|
||||||
dateString,
|
dateString,
|
||||||
y: temp ? normalizeToScale(temp, columnHeight) : null,
|
y: temp ? normalizeToScale(temp, columnHeight) : null,
|
||||||
...symptoms,
|
symptoms,
|
||||||
...getFhmAndLtlInfo(dateString, temp)
|
...getFhmAndLtlInfo(dateString, temp)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ export default class DayColumn extends Component {
|
|||||||
dateString,
|
dateString,
|
||||||
y,
|
y,
|
||||||
temperatureExclude,
|
temperatureExclude,
|
||||||
bleeding,
|
symptoms,
|
||||||
mucus,
|
|
||||||
drawFhmLine,
|
drawFhmLine,
|
||||||
drawLtlAt,
|
drawLtlAt,
|
||||||
rightY,
|
rightY,
|
||||||
@@ -108,24 +107,73 @@ export default class DayColumn extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<View style={[styles.symptomRow, {height: symptomHeight}]}>
|
<View height={symptomHeight}>
|
||||||
{typeof mucus === 'number' &&
|
<View style={styles.symptomRow}>
|
||||||
<View
|
{typeof symptoms.bleeding === 'number' &&
|
||||||
{...styles.mucusIcon}
|
|
||||||
backgroundColor={styles.mucusIconShades[mucus]}
|
|
||||||
key='mucus'
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
{typeof bleeding === 'number' &&
|
|
||||||
<Icon
|
<Icon
|
||||||
name='drop'
|
name='drop'
|
||||||
size={18}
|
size={12}
|
||||||
color={styles.bleedingIconShades[bleeding]}
|
color={styles.bleedingIconShades[symptoms.bleeding]}
|
||||||
key='bleeding'
|
key='bleeding'
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{typeof symptoms.mucus === 'number' &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
backgroundColor={styles.mucusIconShades[symptoms.mucus]}
|
||||||
|
key='mucus'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{typeof symptoms.cervix === 'number' &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
// cervix is sum of openess and firmness - fertile only when closed and hard (=0)
|
||||||
|
backgroundColor={symptoms.cervix > 0 ? 'blue' : 'green'}
|
||||||
|
key='cervix'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{typeof symptoms.sex === 'number' &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
backgroundColor={styles.mucusIconShades[symptoms.mucus]}
|
||||||
|
key='sex'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{typeof symptoms.desire === 'number' &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
backgroundColor='red'
|
||||||
|
key='desire'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{symptoms.pain &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
backgroundColor='blue'
|
||||||
|
key='pain'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
<View style={styles.symptomRow}>
|
||||||
|
{symptoms.note &&
|
||||||
|
<View
|
||||||
|
{...styles.mucusIcon}
|
||||||
|
backgroundColor='green'
|
||||||
|
key='note'
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
{column}
|
{column}
|
||||||
|
|
||||||
<View style={{height: xAxisHeight}}>
|
<View style={{height: xAxisHeight}}>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export default class DotAndLine extends Component {
|
|||||||
|
|
||||||
function makeLine(leftY, rightY, direction, excludeLine) {
|
function makeLine(leftY, rightY, direction, excludeLine) {
|
||||||
const colWidth = config.columnWidth
|
const colWidth = config.columnWidth
|
||||||
const heightDiff = -leftY - -rightY
|
const heightDiff = -(leftY - rightY)
|
||||||
const angle = Math.atan2(heightDiff, colWidth / 2)
|
const angle = Math.atan2(heightDiff, colWidth / 2)
|
||||||
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
|
const lineStyle = excludeLine ? styles.curveExcluded : styles.curve
|
||||||
// hypotenuse, we add 3px for good measure, because otherwise the lines
|
// hypotenuse, we add 3px for good measure, because otherwise the lines
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ const styles = {
|
|||||||
rect: {
|
rect: {
|
||||||
width: config.columnWidth,
|
width: config.columnWidth,
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
borderLeftWidth: 0.5,
|
borderRightWidth: 0.25,
|
||||||
borderRightWidth: 0.5,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bleedingIcon: {
|
bleedingIcon: {
|
||||||
@@ -85,7 +84,7 @@ const styles = {
|
|||||||
horizontalGrid: {
|
horizontalGrid: {
|
||||||
position:'absolute',
|
position:'absolute',
|
||||||
borderColor: 'lightgrey',
|
borderColor: 'lightgrey',
|
||||||
borderWidth: 0.5,
|
borderTopWidth: 0.25,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
left: config.columnWidth
|
left: config.columnWidth
|
||||||
@@ -97,7 +96,9 @@ const styles = {
|
|||||||
},
|
},
|
||||||
symptomRow: {
|
symptomRow: {
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center'
|
justifyContent: 'center',
|
||||||
|
width: '100%',
|
||||||
|
flex: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,34 +2,20 @@ import React from 'react'
|
|||||||
import { Text, View } from 'react-native'
|
import { Text, View } from 'react-native'
|
||||||
import config from '../../config'
|
import config from '../../config'
|
||||||
import styles from './styles'
|
import styles from './styles'
|
||||||
import { scaleObservable } from '../../local-storage'
|
import { scaleObservable, unitObservable } from '../../local-storage'
|
||||||
|
|
||||||
export function makeYAxisLabels(columnHeight) {
|
export function makeYAxisLabels(columnHeight) {
|
||||||
const units = config.temperatureScale.units
|
const units = unitObservable.value
|
||||||
const scaleMax = scaleObservable.value.max
|
const scaleMax = scaleObservable.value.max
|
||||||
const scaleMin = scaleObservable.value.min
|
|
||||||
const style = styles.yAxisLabel
|
const style = styles.yAxisLabel
|
||||||
|
|
||||||
return getTickPositions(columnHeight).map((y, i) => {
|
return getTickPositions(columnHeight).map((y, i) => {
|
||||||
// this eyeballing is sadly necessary because RN does not
|
// this eyeballing is sadly necessary because RN does not
|
||||||
// support percentage values for transforms, which we'd need
|
// support percentage values for transforms, which we'd need
|
||||||
// to reliably place the label vertically centered to the grid
|
// to reliably place the label vertically centered to the grid
|
||||||
let tickLabelDistance
|
const tick = scaleMax - i * units
|
||||||
let tickUnit
|
|
||||||
if (scaleMax - scaleMin <= 3) {
|
|
||||||
tickLabelDistance = 2
|
|
||||||
tickUnit = 1
|
|
||||||
} else if (scaleMax - scaleMin <= 5) {
|
|
||||||
tickLabelDistance = 2
|
|
||||||
tickUnit = 2
|
|
||||||
} else {
|
|
||||||
tickLabelDistance = 5
|
|
||||||
tickUnit = 5
|
|
||||||
}
|
|
||||||
if (scaleMax - i * tickUnit * units === 37) console.log(y)
|
|
||||||
const tick = scaleMax - i * tickUnit * units
|
|
||||||
const tickLabel = tick * 10 % 10 ? tick.toString() : tick.toString() + '.0'
|
const tickLabel = tick * 10 % 10 ? tick.toString() : tick.toString() + '.0'
|
||||||
const showTick = tick * 10 % tickLabelDistance ? false : true
|
const showTick = (tick * 10 % 2) ? false : true
|
||||||
const tickBold = tick * 10 % 5 ? {} : {fontWeight: 'bold'}
|
const tickBold = tick * 10 % 5 ? {} : {fontWeight: 'bold'}
|
||||||
return (
|
return (
|
||||||
<Text
|
<Text
|
||||||
@@ -54,19 +40,11 @@ export function makeHorizontalGrid(columnHeight, symptomRowHeight) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTickPositions(columnHeight) {
|
function getTickPositions(columnHeight) {
|
||||||
const units = config.temperatureScale.units
|
const units = unitObservable.value
|
||||||
const scaleMin = scaleObservable.value.min
|
const scaleMin = scaleObservable.value.min
|
||||||
const scaleMax = scaleObservable.value.max
|
const scaleMax = scaleObservable.value.max
|
||||||
const numberOfTicks = (scaleMax - scaleMin) * (1 / units) + 1
|
const numberOfTicks = (scaleMax - scaleMin) * (1 / units) + 1
|
||||||
let tickDistance
|
const tickDistance = 1 / (numberOfTicks - 1)
|
||||||
if (numberOfTicks <= 31) {
|
|
||||||
tickDistance = 1 / (numberOfTicks - 1)
|
|
||||||
} else if (numberOfTicks <= 51) {
|
|
||||||
tickDistance = 2 / (numberOfTicks - 1)
|
|
||||||
} else {
|
|
||||||
tickDistance = 5 / (numberOfTicks - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
const tickPositions = []
|
const tickPositions = []
|
||||||
for (let i = 0; i < numberOfTicks; i++) {
|
for (let i = 0; i < numberOfTicks; i++) {
|
||||||
const position = getAbsoluteValue(tickDistance * i, columnHeight)
|
const position = getAbsoluteValue(tickDistance * i, columnHeight)
|
||||||
@@ -86,5 +64,4 @@ function getAbsoluteValue(relative, columnHeight) {
|
|||||||
const verticalPadding = columnHeight * config.temperatureScale.verticalPadding
|
const verticalPadding = columnHeight * config.temperatureScale.verticalPadding
|
||||||
const scaleHeight = columnHeight - 2 * verticalPadding
|
const scaleHeight = columnHeight - 2 * verticalPadding
|
||||||
return scaleHeight * relative + verticalPadding
|
return scaleHeight * relative + verticalPadding
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
const config = {
|
const config = {
|
||||||
columnWidth: 25,
|
columnWidth: 25,
|
||||||
columnHeightPercentage: 0.84,
|
columnHeightPercentage: 0.62,
|
||||||
xAxisHeightPercentage: 0.08,
|
xAxisHeightPercentage: 0.08,
|
||||||
symptomRowHeightPercentage: 0.08,
|
symptomRowHeightPercentage: 0.30,
|
||||||
temperatureScale: {
|
temperatureScale: {
|
||||||
defaultLow: 35,
|
defaultLow: 35,
|
||||||
defaultHigh: 38,
|
defaultHigh: 38,
|
||||||
|
|||||||
@@ -8,6 +8,20 @@ setObvWithInitValue('tempScale', scaleObservable, {
|
|||||||
max: config.temperatureScale.defaultHigh
|
max: config.temperatureScale.defaultHigh
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const unitObservable = Observable()
|
||||||
|
unitObservable.set(config.temperatureScale.units)
|
||||||
|
scaleObservable((scale) => {
|
||||||
|
const scaleRange = scale.max - scale.min
|
||||||
|
if (scaleRange <= 3) {
|
||||||
|
unitObservable.set(0.1)
|
||||||
|
} else if (scaleRange <= 5) {
|
||||||
|
unitObservable.set(0.2)
|
||||||
|
} else {
|
||||||
|
unitObservable.set(0.5)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
export const tempReminderObservable = Observable()
|
export const tempReminderObservable = Observable()
|
||||||
setObvWithInitValue('tempReminder', tempReminderObservable, {
|
setObvWithInitValue('tempReminder', tempReminderObservable, {
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
Reference in New Issue
Block a user