This repository has been archived by the owner on Jan 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WDY-406
- Loading branch information
Showing
12 changed files
with
235 additions
and
576 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useMemo, useState } from 'react'; | ||
import { Box, Text, Tooltip } from '@binarycapsule/ui-capsules'; | ||
|
||
interface TooltipContentProps { | ||
label: string; | ||
value: string; | ||
color: string; | ||
} | ||
|
||
const TooltipContent: React.FC<TooltipContentProps> = ({ label, value, color }) => { | ||
return ( | ||
<Box display="flex" alignItems="center"> | ||
<Box width={8} height={8} bg={color} mr="4" /> | ||
|
||
<Text color="neutral.100" fontSize="small" mr="4"> | ||
{`${label}:`} | ||
</Text> | ||
|
||
<Text color="neutral.100" fontSize="small" fontWeight={600}> | ||
{value} | ||
</Text> | ||
</Box> | ||
); | ||
}; | ||
|
||
export interface StackedBarProps { | ||
data: { | ||
label: string; | ||
value: number; | ||
color: string; | ||
}[]; | ||
formatter?(val: number): string; | ||
} | ||
|
||
export const StackedBar: React.FC<StackedBarProps> = ({ data, formatter }) => { | ||
const [hovered, setHovered] = useState<number | null>(null); | ||
|
||
const total = useMemo(() => { | ||
return data.reduce((acc, { value }) => acc + value, 0); | ||
}, [data]); | ||
|
||
return ( | ||
<Box | ||
display="flex" | ||
flexDirection="row" | ||
height={24} | ||
width="100%" | ||
style={{ overflow: 'hidden', borderRadius: 4 }} | ||
> | ||
{data.map(({ label, value, color }, index) => { | ||
return ( | ||
<Tooltip | ||
key={label} | ||
content={ | ||
<TooltipContent | ||
label={label} | ||
value={formatter ? formatter(value) : value.toString()} | ||
color={color} | ||
/> | ||
} | ||
placement="top" | ||
delay={0} | ||
> | ||
<Box | ||
bg={color} | ||
flex={value / total} | ||
height={32} | ||
onMouseEnter={() => setHovered(index)} | ||
onMouseLeave={() => setHovered(null)} | ||
style={{ opacity: hovered !== null && hovered !== index ? 0.3 : 1 }} | ||
/> | ||
</Tooltip> | ||
); | ||
})} | ||
</Box> | ||
); | ||
}; |
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,3 @@ | ||
export interface ReportRouteParams { | ||
dayId: string; | ||
} |
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
73 changes: 0 additions & 73 deletions
73
frontend/src/features/report/ReportPage/TaskPerSectionChart/TaskPerSectionChart.jsx
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
25 changes: 25 additions & 0 deletions
25
frontend/src/features/report/components/SectionChart/SectionChart.styles.ts
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,25 @@ | ||
import styled from '@emotion/styled/macro'; | ||
import { Box } from '@binarycapsule/ui-capsules'; | ||
|
||
export const ChartWrapper = styled(Box)` | ||
border-radius: 12px; | ||
border: ${({ theme }) => `1px solid ${theme.colors.neutral['200']}`}; | ||
`; | ||
|
||
export const HeadCell = styled.th` | ||
height: 38px; | ||
vertical-align: middle; | ||
padding: 0 18px; | ||
text-align: left; | ||
white-space: initial; | ||
border-top: ${({ theme }) => `1px solid ${theme.colors.neutral['200']}`}; | ||
border-bottom: ${({ theme }) => `1px solid ${theme.colors.neutral['200']}`}; | ||
`; | ||
|
||
export const Cell = styled.td` | ||
height: 38px; | ||
vertical-align: middle; | ||
padding: 0 18px; | ||
text-align: left; | ||
white-space: initial; | ||
`; |
66 changes: 66 additions & 0 deletions
66
frontend/src/features/report/components/SectionChart/SectionChart.tsx
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,66 @@ | ||
import React from 'react'; | ||
import useMedia from 'react-use/lib/useMedia'; | ||
import { useSectionChart } from './useSectionChart'; | ||
import { StackedBar } from '../../../../components/charts/StackedBar/StackedBar'; | ||
import { formatTotalTime } from '../../../../helpers/timeHelpers'; | ||
import { Box, Flex, Text, Wrapper, WrapperProps } from '@binarycapsule/ui-capsules'; | ||
import { Cell, ChartWrapper, HeadCell } from './SectionChart.styles'; | ||
|
||
export const SectionChart: React.FC<WrapperProps> = props => { | ||
const { data } = useSectionChart(); | ||
|
||
const isWide = useMedia('(min-width: 720px)'); | ||
|
||
if (!data) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Wrapper {...props}> | ||
<ChartWrapper> | ||
<Box m="16"> | ||
<StackedBar data={data} formatter={formatTotalTime} /> | ||
</Box> | ||
|
||
<table style={{ width: '100%' }}> | ||
<thead> | ||
<tr> | ||
<HeadCell> | ||
<Text variant="smallCaps" color="neutral.700"> | ||
Sections | ||
</Text> | ||
</HeadCell> | ||
|
||
{isWide && ( | ||
<HeadCell style={{ textAlign: 'center' }}> | ||
<Text variant="smallCaps">Tasks</Text> | ||
</HeadCell> | ||
)} | ||
|
||
<HeadCell> | ||
<Text variant="smallCaps">Time</Text> | ||
</HeadCell> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{data.map(({ value, label, color, taskCount }) => ( | ||
<tr> | ||
<Cell> | ||
<Flex alignItems="center"> | ||
<Box bg={color} width={12} height={12} mr="8" /> | ||
{label} | ||
</Flex> | ||
</Cell> | ||
|
||
{isWide && <Cell style={{ textAlign: 'center' }}>{taskCount}</Cell>} | ||
|
||
<Cell>{formatTotalTime(value)}</Cell> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</ChartWrapper> | ||
</Wrapper> | ||
); | ||
}; |
Oops, something went wrong.