From 9938cc48c8559ebd1afe618dfdfdb007a79c34e9 Mon Sep 17 00:00:00 2001 From: Julia Friesel Date: Mon, 25 Jun 2018 11:04:51 +0200 Subject: [PATCH] Display cycle day number along with date --- components/chart.js | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/components/chart.js b/components/chart.js index ce9c443..e1d1f00 100644 --- a/components/chart.js +++ b/components/chart.js @@ -10,16 +10,20 @@ import Svg,{ } from 'react-native-svg' import { LocalDate } from 'js-joda' import { getCycleDay, getOrCreateCycleDay, cycleDaysSortedByDate } from '../db' +import getCycleDayNumberModule from '../get-cycle-day-number' -const right = 600 -const top = 10 -const bottom = 350 +const getCycleDayNumber = getCycleDayNumberModule() + +const chartLength = 350 const columnWidth = 30 const middle = columnWidth / 2 -const dateRow = { - height: 30, - width: right +const xAxis = { + top: chartLength - 15, + margin: 3 } +const dateRowY = xAxis.top - xAxis.margin +const cycleDayNumberRowY = chartLength - xAxis.margin + const temperatureScale = { low: 33, high: 40 @@ -53,24 +57,29 @@ export default class CycleChart extends Component { this.props.navigation.navigate('cycleDay', { cycleDay }) } - makeDayColumn({ label, cycleDay, y }, index) { + makeDayColumn({ dateString, cycleDay, y }, index) { + const cycleDayNumber = getCycleDayNumber(dateString) + const labelProps = { + stroke: "grey", + fontSize: "10", + x: 0, + } + + const dateLabel = dateString.split('-').slice(1).join('-') + return ( - this.passDateToDayView(label)}> + this.passDateToDayView(dateString)}> - {label.split('-')[2]} + {cycleDayNumber} + {dateLabel} {cycleDay && cycleDay.bleeding ? : null} @@ -127,7 +136,7 @@ export default class CycleChart extends Component { data={this.state.columns} renderItem={({item, index}) => { return ( - + {this.makeDayColumn(item, index)} ) @@ -148,11 +157,11 @@ function makeColumnInfo(n) { ).toString() }) - return xAxisDates.map(datestring => { - const cycleDay = getCycleDay(datestring) + return xAxisDates.map(dateString => { + const cycleDay = getCycleDay(dateString) const temp = cycleDay && cycleDay.temperature && cycleDay.temperature.value return { - label: datestring, + dateString, cycleDay, y: temp ? normalizeToScale(temp) : null } @@ -169,6 +178,6 @@ function getPreviousDays(n) { function normalizeToScale(temp) { const valueRelativeToScale = (temperatureScale.high - temp) / (temperatureScale.high - temperatureScale.low) - const scaleHeight = bottom - top + const scaleHeight = chartLength return scaleHeight * valueRelativeToScale } \ No newline at end of file