Re-render when bleeding value changes
This commit is contained in:
+25
-9
@@ -33,7 +33,8 @@ export default class CycleChart extends Component {
|
|||||||
this.xAxisTicks = makeXAxisTicks(cycleDaysToShow)
|
this.xAxisTicks = makeXAxisTicks(cycleDaysToShow)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
curveCoordinates: this.makeCurveCoordinates()
|
curveCoordinates: this.makeCurveCoordinates(),
|
||||||
|
bleedIconCoordinates: this.makeBleedIconCoordinates()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setStateWithNewCurveCoordinates = (function (chartComponent) {
|
this.setStateWithNewCurveCoordinates = (function (chartComponent) {
|
||||||
@@ -44,11 +45,21 @@ export default class CycleChart extends Component {
|
|||||||
}
|
}
|
||||||
})(this)
|
})(this)
|
||||||
|
|
||||||
|
this.setStateWithNewBleedIconCoordinates = (function (chartComponent) {
|
||||||
|
return function () {
|
||||||
|
chartComponent.setState({
|
||||||
|
bleedIconCoordinates: chartComponent.makeBleedIconCoordinates()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})(this)
|
||||||
|
|
||||||
temperatureDaysSortedByDate.addListener(this.setStateWithNewCurveCoordinates)
|
temperatureDaysSortedByDate.addListener(this.setStateWithNewCurveCoordinates)
|
||||||
|
bleedingDaysSortedByDate.addListener(this.setStateWithNewBleedIconCoordinates)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
temperatureDaysSortedByDate.removeListener(this.setStateWithNewCurveCoordinates)
|
temperatureDaysSortedByDate.removeListener(this.setStateWithNewCurveCoordinates)
|
||||||
|
temperatureDaysSortedByDate.removeListener(this.setStateWithNewBleedIconCoordinates)
|
||||||
}
|
}
|
||||||
|
|
||||||
passDateToDayView(dateString) {
|
passDateToDayView(dateString) {
|
||||||
@@ -84,14 +95,8 @@ export default class CycleChart extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
placeBleedingSymbolsOnColumns() {
|
placeBleedingSymbolsOnColumns() {
|
||||||
return bleedingDaysSortedByDate
|
return this.state.bleedIconCoordinates.map(x => {
|
||||||
.filter(cycleDayIsNotInTheFuture())
|
return (<Circle key={x} cx={x} cy="50" r="7" fill="red" />)
|
||||||
.map(day => {
|
|
||||||
const match = this.xAxisTicks.find(tick => {
|
|
||||||
return tick.label === day.date
|
|
||||||
})
|
|
||||||
const x = match.rightOffset + columnWidth / 2
|
|
||||||
return (<Circle key={day.date} cx={x} cy="50" r="7" fill="red" />)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +107,17 @@ export default class CycleChart extends Component {
|
|||||||
.map(makeCurveCoordinatesForChunk.bind(this))
|
.map(makeCurveCoordinatesForChunk.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
makeBleedIconCoordinates() {
|
||||||
|
return bleedingDaysSortedByDate
|
||||||
|
.filter(cycleDayIsNotInTheFuture())
|
||||||
|
.map(day => {
|
||||||
|
const match = this.xAxisTicks.find(tick => {
|
||||||
|
return tick.label === day.date
|
||||||
|
})
|
||||||
|
return match.rightOffset + columnWidth / 2
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
makeTemperatureCurves() {
|
makeTemperatureCurves() {
|
||||||
return this.state.curveCoordinates.map(makeCurveFromPoints)
|
return this.state.curveCoordinates.map(makeCurveFromPoints)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user