Skip to content

Commit

Permalink
Minor: improve the UX of profiler graph tooltip (#17892)
Browse files Browse the repository at this point in the history
* Minor: improve the UX of profiler graph tooltip

* addressing comment
  • Loading branch information
ShaileshParmar11 authored Sep 18, 2024
1 parent 4b0b22a commit ec6a662
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jest.mock('../../../common/ErrorWithPlaceholder/ErrorPlaceHolder', () => {
return <div>ErrorPlaceHolder</div>;
});
});
jest.mock('../../../../utils/DataInsightUtils', () => {
return jest.fn().mockImplementation(() => {
return <div>CustomTooltip</div>;
});
});

describe('ProfilerDetailsCard Test', () => {
it('Component should render', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
tooltipFormatter,
updateActiveChartFilter,
} from '../../../../utils/ChartUtils';
import { CustomTooltip } from '../../../../utils/DataInsightUtils';
import { formatDateTime } from '../../../../utils/date-time/DateTimeUtils';
import ErrorPlaceHolder from '../../../common/ErrorWithPlaceholder/ErrorPlaceHolder';
import { ProfilerDetailsCardProps } from '../ProfilerDashboard/profilerDashboard.interface';
import ProfilerLatestValue from '../ProfilerLatestValue/ProfilerLatestValue';
Expand Down Expand Up @@ -94,8 +96,14 @@ const ProfilerDetailsCard: React.FC<ProfilerDetailsCardProps> = ({
type={showYAxisCategory ? 'category' : 'number'}
/>
<Tooltip
formatter={(value: number | string) =>
tooltipFormatter(value, tickFormatter)
content={
<CustomTooltip
dateTimeFormatter={formatDateTime}
timeStampKey="timestamp"
valueFormatter={(value) =>
tooltipFormatter(value, tickFormatter)
}
/>
}
/>
{information.map((info) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ import {
axisTickFormatter,
tooltipFormatter,
} from '../../../../../utils/ChartUtils';
import { getRandomHexColor } from '../../../../../utils/DataInsightUtils';
import {
CustomTooltip,
getRandomHexColor,
} from '../../../../../utils/DataInsightUtils';
import { formatDateTime } from '../../../../../utils/date-time/DateTimeUtils';
import {
showErrorToast,
showSuccessToast,
Expand Down Expand Up @@ -260,9 +264,16 @@ const CustomMetricGraphs = ({
tickFormatter={(props) => axisTickFormatter(props)}
type="number"
/>

<Tooltip
formatter={(value: number | string) =>
tooltipFormatter(value)
content={
<CustomTooltip
dateTimeFormatter={formatDateTime}
timeStampKey="timestamp"
valueFormatter={(value) =>
tooltipFormatter(value)
}
/>
}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ const mockProps = {
},
],
};

jest.mock('../../../../../utils/DataInsightUtils', () => {
return jest.fn().mockImplementation(() => {
return <div>CustomTooltip</div>;
});
});
jest.mock(
'../../../../DataQuality/CustomMetricForm/CustomMetricForm.component',
() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const mockCustomBarChartProp: CustomBarChartProps = {
},
name: 'testChart',
};
jest.mock('../../../utils/DataInsightUtils', () => {
return jest.fn().mockImplementation(() => {
return <div>CustomTooltip</div>;
});
});

describe('CustomBarChart component test', () => {
it('Component should render', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
tooltipFormatter,
updateActiveChartFilter,
} from '../../../utils/ChartUtils';
import { CustomTooltip } from '../../../utils/DataInsightUtils';
import { formatDateTime } from '../../../utils/date-time/DateTimeUtils';
import ErrorPlaceHolder from '../../common/ErrorWithPlaceholder/ErrorPlaceHolder';
import { CustomBarChartProps } from './Chart.interface';

Expand Down Expand Up @@ -77,8 +79,12 @@ const CustomBarChart = ({
tickFormatter={(props) => axisTickFormatter(props, tickFormatter)}
/>
<Tooltip
formatter={(value: number | string) =>
tooltipFormatter(value, tickFormatter)
content={
<CustomTooltip
dateTimeFormatter={formatDateTime}
timeStampKey="timestamp"
valueFormatter={(value) => tooltipFormatter(value, tickFormatter)}
/>
}
/>
{information.map((info) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ const mockCustomBarChartProp: CustomBarChartProps = {
},
name: 'testChart',
};
jest.mock('../../../utils/DataInsightUtils', () => {
return jest.fn().mockImplementation(() => {
return <div>CustomTooltip</div>;
});
});

describe('OperationDateBarChart component test', () => {
it('Component should render', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ import {
ResponsiveContainer,
Scatter,
Tooltip,
TooltipProps,
XAxis,
} from 'recharts';
import { GRAPH_BACKGROUND_COLOR } from '../../../constants/constants';
import { updateActiveChartFilter } from '../../../utils/ChartUtils';
import { formatNumberWithComma } from '../../../utils/CommonUtils';
import {
tooltipFormatter,
updateActiveChartFilter,
} from '../../../utils/ChartUtils';
import { CustomTooltip } from '../../../utils/DataInsightUtils';
import { formatDateTime } from '../../../utils/date-time/DateTimeUtils';
import ErrorPlaceHolder from '../../common/ErrorWithPlaceholder/ErrorPlaceHolder';
import { CustomBarChartProps } from './Chart.interface';

Expand All @@ -38,14 +41,6 @@ const OperationDateBarChart = ({
const { data, information } = chartCollection;
const [activeKeys, setActiveKeys] = useState<string[]>([]);

const tooltipFormatter: TooltipProps<number | string, string>['formatter'] = (
_value,
_label,
data
) => {
return formatNumberWithComma(data.payload.data);
};

const handleClick: LegendProps['onClick'] = (event) => {
setActiveKeys((prevActiveKeys) =>
updateActiveChartFilter(event.dataKey, prevActiveKeys)
Expand Down Expand Up @@ -75,7 +70,16 @@ const OperationDateBarChart = ({
tick={{ fontSize: 12 }}
/>
<CartesianGrid stroke={GRAPH_BACKGROUND_COLOR} />
<Tooltip formatter={tooltipFormatter} />
<Tooltip
content={
<CustomTooltip
dateTimeFormatter={formatDateTime}
timeStampKey="timestamp"
valueFormatter={(value) => tooltipFormatter(value)}
/>
}
/>

{information.map((info) => (
<Bar
barSize={1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export interface ChartFilter {
export interface DataInsightChartTooltipProps extends TooltipProps<any, any> {
isPercentage?: boolean;
isTier?: boolean;
valueFormatter?: (value: number | string, key?: string) => string;
dateTimeFormatter?: (date?: number) => string;
valueFormatter?: (value: number | string, key?: string) => string | number;
timeStampKey?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
startCase,
sumBy,
toNumber,
uniqBy,
} from 'lodash';
import moment from 'moment';
import React from 'react';
Expand Down Expand Up @@ -144,19 +145,21 @@ export const CustomTooltip = (props: DataInsightChartTooltipProps) => {
active,
payload = [],
valueFormatter,
dateTimeFormatter = formatDate,
isPercentage,
timeStampKey = 'timestampValue',
} = props;

if (active && payload && payload.length) {
const timestamp = formatDate(payload[0].payload[timeStampKey] || 0);
const timestamp = dateTimeFormatter(payload[0].payload[timeStampKey] || 0);
const payloadValue = uniqBy(payload, 'dataKey');

return (
<Card
className="custom-data-insight-tooltip"
title={<Typography.Title level={5}>{timestamp}</Typography.Title>}>
<ul className="custom-data-insight-tooltip-container">
{payload.map((entry, index) => (
{payloadValue.map((entry, index) => (
<li
className="d-flex items-center justify-between gap-6 p-b-xss text-sm"
key={`item-${index}`}>
Expand Down

0 comments on commit ec6a662

Please sign in to comment.