diff --git a/components/chart/chart.js b/components/chart/chart.js index dd2c29b92fca45f1917ed3310976b53386ce074c..da19f2cf22c7af6c5eb2e07830a1a5335d027b45 100644 --- a/components/chart/chart.js +++ b/components/chart/chart.js @@ -7,7 +7,7 @@ import setUpFertilityStatusFunc from './nfp-lines' import DayColumn from './day-column' import { getCycleDay, cycleDaysSortedByDate, getAmountOfCycleDays } from '../../db' import styles from './styles' - +import { scaleObservable } from '../../local-storage' export default class CycleChart extends Component { constructor(props) { @@ -24,7 +24,6 @@ export default class CycleChart extends Component { /> ) } - this.yAxisView = <View {...styles.yAxis}>{makeYAxisLabels()}</View> this.reCalculateChartInfo = (function(Chart) { return function() { @@ -33,16 +32,18 @@ export default class CycleChart extends Component { })(this) cycleDaysSortedByDate.addListener(this.reCalculateChartInfo) + this.removeObvListener = scaleObservable(this.reCalculateChartInfo, false) } componentWillUnmount() { cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo) + this.removeObvListener() } render() { return ( <View style={{ flexDirection: 'row', marginTop: 50 }}> - {this.yAxisView} + <View {...styles.yAxis}>{makeYAxisLabels()}</View> {makeHorizontalGrid()} {<FlatList horizontal={true} diff --git a/components/chart/day-column.js b/components/chart/day-column.js index a8d15620c24b0425668fabd6cc82c13654c3e5a3..1b61a7aec5014f8bf025b34cbd543be0aaa10e6d 100644 --- a/components/chart/day-column.js +++ b/components/chart/day-column.js @@ -15,7 +15,7 @@ const label = styles.column.label export default class DayColumn extends Component { passDateToDayView(dateString) { const cycleDay = getOrCreateCycleDay(dateString) - this.props.navigate('cycleDay', { cycleDay }) + this.props.navigate('CycleDay', { cycleDay }) } shouldComponentUpdate(newProps) { diff --git a/components/chart/y-axis.js b/components/chart/y-axis.js index 61f0c2d8ffce71f19ad986dfd900d10b63c5eff4..5b78b3683f6ce216b83af173630980810a09f4d4 100644 --- a/components/chart/y-axis.js +++ b/components/chart/y-axis.js @@ -2,11 +2,11 @@ import React from 'react' import { Text, View } from 'react-native' import config from '../../config' import styles from './styles' -import { tempScaleObservable } from '../../local-storage' +import { scaleObservable } from '../../local-storage' export function makeYAxisLabels() { const units = config.temperatureScale.units - const scaleMax = tempScaleObservable.value.max + const scaleMax = scaleObservable.value.max return getTickPositions().map((y, i) => { const style = styles.yAxisLabel @@ -38,8 +38,8 @@ export function makeHorizontalGrid() { function getTickPositions() { const units = config.temperatureScale.units - const scaleMin = tempScaleObservable.value.min - const scaleMax = tempScaleObservable.value.max + const scaleMin = scaleObservable.value.min + const scaleMax = scaleObservable.value.max const numberOfTicks = (scaleMax - scaleMin) * (1 / units) const tickDistance = config.chartHeight / numberOfTicks @@ -52,8 +52,8 @@ function getTickPositions() { } export function normalizeToScale(temp) { - const scale = config.temperatureScale - const valueRelativeToScale = (scale.high - temp) / (scale.high - scale.low) + const scale = scaleObservable.value + const valueRelativeToScale = (scale.max - temp) / (scale.max - scale.min) const scaleHeight = config.chartHeight return scaleHeight * valueRelativeToScale } \ No newline at end of file diff --git a/components/settings.js b/components/settings.js index f5fa29f84a1ce42a8a473f58670f9ddfaaef95bb..49172db04b901ce2430a27bfc8f046483b278234 100644 --- a/components/settings.js +++ b/components/settings.js @@ -15,7 +15,7 @@ import config from '../config' import { settings as labels } from './labels' import getDataAsCsvDataUri from '../lib/import-export/export-to-csv' import importCsv from '../lib/import-export/import-from-csv' -import { tempScaleObservable, saveTempScale } from '../local-storage' +import { scaleObservable, saveTempScale } from '../local-storage' export default class Settings extends Component { render() { @@ -62,7 +62,7 @@ export default class Settings extends Component { class TempSlider extends Component { constructor(props) { super(props) - this.state = Object.assign({}, tempScaleObservable.value) + this.state = Object.assign({}, scaleObservable.value) } onValuesChange = (values) => { diff --git a/local-storage/index.js b/local-storage/index.js index 21ac57cbd6abc5e23ae3ed41873bd673e8b31760..50d886fb6c9ada10b874a433dbe17359474f2a87 100644 --- a/local-storage/index.js +++ b/local-storage/index.js @@ -2,7 +2,7 @@ import { AsyncStorage } from 'react-native' import Observable from 'obv' import config from '../config' -export const tempScaleObservable = Observable() +export const scaleObservable = Observable() setTempScaleInitially() async function setTempScaleInitially() { @@ -16,11 +16,11 @@ async function setTempScaleInitially() { max: config.temperatureScale.defaultHigh } } - tempScaleObservable.set(value) + scaleObservable.set(value) } export async function saveTempScale(scale) { await AsyncStorage.setItem('tempScale', JSON.stringify(scale)) - tempScaleObservable.set(scale) + scaleObservable.set(scale) }