Display cycle day number along with date
This commit is contained in:
+30
-21
@@ -10,16 +10,20 @@ import Svg,{
|
|||||||
} from 'react-native-svg'
|
} from 'react-native-svg'
|
||||||
import { LocalDate } from 'js-joda'
|
import { LocalDate } from 'js-joda'
|
||||||
import { getCycleDay, getOrCreateCycleDay, cycleDaysSortedByDate } from '../db'
|
import { getCycleDay, getOrCreateCycleDay, cycleDaysSortedByDate } from '../db'
|
||||||
|
import getCycleDayNumberModule from '../get-cycle-day-number'
|
||||||
|
|
||||||
const right = 600
|
const getCycleDayNumber = getCycleDayNumberModule()
|
||||||
const top = 10
|
|
||||||
const bottom = 350
|
const chartLength = 350
|
||||||
const columnWidth = 30
|
const columnWidth = 30
|
||||||
const middle = columnWidth / 2
|
const middle = columnWidth / 2
|
||||||
const dateRow = {
|
const xAxis = {
|
||||||
height: 30,
|
top: chartLength - 15,
|
||||||
width: right
|
margin: 3
|
||||||
}
|
}
|
||||||
|
const dateRowY = xAxis.top - xAxis.margin
|
||||||
|
const cycleDayNumberRowY = chartLength - xAxis.margin
|
||||||
|
|
||||||
const temperatureScale = {
|
const temperatureScale = {
|
||||||
low: 33,
|
low: 33,
|
||||||
high: 40
|
high: 40
|
||||||
@@ -53,24 +57,29 @@ export default class CycleChart extends Component {
|
|||||||
this.props.navigation.navigate('cycleDay', { cycleDay })
|
this.props.navigation.navigate('cycleDay', { cycleDay })
|
||||||
}
|
}
|
||||||
|
|
||||||
makeDayColumn({ label, cycleDay, y }, index) {
|
makeDayColumn({ dateString, cycleDay, y }, index) {
|
||||||
|
const cycleDayNumber = getCycleDayNumber(dateString)
|
||||||
|
const labelProps = {
|
||||||
|
stroke: "grey",
|
||||||
|
fontSize: "10",
|
||||||
|
x: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateLabel = dateString.split('-').slice(1).join('-')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<G key={label} onPress={() => this.passDateToDayView(label)}>
|
<G key={dateString} onPress={() => this.passDateToDayView(dateString)}>
|
||||||
<Rect
|
<Rect
|
||||||
x={0}
|
x={0}
|
||||||
y={top}
|
y={0}
|
||||||
width={columnWidth}
|
width={columnWidth}
|
||||||
height={bottom - top - dateRow.height}
|
height={chartLength}
|
||||||
fill="lightgrey"
|
fill="lightgrey"
|
||||||
strokeWidth="1"
|
strokeWidth="1"
|
||||||
stroke="grey"
|
stroke="grey"
|
||||||
/>
|
/>
|
||||||
<Text
|
<Text {...labelProps} y={cycleDayNumberRowY}>{cycleDayNumber}</Text>
|
||||||
stroke="grey"
|
<Text {...labelProps} y={dateRowY}>{dateLabel}</Text>
|
||||||
fontSize="10"
|
|
||||||
x={0}
|
|
||||||
y={bottom - top - dateRow.height}
|
|
||||||
>{label.split('-')[2]}</Text>
|
|
||||||
|
|
||||||
{cycleDay && cycleDay.bleeding ? <Circle cx={middle} cy="50" r="7" fill="red" /> : null}
|
{cycleDay && cycleDay.bleeding ? <Circle cx={middle} cy="50" r="7" fill="red" /> : null}
|
||||||
|
|
||||||
@@ -127,7 +136,7 @@ export default class CycleChart extends Component {
|
|||||||
data={this.state.columns}
|
data={this.state.columns}
|
||||||
renderItem={({item, index}) => {
|
renderItem={({item, index}) => {
|
||||||
return (
|
return (
|
||||||
<Svg width={columnWidth} height={bottom}>
|
<Svg width={columnWidth} height={chartLength}>
|
||||||
{this.makeDayColumn(item, index)}
|
{this.makeDayColumn(item, index)}
|
||||||
</Svg>
|
</Svg>
|
||||||
)
|
)
|
||||||
@@ -148,11 +157,11 @@ function makeColumnInfo(n) {
|
|||||||
).toString()
|
).toString()
|
||||||
})
|
})
|
||||||
|
|
||||||
return xAxisDates.map(datestring => {
|
return xAxisDates.map(dateString => {
|
||||||
const cycleDay = getCycleDay(datestring)
|
const cycleDay = getCycleDay(dateString)
|
||||||
const temp = cycleDay && cycleDay.temperature && cycleDay.temperature.value
|
const temp = cycleDay && cycleDay.temperature && cycleDay.temperature.value
|
||||||
return {
|
return {
|
||||||
label: datestring,
|
dateString,
|
||||||
cycleDay,
|
cycleDay,
|
||||||
y: temp ? normalizeToScale(temp) : null
|
y: temp ? normalizeToScale(temp) : null
|
||||||
}
|
}
|
||||||
@@ -169,6 +178,6 @@ function getPreviousDays(n) {
|
|||||||
|
|
||||||
function normalizeToScale(temp) {
|
function normalizeToScale(temp) {
|
||||||
const valueRelativeToScale = (temperatureScale.high - temp) / (temperatureScale.high - temperatureScale.low)
|
const valueRelativeToScale = (temperatureScale.high - temp) / (temperatureScale.high - temperatureScale.low)
|
||||||
const scaleHeight = bottom - top
|
const scaleHeight = chartLength
|
||||||
return scaleHeight * valueRelativeToScale
|
return scaleHeight * valueRelativeToScale
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user