Re-render chart on temp change
This commit is contained in:
+24
-4
@@ -31,6 +31,24 @@ export default class CycleChart extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.xAxisTicks = makeXAxisTicks(cycleDaysToShow)
|
this.xAxisTicks = makeXAxisTicks(cycleDaysToShow)
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
curveCoordinates: this.makeCurveCoordinates()
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setStateWithNewCurveCoordinates = (function (chartComponent) {
|
||||||
|
return function () {
|
||||||
|
chartComponent.setState({
|
||||||
|
curveCoordinates: chartComponent.makeCurveCoordinates()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})(this)
|
||||||
|
|
||||||
|
temperatureDaysSortedByDate.addListener(this.setStateWithNewCurveCoordinates)
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
temperatureDaysSortedByDate.removeListener(this.setStateWithNewCurveCoordinates)
|
||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView(dateString) {
|
passDateToDayView(dateString) {
|
||||||
@@ -77,12 +95,15 @@ export default class CycleChart extends Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
makeTemperatureCurves() {
|
makeCurveCoordinates() {
|
||||||
return temperatureDaysSortedByDate
|
return temperatureDaysSortedByDate
|
||||||
.filter(cycleDayIsNotInTheFuture())
|
.filter(cycleDayIsNotInTheFuture())
|
||||||
.reduce(separateIntoContinousChunks, [[]])
|
.reduce(separateIntoContinousChunks, [[]])
|
||||||
.map(makeCurveCoordinatesForChunk.bind(this))
|
.map(makeCurveCoordinatesForChunk.bind(this))
|
||||||
.map(makeCurveFromPoints)
|
}
|
||||||
|
|
||||||
|
makeTemperatureCurves() {
|
||||||
|
return this.state.curveCoordinates.map(makeCurveFromPoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@@ -195,9 +216,8 @@ function makeCurveFromPoints(curveChunkPoints, i) {
|
|||||||
.join(' ')
|
.join(' ')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<G>
|
<G key={i}>
|
||||||
<Polyline
|
<Polyline
|
||||||
key={i}
|
|
||||||
points={pointsInPolyLineFormat}
|
points={pointsInPolyLineFormat}
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke={curveColor}
|
stroke={curveColor}
|
||||||
|
|||||||
Reference in New Issue
Block a user