Compare commits

...

4 Commits

Author SHA1 Message Date
bl00dymarie c519a22456 Check for oldest/ highest column 2024-04-05 18:22:26 +02:00
bl00dymarie ea8e13e90f Make var names more precise 2024-04-05 18:21:25 +02:00
bl00dymarie baa057229e Fix: Bug for displayedMonth of oldest scrollable date on chart 2024-04-05 12:50:22 +02:00
bl00dymarie a54e48b17e Feature: Combine dynamic month label with moving month label in x axis
Co-authored-by: @livgm
2024-04-03 20:39:59 +02:00
3 changed files with 44 additions and 7 deletions
+6 -3
View File
@@ -1,21 +1,23 @@
import React from 'react'
import PropTypes from 'prop-types'
import { StyleSheet, View } from 'react-native'
import moment from 'moment'
import AppText from '../common/app-text'
import { Sizes, Typography } from '../../styles'
import { CHART_YAXIS_WIDTH } from '../../config'
import { shared as labels } from '../../i18n/en/labels'
const ChartLegend = ({ height }) => {
const ChartLegend = ({ height, currentDate }) => {
const displayedMonth = moment(currentDate).format('MMM')
return (
<View style={[styles.container, { height }]}>
<View style={[styles.singleLabelContainer, { height: height / 2 }]}>
<AppText style={styles.textBold}>#</AppText>
</View>
<View style={[styles.singleLabelContainer, { height: height / 2 }]}>
<AppText style={styles.text}>{labels.date}</AppText>
<AppText style={styles.text}>{displayedMonth}</AppText>
</View>
</View>
)
@@ -23,6 +25,7 @@ const ChartLegend = ({ height }) => {
ChartLegend.propTypes = {
height: PropTypes.number.isRequired,
currentDate: PropTypes.string,
}
const styles = StyleSheet.create({
+35 -3
View File
@@ -32,6 +32,7 @@ import {
CHART_GRID_LINE_HORIZONTAL_WIDTH,
CHART_SYMPTOM_HEIGHT_RATIO,
CHART_XAXIS_HEIGHT_RATIO,
CHART_YAXIS_WIDTH,
SYMPTOMS,
} from '../../config'
import { Spacing } from '../../styles'
@@ -97,8 +98,7 @@ const CycleChart = ({ navigate, setDate }) => {
const shouldShowNoDataWarning =
isTemperatureEnabled && chartSymptoms.indexOf('temperature') <= -1
const { width, height } = Dimensions.get('window')
const numberOfColumnsToRender = Math.round(width / CHART_COLUMN_WIDTH)
const { height } = Dimensions.get('window')
const xAxisHeight = height * 0.7 * CHART_XAXIS_HEIGHT_RATIO
const remainingHeight = height * 0.7 - xAxisHeight
@@ -117,6 +117,35 @@ const CycleChart = ({ navigate, setDate }) => {
const columns = makeColumnInfo()
// Monitor scrolling to show proper month abbreviation in symptom chart
const [currentScrollPosition, setCurrentScrollPosition] = useState(0)
const handleScroll = (event) => {
const currentPosition = event.nativeEvent.contentOffset.x
setCurrentScrollPosition(currentPosition)
}
const [numberOfColumnsToRender, setNumberOfColumnsToRender] = useState(0)
const onLayout = (event) => {
const { width } = event.nativeEvent.layout
setNumberOfColumnsToRender(
Math.round((width - CHART_YAXIS_WIDTH) / CHART_COLUMN_WIDTH)
)
}
const getLeftmostComputedDateInView = () => {
const rightmostVisibleIndexInView = Math.floor(
currentScrollPosition / CHART_COLUMN_WIDTH
)
const leftmostVisibleIndexInView =
rightmostVisibleIndexInView + numberOfColumnsToRender >= columns.length
? columns.length - 1
: rightmostVisibleIndexInView + numberOfColumnsToRender
// detect leftmost aka oldest visible day to render its month dynamically
return columns[leftmostVisibleIndexInView]
}
const renderColumn = ({ item }) => {
return (
<DayColumn
@@ -144,7 +173,7 @@ const CycleChart = ({ navigate, setDate }) => {
contentContainerStyle={styles.pageContainer}
scrollViewStyle={styles.page}
>
<View style={styles.chartContainer}>
<View style={styles.chartContainer} onLayout={onLayout}>
{shouldShowHint && <Tutorial onClose={hideHint} />}
{shouldShowNoDataWarning && <NoTemperature />}
<View style={styles.chartArea}>
@@ -154,12 +183,15 @@ const CycleChart = ({ navigate, setDate }) => {
symptomsSectionHeight={symptomRowHeight}
shouldShowTemperatureColumn={shouldShowTemperatureColumn}
xAxisHeight={xAxisHeight}
computedDate={getLeftmostComputedDateInView()}
/>
<MainGrid
data={columns}
renderItem={renderColumn}
initialNumToRender={numberOfColumnsToRender}
contentContainerStyle={{ height: chartHeight }}
onScroll={handleScroll}
scrollEventThrottle={16} // Detects scroll events at roughly 60fps
/>
{shouldShowTemperatureColumn && (
<HorizontalGrid height={columnHeight} />
+3 -1
View File
@@ -14,13 +14,14 @@ const YAxis = ({
symptomsSectionHeight,
shouldShowTemperatureColumn,
xAxisHeight,
computedDate,
}) => {
const symptomIconHeight = symptomsSectionHeight / symptomsToDisplay.length
return (
<View>
{shouldShowTemperatureColumn && <TickList height={height} />}
<ChartLegend height={xAxisHeight} />
<ChartLegend height={xAxisHeight} currentDate={computedDate} />
<View style={[styles.yAxis, { height: symptomsSectionHeight }]}>
{symptomsToDisplay.map((symptom) => (
<SymptomIcon
@@ -40,6 +41,7 @@ YAxis.propTypes = {
symptomsSectionHeight: PropTypes.number,
shouldShowTemperatureColumn: PropTypes.bool,
xAxisHeight: PropTypes.number.isRequired,
computedDate: PropTypes.string,
}
const styles = StyleSheet.create({