Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Commit 72da60e

Browse files
authored
Merge pull request #565 from lifeomic/sleep-chart-bug-fixes
fix: Sleep Chart Bug Fixes
2 parents ee88f56 + 0289aab commit 72da60e

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

src/components/MyData/SleepChart/DailyChart.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,12 @@ export const DailyChart = (props: Props) => {
175175
<ActivityIndicatorView animating={isFetching} />
176176
</View>
177177

178-
<DataSelector
179-
onBlockScrollChange={onBlockScrollChange}
180-
prepareTooltipData={prepareTooltipData}
181-
/>
178+
{data.length > 0 && (
179+
<DataSelector
180+
onBlockScrollChange={onBlockScrollChange}
181+
prepareTooltipData={prepareTooltipData}
182+
/>
183+
)}
182184
</View>
183185
);
184186
};

src/components/MyData/SleepChart/MultiDayChart.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,12 @@ export const MultiDayChart = (props: Props) => {
207207
<ActivityIndicatorView animating={isFetching} />
208208
</View>
209209

210-
<DataSelector
211-
onBlockScrollChange={onBlockScrollChange}
212-
prepareTooltipData={prepareTooltipData}
213-
/>
210+
{data.length > 0 && (
211+
<DataSelector
212+
onBlockScrollChange={onBlockScrollChange}
213+
prepareTooltipData={prepareTooltipData}
214+
/>
215+
)}
214216
</View>
215217
);
216218
};
@@ -226,6 +228,10 @@ const SleepBar = (props: BarProps) => {
226228
};
227229
let total = 0;
228230

231+
if (props.datum.components.length === 0) {
232+
return null;
233+
}
234+
229235
props.datum.components.forEach((component: ObservationComponent) => {
230236
if (!component?.valuePeriod?.start || !component?.valuePeriod?.end) {
231237
return;

src/components/MyData/SleepChart/useSleepChartData.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { useEffect, useState } from 'react';
22
import { useFhirClient } from '../../../hooks';
33
import { ScaleTime, scaleTime } from 'd3-scale';
4-
import { differenceInDays, min, max, startOfDay, endOfDay } from 'date-fns';
4+
import {
5+
differenceInDays,
6+
min,
7+
max,
8+
startOfDay,
9+
endOfDay,
10+
isValid,
11+
} from 'date-fns';
512
import { useCommonChartProps } from '../useCommonChartProps';
613
import { Observation } from 'fhir/r3';
714
import compact from 'lodash/compact';
@@ -87,9 +94,12 @@ export const useSleepChartData = (props: Props) => {
8794
{} as { start?: Date; end?: Date },
8895
);
8996

97+
const startDate = start && isValid(start) ? start : new Date(0);
98+
const endDate = end && isValid(end) ? end : new Date(0);
99+
90100
const newXDomain = scaleTime()
91101
.range([0, common.plotAreaWidth])
92-
.domain([new Date(start ?? 0), new Date(end ?? 0)]);
102+
.domain([startDate, endDate]);
93103

94104
setChartData({ sleepData: newSleepData, xDomain: newXDomain, dateRange });
95105
setIsLoading(false);

src/screens/MyDataScreen.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const MyDataScreen = () => {
110110
{config?.homeTab?.myDataSettings?.components.map((component, index) => (
111111
<React.Fragment key={`${component.type}-${index}`}>
112112
<View
113+
style={styles.chartWrapperContainer}
113114
onLayout={(e) => {
114115
chartDimensions.current[index] = e.nativeEvent.layout;
115116
}}
@@ -327,6 +328,9 @@ const defaultStyles = createStyles('MyDataScreen', (theme) => ({
327328
marginBottom: 24,
328329
marginTop: 5,
329330
},
331+
chartWrapperContainer: {
332+
width: '100%',
333+
},
330334
}));
331335

332336
declare module '@styles' {

0 commit comments

Comments
 (0)