diff --git a/components/chart/day-column.js b/components/chart/day-column.js
index 834a618..4236c41 100644
--- a/components/chart/day-column.js
+++ b/components/chart/day-column.js
@@ -26,40 +26,55 @@ const label = styles.column.label
class DayColumn extends Component {
constructor(props) {
super()
- const dateString = props.dateString
- const columnHeight = props.columnHeight
- this.getCycleDayNumber = cycleModule().getCycleDayNumber
- const cycleDay = getCycleDay(dateString)
+
+ const { dateString, columnHeight, chartSymptoms } = props
+ const cycleDayData = getCycleDay(dateString)
this.data = {}
- if (cycleDay) {
- this.data = props.chartSymptoms.reduce((acc, symptom) => {
- if (['bleeding', 'temperature', 'mucus', 'desire', 'note'].includes(symptom)) {
- acc[symptom] = cycleDay[symptom] && cycleDay[symptom].value
- if (symptom === 'temperature' && acc.temperature) {
- acc.y = normalizeToScale(acc.temperature, columnHeight)
- const neighbor = getInfoForNeighborColumns(dateString, columnHeight)
- for (const key in neighbor) {
- acc[key] = neighbor[key]
+
+ if (cycleDayData) {
+ this.data = chartSymptoms.reduce((symptomDataToDisplay, symptom) => {
+ const symptomData = cycleDayData[symptom]
+
+ if (symptomData && !this.isSymptomExcluded(symptomData)) {
+ symptomDataToDisplay[symptom] = {}
+ switch (symptom) {
+ case 'temperature': {
+ symptomDataToDisplay[symptom].data = symptomData.value
+ symptomDataToDisplay.y =
+ normalizeToScale(symptomData.value, columnHeight)
+ const neighbourTemperatureValue =
+ getInfoForNeighborColumns(dateString, columnHeight)
+ for (const key in neighbourTemperatureValue) {
+ symptomDataToDisplay[key] = neighbourTemperatureValue[key]
}
+ break
+ }
+ case 'cervix':
+ symptomDataToDisplay[symptom].data =
+ (symptomData.opening + symptomData.firmness) > 0 ? 2 : 0
+ symptomDataToDisplay[symptom].isComplete =
+ this.isCervixDataComplete(symptomData)
+ break
+ case 'mucus':
+ symptomDataToDisplay[symptom].data =
+ (symptomData.feeling + symptomData.texture) > 0 ? 2 : 0
+ symptomDataToDisplay[symptom].isComplete =
+ this.isMucusDataComplete(symptomData)
+ break
+ case 'sex':
+ symptomDataToDisplay[symptom].data =
+ symptomData.solo + 2 * symptomData.partner - 1
+ break
+ case 'bleeding':
+ case 'desire':
+ symptomDataToDisplay[symptom].data = symptomData.value
+ break
+ default: // pain, mood, note
+ symptomDataToDisplay[symptom].data = 0
}
- } else if (symptom === 'cervix') {
- acc.cervix = cycleDay.cervix &&
- (cycleDay.cervix.opening + cycleDay.cervix.firmness)
- } else if (symptom === 'sex') {
- // solo = 1 + partner = 2
- acc.sex = cycleDay.sex &&
- (cycleDay.sex.solo + 2 * cycleDay.sex.partner)
- } else if (symptom === 'pain') {
- // is any pain documented?
- acc.pain = cycleDay.pain &&
- Object.values({...cycleDay.pain}).some(x => x === true)
- } else if (symptom === 'mood') {
- // is mood documented?
- acc.mood = cycleDay.mood &&
- Object.values({...cycleDay.mood}).some(x => x === true)
}
- acc[`${symptom}Exclude`] = cycleDay[symptom] && cycleDay[symptom].exclude
- return acc
+
+ return symptomDataToDisplay
}, this.data)
}
@@ -70,6 +85,16 @@ class DayColumn extends Component {
)
}
+ isSymptomExcluded = (symptomData) => {
+ return symptomData && symptomData.exclude ? symptomData.exclude : false
+ }
+
+ isCervixDataComplete = (symptomData) =>
+ (symptomData.opening != null) && (symptomData.firmness != null)
+
+ isMucusDataComplete = (symptomData) =>
+ (symptomData.feeling != null) && (symptomData.texture != null)
+
onDaySelect = (date) => {
this.props.setDate(date)
this.props.navigate('CycleDay')
@@ -79,10 +104,50 @@ class DayColumn extends Component {
return false
}
+ drawSypmtom = (symptom) => {
+
+ const { symptomHeight } = this.props
+ const shouldDrawSymptom = this.data.hasOwnProperty(symptom)
+ const styleParent = [styles.symptomRow, {height: symptomHeight}]
+
+ if (shouldDrawSymptom) {
+ const styleSymptom = styles.iconShades[symptom]
+ const symptomData = this.data[symptom]
+
+ const isDataIncomplete = !symptomData.isComplete
+ const isMucusOrCervix = (symptom === 'mucus') || (symptom === 'cervix')
+
+ const backgroundColor = ( isMucusOrCervix && isDataIncomplete) ?
+ 'white' : styleSymptom[symptomData.data]
+ const borderWidth = ( isMucusOrCervix && isDataIncomplete) ? 2 : 0
+ const borderColor = styleSymptom[0]
+
+ const styleChild = [styles.symptomIcon, {
+ backgroundColor,
+ borderColor,
+ borderWidth
+ }]
+
+ return (
+
+ {shouldDrawSymptom && }
+
+ )
+ } else {
+ return (
+
+ )
+ }
+ }
+
render() {
const columnElements = []
- const dateString = this.props.dateString
- const symptomHeight = this.props.symptomHeight
+ const { dateString,
+ symptomRowSymptoms,
+ chartHeight,
+ columnHeight,
+ xAxisHeight } = this.props
+
if(this.fhmAndLtl.drawLtlAt) {
const ltlLine = ()
columnElements.push(fhmLine)
}
-
if (this.data.y) {
columnElements.push(
{cycleDayNumber ? cycleDayNumber : ' '}
@@ -149,131 +211,26 @@ class DayColumn extends Component {
{ columnElements }
)
- const symptomIconViews = {
- bleeding: (
-
-
-
- ),
- mucus: (
-
-
-
- ),
- cervix: (
-
- 0 ?
- styles.iconShades.cervix[2] :
- styles.iconShades.cervix[0]
- }
- />
-
- ),
- sex: (
-
-
-
- ),
- desire: (
-
-
-
- ),
- pain: (
-
-
-
- ),
- mood: (
-
-
-
- ),
- note: (
-
-
-
- )
- }
-
return (
this.onDaySelect(dateString)}
activeOpacity={1}
>
- {this.props.symptomRowSymptoms.map(symptomName => {
- return symptomIconViews[symptomName]
- })}
+ {symptomRowSymptoms.map(symptom => this.drawSypmtom(symptom))}
-
+
{column}
-
+
{cycleDayLabel}
{dateLabel}
@@ -294,18 +251,6 @@ export default connect(
)(DayColumn)
-
-function SymptomIconView(props) {
- const style = [styles.symptomRow, {height: props.symptomHeight}]
- return (
-
- {(typeof props.value === 'number' || props.value === true || typeof props.value === 'string') &&
- props.children
- }
-
- )
-}
-
function getInfoForNeighborColumns(dateString, columnHeight) {
const ret = {
rightY: null,