diff --git a/components/chart/chart.js b/components/chart/chart.js
index dd2c29b..da19f2c 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 = {makeYAxisLabels()}
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 (
- {this.yAxisView}
+ {makeYAxisLabels()}
{makeHorizontalGrid()}
{ {
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 f5fa29f..49172db 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 21ac57c..50d886f 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)
}