Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(annotations): Update annotations UI to display label as tooltip on hover #27

Merged
merged 4 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
evalFormula,
extractRecordAnnotations,
formatAnnotationLabel,
formatAnnotationTooltipLabel,
parseAnnotationOpacity,
} from '../utils/annotation';
import { currentSeries, getChartPadding } from '../utils/series';
Expand Down Expand Up @@ -326,16 +327,8 @@ export function transformIntervalAnnotation(
}
: {
show: false,
color: theme.colors.grayscale.dark2,
// @ts-ignore
emphasis: {
fontWeight: 'bold',
show: true,
position: 'insideTop',
verticalAlign: 'top',
backgroundColor: theme.colors.grayscale.light5,
},
};

series.push({
id: `Interval - ${label}`,
type: 'line',
Expand All @@ -351,6 +344,12 @@ export function transformIntervalAnnotation(
} as ItemStyleOption,
label: intervalLabel,
data: intervalData,
tooltip: {
show: !showLabel,
trigger: 'item',
formatter: () =>
formatAnnotationTooltipLabel(name, title, descriptions),
},
},
});
});
Expand Down Expand Up @@ -403,15 +402,6 @@ export function transformEventAnnotation(
}
: {
show: false,
color: theme.colors.grayscale.dark2,
position: 'insideEndTop',
// @ts-ignore
emphasis: {
formatter: (params: CallbackDataParams) => params.name,
fontWeight: 'bold',
show: true,
backgroundColor: theme.colors.grayscale.light5,
},
};

series.push({
Expand All @@ -424,6 +414,12 @@ export function transformEventAnnotation(
lineStyle,
label: eventLabel,
data: eventData,
tooltip: {
show: !showLabel,
trigger: 'item',
formatter: () =>
formatAnnotationTooltipLabel(name, title, descriptions),
},
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ export function formatAnnotationLabel(
return labels.join('\n\n');
}

export function formatAnnotationTooltipLabel(
name?: string,
title?: string,
descriptions: string[] = [],
): string {
const tooltipParts: string[] = [];

const titleParts = [name, title].filter(val => !!val);
if (titleParts.length) {
const titleSection = `<strong>${titleParts.join(' - ')}</strong>`;
tooltipParts.push(titleSection);
}

const filteredDescriptions: string[] = descriptions.filter(
description => !!description,
);
tooltipParts.push(...filteredDescriptions);

return `<div>${tooltipParts.join('<br/>')}</div>`;
}
export function extractAnnotationLabels(
layers: AnnotationLayer[],
data: AnnotationData,
Expand Down
Loading