-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f13db93
commit 87668b5
Showing
9 changed files
with
107 additions
and
53 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,49 +1,11 @@ | ||
import React from 'react'; | ||
import { useDataQuery } from '../hooks/useDataQuery'; | ||
import { TargetBuckets } from '../types/types'; | ||
import { Box, Heading, useColorModeValue, useTheme } from '@chakra-ui/react'; | ||
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, XAxis } from 'recharts'; | ||
import { useColorModeValue, useTheme } from '@chakra-ui/react'; | ||
import { Distribution } from './Distribution'; | ||
|
||
interface CadenceDistributionContentProps { | ||
data: TargetBuckets; | ||
} | ||
|
||
const CadenceDistributionContent: React.FC<CadenceDistributionContentProps> = ({ data }) => { | ||
export const CadenceDistribution: React.FC = () => { | ||
const theme = useTheme(); | ||
const strokeColor = useColorModeValue(theme.colors.yellow[500], theme.colors.yellow[300]); | ||
const fillColor = useColorModeValue(theme.colors.yellow[200], theme.colors.yellow[100]); | ||
|
||
const filtered = data | ||
.filter(([bucket]) => bucket >= 0) | ||
.map(([bucket, value]) => ([bucket, bucket > 0 ? value : 0] as const)); | ||
const total = filtered.length > 0 ? filtered.map(([_, value]) => value).reduce((a, b) => a + b) : 0; | ||
const seriesData = filtered | ||
.map(([name, value]) => ({ name, value: 100 * value / total })); | ||
const xTicks = seriesData.map(({ name }) => name).filter(bucket => bucket % 10 === 0); | ||
|
||
return ( | ||
<Box w="100%"> | ||
<Heading as="h1" fontSize={{ base: "2xl", md: "3xl" }} mb={3} textAlign="center"> | ||
Pedaling rate | ||
</Heading> | ||
<ResponsiveContainer width="100%" height={300}> | ||
<AreaChart | ||
data={seriesData} | ||
margin={{ top: 5, right: 5, left: 5, bottom: 5 }} | ||
> | ||
<CartesianGrid strokeDasharray="3 3" /> | ||
<XAxis dataKey="name" ticks={xTicks} unit=" RPM" /> | ||
{/*<YAxis unit="%" />*/} | ||
<Area type="monotone" dataKey="value" stroke={strokeColor} fill={fillColor} /> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
</Box> | ||
); | ||
}; | ||
|
||
export const CadenceDistribution: React.FC = () => { | ||
const { data } = useDataQuery('cadence') | ||
if (!data) return null; | ||
|
||
return <CadenceDistributionContent data={data} />; | ||
return <Distribution dataKey="cadence" heading="Cadence" unit="RPM" strokeColor={strokeColor} fillColor={fillColor} />; | ||
}; |
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,53 @@ | ||
import React from 'react'; | ||
import { useDataQuery } from '../hooks/useDataQuery'; | ||
import { Data, TargetBuckets } from '../types/types'; | ||
import { Box, Heading } from '@chakra-ui/react'; | ||
import { Area, AreaChart, CartesianGrid, ResponsiveContainer, XAxis } from 'recharts'; | ||
|
||
interface DistributionContentProps extends Omit<DistributionProps, 'dataKey'> { | ||
data: TargetBuckets; | ||
} | ||
|
||
const DistributionContent: React.FC<DistributionContentProps> = ({ data, heading, unit, strokeColor, fillColor }) => { | ||
const filtered = data | ||
.filter(([bucket]) => bucket >= 0) | ||
.map(([bucket, value]) => ([bucket, bucket > 0 ? value : 0] as const)); | ||
const total = filtered.length > 0 ? filtered.map(([_, value]) => value).reduce((a, b) => a + b) : 0; | ||
const seriesData = filtered | ||
.map(([name, value]) => ({ name, value: 100 * value / total })); | ||
const xTicks = seriesData.map(({ name }) => name).filter(bucket => bucket % 10 === 0); | ||
|
||
return ( | ||
<Box w="100%"> | ||
<Heading as="h1" fontSize={{ base: "2xl", md: "3xl" }} mb={3} textAlign="center"> | ||
{heading} | ||
</Heading> | ||
<ResponsiveContainer width="100%" height={300}> | ||
<AreaChart | ||
data={seriesData} | ||
margin={{ top: 5, right: 5, left: 5, bottom: 5 }} | ||
> | ||
<CartesianGrid strokeDasharray="3 3" /> | ||
<XAxis dataKey="name" ticks={xTicks} unit={` ${unit}`} /> | ||
{/*<YAxis unit="%" />*/} | ||
<Area type="monotone" dataKey="value" stroke={strokeColor} fill={fillColor} /> | ||
</AreaChart> | ||
</ResponsiveContainer> | ||
</Box> | ||
); | ||
}; | ||
|
||
interface DistributionProps { | ||
dataKey: { [K in keyof Data]: Data[K] extends TargetBuckets ? K : never }[keyof Data]; | ||
heading: string; | ||
unit: string; | ||
strokeColor: string; | ||
fillColor: string; | ||
} | ||
|
||
export const Distribution: React.FC<DistributionProps> = ({ dataKey, ...rest }) => { | ||
const { data } = useDataQuery(dataKey) | ||
if (!data) return null; | ||
|
||
return <DistributionContent data={data} {...rest} />; | ||
}; |
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,11 @@ | ||
import React from 'react'; | ||
import { useColorModeValue, useTheme } from '@chakra-ui/react'; | ||
import { Distribution } from './Distribution'; | ||
|
||
export const PowerDistribution: React.FC = () => { | ||
const theme = useTheme(); | ||
const strokeColor = useColorModeValue(theme.colors.yellow[500], theme.colors.yellow[300]); | ||
const fillColor = useColorModeValue(theme.colors.yellow[200], theme.colors.yellow[100]); | ||
|
||
return <Distribution dataKey="power" heading="Power" unit="W" strokeColor={strokeColor} fillColor={fillColor} />; | ||
}; |
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,11 @@ | ||
import React from 'react'; | ||
import { useColorModeValue, useTheme } from '@chakra-ui/react'; | ||
import { Distribution } from './Distribution'; | ||
|
||
export const SpeedDistribution: React.FC = () => { | ||
const theme = useTheme(); | ||
const strokeColor = useColorModeValue(theme.colors.yellow[500], theme.colors.yellow[300]); | ||
const fillColor = useColorModeValue(theme.colors.yellow[200], theme.colors.yellow[100]); | ||
|
||
return <Distribution dataKey="speed" heading="Speed" unit="km/h" strokeColor={strokeColor} fillColor={fillColor} />; | ||
}; |
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