Skip to content

Commit

Permalink
Merge pull request #565 from lifeomic/sleep-chart-bug-fixes
Browse files Browse the repository at this point in the history
fix: Sleep Chart Bug Fixes
  • Loading branch information
sternetj authored Jun 6, 2024
2 parents ee88f56 + 0289aab commit 72da60e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
10 changes: 6 additions & 4 deletions src/components/MyData/SleepChart/DailyChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ export const DailyChart = (props: Props) => {
<ActivityIndicatorView animating={isFetching} />
</View>

<DataSelector
onBlockScrollChange={onBlockScrollChange}
prepareTooltipData={prepareTooltipData}
/>
{data.length > 0 && (
<DataSelector
onBlockScrollChange={onBlockScrollChange}
prepareTooltipData={prepareTooltipData}
/>
)}
</View>
);
};
Expand Down
14 changes: 10 additions & 4 deletions src/components/MyData/SleepChart/MultiDayChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ export const MultiDayChart = (props: Props) => {
<ActivityIndicatorView animating={isFetching} />
</View>

<DataSelector
onBlockScrollChange={onBlockScrollChange}
prepareTooltipData={prepareTooltipData}
/>
{data.length > 0 && (
<DataSelector
onBlockScrollChange={onBlockScrollChange}
prepareTooltipData={prepareTooltipData}
/>
)}
</View>
);
};
Expand All @@ -226,6 +228,10 @@ const SleepBar = (props: BarProps) => {
};
let total = 0;

if (props.datum.components.length === 0) {
return null;
}

props.datum.components.forEach((component: ObservationComponent) => {
if (!component?.valuePeriod?.start || !component?.valuePeriod?.end) {
return;
Expand Down
14 changes: 12 additions & 2 deletions src/components/MyData/SleepChart/useSleepChartData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { useEffect, useState } from 'react';
import { useFhirClient } from '../../../hooks';
import { ScaleTime, scaleTime } from 'd3-scale';
import { differenceInDays, min, max, startOfDay, endOfDay } from 'date-fns';
import {
differenceInDays,
min,
max,
startOfDay,
endOfDay,
isValid,
} from 'date-fns';
import { useCommonChartProps } from '../useCommonChartProps';
import { Observation } from 'fhir/r3';
import compact from 'lodash/compact';
Expand Down Expand Up @@ -87,9 +94,12 @@ export const useSleepChartData = (props: Props) => {
{} as { start?: Date; end?: Date },
);

const startDate = start && isValid(start) ? start : new Date(0);
const endDate = end && isValid(end) ? end : new Date(0);

const newXDomain = scaleTime()
.range([0, common.plotAreaWidth])
.domain([new Date(start ?? 0), new Date(end ?? 0)]);
.domain([startDate, endDate]);

setChartData({ sleepData: newSleepData, xDomain: newXDomain, dateRange });
setIsLoading(false);
Expand Down
4 changes: 4 additions & 0 deletions src/screens/MyDataScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export const MyDataScreen = () => {
{config?.homeTab?.myDataSettings?.components.map((component, index) => (
<React.Fragment key={`${component.type}-${index}`}>
<View
style={styles.chartWrapperContainer}
onLayout={(e) => {
chartDimensions.current[index] = e.nativeEvent.layout;
}}
Expand Down Expand Up @@ -327,6 +328,9 @@ const defaultStyles = createStyles('MyDataScreen', (theme) => ({
marginBottom: 24,
marginTop: 5,
},
chartWrapperContainer: {
width: '100%',
},
}));

declare module '@styles' {
Expand Down

0 comments on commit 72da60e

Please sign in to comment.