diff --git a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveChart.tsx b/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveChart.tsx index e3fcb657c3..36f7b801b5 100644 --- a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveChart.tsx +++ b/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveChart.tsx @@ -5,7 +5,6 @@ import { useProjectChartData } from 'component/insights/hooks/useProjectChartDat import { useTheme } from '@mui/material'; import type { GroupedDataByProject } from 'component/insights/hooks/useGroupedProjectTrends'; import { usePlaceholderData } from 'component/insights/hooks/usePlaceholderData'; -import { Chart } from 'react-chartjs-2'; import { CategoryScale, LinearScale, @@ -19,13 +18,11 @@ import { Filler, } from 'chart.js'; import { useLocationSettings } from 'hooks/useLocationSettings'; -import { - ChartTooltip, - type TooltipState, -} from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; -import { createTooltip } from 'component/insights/components/LineChart/createTooltip'; -import { CreationArchiveTooltip } from './CreationArchiveTooltip.tsx'; +import type { TooltipState } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; import type { WeekData, RawWeekData } from './types.ts'; +import { createTooltip } from 'component/insights/components/LineChart/createTooltip.ts'; +import { CreationArchiveRatioTooltip } from './CreationArchiveRatioTooltip.tsx'; +import { Chart } from 'react-chartjs-2'; ChartJS.register( CategoryScale, @@ -144,6 +141,10 @@ export const CreationArchiveChart: FC = ({ data={data} options={{ responsive: true, + interaction: { + mode: 'index', + intersect: false, + }, plugins: { legend: { position: 'bottom' as const, @@ -156,7 +157,7 @@ export const CreationArchiveChart: FC = ({ }, tooltip: { enabled: false, - position: 'nearest', + position: 'average', external: createTooltip(setTooltip), }, }, @@ -187,13 +188,7 @@ export const CreationArchiveChart: FC = ({ height={100} width={250} /> - {tooltip?.dataPoints?.some( - (point) => point.dataset.label !== 'Flags archived', - ) ? ( - - ) : ( - - )} + ); }; diff --git a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveRatioTooltip.tsx b/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveRatioTooltip.tsx index 0edc04c797..d88783627c 100644 --- a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveRatioTooltip.tsx +++ b/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveRatioTooltip.tsx @@ -1,24 +1,38 @@ import type { FC } from 'react'; -import { Box, Paper, Typography, styled, useTheme } from '@mui/material'; +import { Paper, Typography, styled } from '@mui/material'; import type { TooltipState } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; import { ChartTooltipContainer } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; -import type { Theme } from '@mui/material/styles/createTheme'; import type { WeekData } from './types.ts'; -const getRatioTooltipColors = (theme: Theme) => ({ - CREATED: theme.palette.success.main, - ARCHIVED: theme.palette.background.application, -}); const StyledTooltipItemContainer = styled(Paper)(({ theme }) => ({ padding: theme.spacing(2), width: 200, })); -const StyledFlagItem = styled(Box)(({ theme }) => ({ +const DataList = styled('dl')(({ theme }) => ({ + margin: 0, +})); + +const DataRow = styled('div', { + shouldForwardProp: (prop) => prop !== 'dataType', +})<{ dataType: 'archived' | 'created' }>(({ theme, dataType }) => ({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', - marginBottom: theme.spacing(0.5), + whiteSpace: 'nowrap', + fontSize: theme.typography.body2.fontSize, + '::before': { + content: '" "', + display: 'inline-block', + height: '.65rem', + aspectRatio: '1/1', + borderRadius: '50%', + + backgroundColor: + dataType === 'archived' + ? theme.palette.charts.A2 + : theme.palette.charts.A1, + }, })); interface CreationArchiveRatioTooltipProps { @@ -28,30 +42,14 @@ interface CreationArchiveRatioTooltipProps { export const CreationArchiveRatioTooltip: FC< CreationArchiveRatioTooltipProps > = ({ tooltip }) => { - const theme = useTheme(); - const colors = getRatioTooltipColors(theme); - if (!tooltip?.dataPoints) { return null; } - const ratioDataPoint = tooltip.dataPoints.find( - (point) => point.dataset.label === 'Flags archived / Flags created', - ); - - if (!ratioDataPoint) { - return null; - } - - const rawData = ratioDataPoint.raw as WeekData; - - if (!rawData) { - return null; - } - + const rawData = tooltip.dataPoints[0].raw as WeekData; const archivedCount = rawData.archivedFlags || 0; const createdCount = rawData.totalCreatedFlags || 0; - const ratio = Math.round(ratioDataPoint.parsed.y as number); + const ratio = Math.round((archivedCount / createdCount) * 100); return ( @@ -65,35 +63,16 @@ export const CreationArchiveRatioTooltip: FC< Ratio {ratio}% - - - - {'● '} - - Flags created - - - {createdCount} - - - - - - - {'● '} - - Flags archived - - - {archivedCount} - - + + +
Flags archived
+
{archivedCount}
+
+ +
Flags created
+
{createdCount}
+
+
); diff --git a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveTooltip.tsx b/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveTooltip.tsx deleted file mode 100644 index 4cb525bfa2..0000000000 --- a/frontend/src/component/insights/componentsChart/CreationArchiveChart/CreationArchiveTooltip.tsx +++ /dev/null @@ -1,77 +0,0 @@ -import type { FC } from 'react'; -import { Box, Paper, Typography, styled, useTheme } from '@mui/material'; -import type { TooltipState } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; -import { ChartTooltipContainer } from 'component/insights/components/LineChart/ChartTooltip/ChartTooltip'; -import { getFlagTypeColors } from './flagTypeColors.ts'; -import type { WeekData } from './types.ts'; - -const StyledTooltipItemContainer = styled(Paper)(({ theme }) => ({ - padding: theme.spacing(2), - width: 240, -})); - -const StyledFlagTypeItem = styled(Box)(({ theme }) => ({ - display: 'flex', - justifyContent: 'space-between', - alignItems: 'center', -})); - -interface CreationArchiveTooltipProps { - tooltip: TooltipState | null; -} - -export const CreationArchiveTooltip: FC = ({ - tooltip, -}) => { - const theme = useTheme(); - - if (!tooltip?.dataPoints) { - return null; - } - - const createdFlagDataPoints = tooltip.dataPoints.filter( - (point) => - point.dataset.label !== 'Archived flags' && - point.dataset.label !== 'Flags archived / Flags created', - ); - - if (createdFlagDataPoints.length === 0) { - return null; - } - - const rawData = createdFlagDataPoints[0]?.raw as WeekData; - - const flagTypeNames = createdFlagDataPoints.map( - (point) => point.dataset.label || '', - ); - - const flagTypeColors = getFlagTypeColors(theme); - - return ( - - - - Flag type - - - - - {'● '} - - Total created: - - - {rawData.totalCreatedFlags} - - - - ); -}; diff --git a/frontend/src/component/insights/componentsChart/CreationArchiveChart/flagTypeColors.ts b/frontend/src/component/insights/componentsChart/CreationArchiveChart/flagTypeColors.ts deleted file mode 100644 index a206b6e8f5..0000000000 --- a/frontend/src/component/insights/componentsChart/CreationArchiveChart/flagTypeColors.ts +++ /dev/null @@ -1,10 +0,0 @@ -// todo (lifecycleGraphs): delete this file -import type { Theme } from '@mui/material'; - -export const getFlagTypeColors = (theme: Theme) => [ - theme.palette.success.border, - theme.palette.success.main, - theme.palette.success.dark, - '#4D8007', - '#7D935E', -];