Skip to content

Commit 48c1935

Browse files
committed
[#10776] OpenTelemetry > Apply text ellipsis to chart tooltip
1 parent bec250d commit 48c1935

File tree

4 files changed

+53
-44
lines changed

4 files changed

+53
-44
lines changed

web-frontend/src/main/v3/packages/ui/src/components/OpenTelemetry/charts/OpenTelemetryChart.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,21 @@ export const OpenTelemetryChart = ({
6565
return chartDataConfig[dataKey].stack ? uniqueId : undefined;
6666
};
6767

68+
const chartContainerRef = React.useRef<HTMLDivElement>(null);
69+
6870
return (
69-
<ChartContainer config={chartDataConfig} className="w-full h-full p-1.5 aspect-auto">
71+
<ChartContainer
72+
config={chartDataConfig}
73+
className="w-full h-full p-1.5 aspect-auto"
74+
ref={chartContainerRef}
75+
>
7076
<ChartComponent
7177
accessibilityLayer
7278
data={chartData}
7379
margin={{ right: 12 }}
7480
syncId={dashboardId}
7581
>
76-
{OpenTelemetryChartCommon(chartCommonProps)}
82+
{OpenTelemetryChartCommon(chartCommonProps, chartContainerRef)}
7783
{dataKeys.map((key) => (
7884
<ChartChildComponent
7985
key={key}

web-frontend/src/main/v3/packages/ui/src/components/OpenTelemetry/charts/OpenTelemetryChartCommon.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ export interface OpenTelemetryChartCommonProps {
1919
tooltipConfig?: TooltipProps<number, string> & { showTotal?: boolean };
2020
}
2121

22-
export const OpenTelemetryChartCommon = ({
23-
gridConfig,
24-
xAxisConfig,
25-
yAxisConfig,
26-
tooltipConfig,
27-
}: OpenTelemetryChartCommonProps) => {
22+
export const OpenTelemetryChartCommon = (
23+
{ gridConfig, xAxisConfig, yAxisConfig, tooltipConfig }: OpenTelemetryChartCommonProps,
24+
chartContainerRef: React.RefObject<HTMLDivElement>,
25+
) => {
2826
const { showTotal, ...restTooltipConfig } = tooltipConfig || {};
27+
const chartWidth = chartContainerRef?.current?.offsetWidth || 392;
2928

3029
return (
3130
<>
@@ -50,6 +49,7 @@ export const OpenTelemetryChartCommon = ({
5049
labelFormatter={(label) => xAxisConfig?.tickFormatter?.(label, 0) || ''}
5150
formatter={yAxisConfig?.tickFormatter}
5251
showTotal={showTotal}
52+
chartWidth={chartWidth}
5353
/>
5454
}
5555
{...restTooltipConfig}

web-frontend/src/main/v3/packages/ui/src/components/OpenTelemetry/charts/OpenTelemetryChartTooltipContent.tsx

+38-36
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CustomChartTooltipContentProps = Omit<
1212
> & {
1313
formatter?: (value: number, index: number) => string;
1414
showTotal?: boolean;
15+
chartWidth?: number;
1516
};
1617
export interface OpenTelemetryChartTooltipContentProps extends CustomChartTooltipContentProps {}
1718

@@ -25,6 +26,7 @@ export const OpenTelemetryChartTooltipContent = ({
2526
labelFormatter = (label) => format(label, 'HH:mm:ss'),
2627
formatter = (value) => `${value}`,
2728
showTotal = false,
29+
chartWidth,
2830
}: OpenTelemetryChartTooltipContentProps) => {
2931
const renderTooltipLabel = () => {
3032
if (hideLabel || !payload?.length) {
@@ -54,9 +56,14 @@ export const OpenTelemetryChartTooltipContent = ({
5456

5557
return (
5658
active && (
57-
<div className="grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl w-max">
59+
<div
60+
className="grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl"
61+
style={{
62+
maxWidth: chartWidth ? chartWidth * 0.8 : 300,
63+
}}
64+
>
5865
{renderTooltipLabel()}
59-
<div className="grid gap-1.5">
66+
<div className="overflow-hidden">
6067
{tooltipPayload?.map((item, index) => {
6168
const indicatorColor = item.color;
6269
// const nestLabel = payload.length === 1 && indicator !== 'dot';
@@ -65,44 +72,39 @@ export const OpenTelemetryChartTooltipContent = ({
6572
<div
6673
key={item.dataKey}
6774
className={cn(
68-
'flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground',
75+
'flex whitespace-nowrap w-full gap-1.5 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground items-center',
6976
indicator === 'dot' && 'items-center',
7077
)}
7178
>
72-
<>
73-
<div
74-
className={cn(
75-
'shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]',
76-
{
77-
'h-2.5 w-2.5': indicator === 'dot',
78-
'w-1': indicator === 'line',
79-
'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',
80-
'my-0.5': indicator === 'dashed',
81-
},
82-
)}
83-
style={
84-
{
85-
'--color-bg': indicatorColor,
86-
'--color-border': indicatorColor,
87-
} as React.CSSProperties
88-
}
89-
/>
90-
<div
91-
className={cn(
92-
'flex flex-1 justify-between leading-none',
93-
// nestLabel ? 'items-end' : 'items-center',
94-
)}
95-
>
96-
<div className="grid gap-1.5">
97-
<span className="text-muted-foreground">{item.name}</span>
98-
</div>
99-
{item.value && (
100-
<span className="font-mono font-medium tabular-nums text-foreground">
101-
{formatter(item.value as number, index)}
102-
</span>
103-
)}
79+
<div
80+
className={cn('shrink-0 rounded-[2px] border-[--color-border] bg-[--color-bg]', {
81+
'h-2.5 w-2.5': indicator === 'dot',
82+
'w-1 h-3': indicator === 'line',
83+
'w-0 border-[1.5px] border-dashed bg-transparent': indicator === 'dashed',
84+
'my-0.5': indicator === 'dashed',
85+
})}
86+
style={
87+
{
88+
'--color-bg': indicatorColor,
89+
'--color-border': indicatorColor,
90+
} as React.CSSProperties
91+
}
92+
/>
93+
<div
94+
className={cn(
95+
'inline-flex overflow-hidden w-full',
96+
// nestLabel ? 'items-end' : 'items-center',
97+
)}
98+
>
99+
<div className="overflow-hidden text-ellipsis mr-auto">
100+
<span className="text-muted-foreground">{item.name}</span>
104101
</div>
105-
</>
102+
{item.value && (
103+
<span className="font-mono font-medium tabular-nums text-foreground">
104+
{formatter(item.value as number, index)}
105+
</span>
106+
)}
107+
</div>
106108
</div>
107109
);
108110
})}

web-frontend/src/main/v3/packages/ui/src/components/OpenTelemetry/charts/OpenTelemetryTick.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
12
export const OpenTelemetryTick = (props: any) => {
23
const { payload, tickFormatter, x, y } = props;
34
const tickString = tickFormatter?.(payload?.value) || '';

0 commit comments

Comments
 (0)