Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: fall back to - when no data is available for behavior choropleth…
Browse files Browse the repository at this point in the history
… tooltip (#4258)

Co-authored-by: VWSCoronaDashboard24 <[email protected]>
  • Loading branch information
VWSCoronaDashboard24 and VWSCoronaDashboard24 authored May 19, 2022
1 parent 2fd679b commit 4d02ed5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
13 changes: 9 additions & 4 deletions packages/app/src/domain/behavior/behavior-choropleths-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
VrCollectionBehavior,
} from '@corona-dashboard/common';
import css from '@styled-system/css';
import { isNumber } from 'lodash';
import { useMemo } from 'react';
import { Box } from '~/components/base';
import { ChartTile } from '~/components/chart-tile';
Expand Down Expand Up @@ -164,24 +165,28 @@ function ChoroplethBlock({
}}
minHeight={!isSmallScreen ? 350 : 400}
formatTooltip={(context) => {
const currentComplianceValue =
const currentComplianceValueKey =
`${currentId}_compliance` as keyof VrCollectionBehavior;
const currentSupportValue =
const currentSupportValueKey =
`${currentId}_support` as keyof VrCollectionBehavior;

// Return null when there is no data available to prevent breaking the application when using tab
if (keysWithoutData.includes(currentId)) return null;

const complianceValue =
context.dataItem[currentComplianceValueKey];
const supportValue = context.dataItem[currentSupportValueKey];

return (
<VrBehaviorTooltip
behaviorType={behaviorType}
context={context}
currentMetric={currentId}
currentComplianceValue={
context.dataItem[currentComplianceValue] as number
isNumber(complianceValue) ? complianceValue : null
}
currentSupportValue={
context.dataItem[currentSupportValue] as number
isNumber(supportValue) ? supportValue : null
}
text={text}
/>
Expand Down
24 changes: 15 additions & 9 deletions packages/app/src/domain/behavior/tooltip/vr-behavior-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import { useReverseRouter } from '~/utils/use-reverse-router';
interface VrBehaviorTooltipProps {
context: TooltipData<VrCollectionBehavior>;
currentMetric: BehaviorIdentifier;
currentComplianceValue: number;
currentSupportValue: number;
currentComplianceValue: number | null;
currentSupportValue: number | null;
behaviorType: 'compliance' | 'support';
text: SiteText['pages']['behaviorPage'];
}
Expand All @@ -29,33 +29,39 @@ export function VrBehaviorTooltip({
behaviorType,
text,
}: VrBehaviorTooltipProps) {
const { commonTexts } = useIntl();
const { commonTexts, formatPercentage } = useIntl();
const reverseRouter = useReverseRouter();
const complianceThresholdKey = `${currentMetric}_compliance` as const;
const supportThresholdKey = `${currentMetric}_support` as const;

const complianceFilteredThreshold = getThresholdValue(
thresholds.vr[complianceThresholdKey],
currentComplianceValue
currentComplianceValue || 0
);

const supportFilteredThreshold = getThresholdValue(
thresholds.vr[supportThresholdKey],
currentSupportValue
currentSupportValue || 0
);

const complianceTooltipInfo = (
<TooltipInfo
title={text.nl.tooltip_labels.compliance}
value={currentComplianceValue}
value={
currentComplianceValue
? `${formatPercentage(currentComplianceValue)}%`
: '-'
}
background={complianceFilteredThreshold.color}
/>
);

const supportTooltipInfo = (
<TooltipInfo
title={text.nl.tooltip_labels.support}
value={currentSupportValue}
value={
currentSupportValue ? `${formatPercentage(currentSupportValue)}%` : '-'
}
background={supportFilteredThreshold.color}
/>
);
Expand Down Expand Up @@ -89,7 +95,7 @@ export function VrBehaviorTooltip({

interface TooltipInfoProps {
title: string;
value: number;
value: string;
background: string;
}

Expand All @@ -98,7 +104,7 @@ function TooltipInfo({ title, value, background }: TooltipInfoProps) {
<Box display="flex" alignItems="center" justifyContent="space-between">
{title}
<Box display="flex" alignItems="center">
<BoldText>{`${value}%`}</BoldText>
<BoldText>{value}</BoldText>
<LegendaColorBox backgroundColor={background} />
</Box>
</Box>
Expand Down

0 comments on commit 4d02ed5

Please sign in to comment.