diff --git a/chart.js b/chart.js index d87669e..0199b96 100644 --- a/chart.js +++ b/chart.js @@ -1,6 +1,6 @@ import React, { Component } from 'react' import { ScrollView } from 'react-native' -import { temperatureDaysSortedByDate } from './db' +import { temperatureDaysSortedByDate, getOrCreateCycleDay } from './db' import range from 'date-range' import Svg,{ G, @@ -19,27 +19,6 @@ const dateRow = { width: right } -function makeDayColumn(labelInfo) { - return ( - - - {labelInfo.label.split('-')[2]} - - ) -} function getPreviousDays(n) { const today = new Date() @@ -63,9 +42,10 @@ const xAxisDatesWithRightOffset = xAxisDates.map((datestring, columnIndex) => { } }) -function determineCurvePoints(temperatureDaysSortedByDate, xAxisDatesWithRightOffset) { +function determineCurvePoints() { return temperatureDaysSortedByDate.map(cycleDay => { - const x = xAxisDatesWithRightOffset.find(tick => tick.label === cycleDay.date).rightOffset + const match = xAxisDatesWithRightOffset.find(tick => tick.label === cycleDay.date) + const x = match.rightOffset + columnWidth / 2 const y = normalizeToScale(cycleDay.temperature.value) return [x,y].join() }).join(' ') @@ -81,7 +61,40 @@ function normalizeToScale(temp) { return scaleHeight * tempInScaleDecs } + export default class SvgExample extends Component { + constructor(props) { + super(props) + } + + passDateToDayView(dateString) { + const cycleDay = getOrCreateCycleDay(dateString) + this.props.navigation.navigate('cycleDay', { cycleDay }) + } + + makeDayColumn(labelInfo) { + return ( + + this.passDateToDayView(labelInfo.label)} + /> + {labelInfo.label.split('-')[2]} + + ) + } + render() { return ( @@ -89,9 +102,9 @@ export default class SvgExample extends Component { height="350" width="2000" > - {xAxisDatesWithRightOffset.map(makeDayColumn)} + { xAxisDatesWithRightOffset.map(this.makeDayColumn.bind(this)) }