-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reports screen: SleepPieChart added && report time bugfix
- Loading branch information
1 parent
ba01575
commit e612b1d
Showing
6 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from "react"; | ||
import {GenericCard} from "../cards/GenericCard"; | ||
import {Dimensions} from "react-native"; | ||
import {Sleep} from "../../store/SleepStore"; | ||
import {Observer} from "mobx-react"; | ||
import {LineChart, PieChart} from "react-native-chart-kit"; | ||
import {Text} from "native-base"; | ||
|
||
const sleepColors = ["#f3e8ff", "#e9d5ff", "#d8b4fe", "#c084fc", "#a855f7", "#9333ea", "#7e22ce", "#6b21a8", "#581c87", "#4c1d95", "#4527a0", "#382b7f", "#2d3a59", "#27303f", "#1e213a"] | ||
|
||
export const SleepPieChart = ({sleeps}: {sleeps: Array<Sleep> | undefined }) => { | ||
return ( | ||
<Observer> | ||
{() => { | ||
let data: { name: string; value: number; color: string; legendFontColor: string }[] | undefined = sleeps?.reduce((acc, sleep, i) => { | ||
if (sleep.cycle !== undefined) { | ||
const existingIndex = acc.findIndex((item) => item.name === `${sleep.cycle} Cycles`); | ||
|
||
if (existingIndex !== -1) { | ||
acc[existingIndex].value += 1; | ||
} else { | ||
acc.push({ | ||
name: `${sleep.cycle} Cycles`, | ||
value: 1, | ||
color: sleepColors[i % sleepColors.length], | ||
legendFontColor: "white", | ||
}); | ||
} | ||
} | ||
return acc; | ||
}, [] as { name: string; value: number; color: string; legendFontColor: string }[]); | ||
|
||
if (!data || data.length == 0) { | ||
data = [{ | ||
name: "No Sleep Data", | ||
value: 100, | ||
color: "white", | ||
legendFontColor: "white", | ||
}] | ||
} | ||
|
||
return ( | ||
<GenericCard style={{marginVertical: 10, backgroundColor: "#360b54", marginTop: 5}}> | ||
<Text color="white" fontSize="md" bold textAlign="center">Sleep Cycles</Text> | ||
<PieChart | ||
data={data} | ||
accessor={"value"} | ||
backgroundColor={"#360b54"} | ||
width={Dimensions.get("window").width} | ||
height={Dimensions.get("window").height / 3} | ||
paddingLeft={"15"} | ||
center={[10, 0]} | ||
chartConfig={{ | ||
decimalPlaces: 0, | ||
color: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`, | ||
labelColor: (opacity = 1) => `rgba(255, 255, 255, ${opacity})`, | ||
}} | ||
style={{borderRadius: 20}} | ||
/> | ||
</GenericCard>); | ||
}} | ||
</Observer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters