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: Funnel/tooltip-customization #25666

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -32,7 +32,8 @@ import {
import { DEFAULT_FORM_DATA, EchartsFunnelLabelTypeType } from './types';
import { legendSection } from '../controls';

const { labelType, numberFormat, showLabels } = DEFAULT_FORM_DATA;
const { labelType, numberFormat, showLabels, defaultTooltipLabel } =
DEFAULT_FORM_DATA;

const funnelLegendSection = [...legendSection];
funnelLegendSection.splice(2, 1);
Expand Down Expand Up @@ -84,7 +85,7 @@ const config: ControlPanelConfig = {
name: 'label_type',
config: {
type: 'SelectControl',
label: t('Label Type'),
label: t('Label Contents'),
default: labelType,
renderTrigger: true,
choices: [
Expand All @@ -101,7 +102,33 @@ const config: ControlPanelConfig = {
t('Category, Value and Percentage'),
],
],
description: t('What should be shown on the label?'),
description: t('What should be shown as the label'),
},
},
],
[
{
name: 'tooltip_label_type',
config: {
type: 'SelectControl',
label: t('Tooltip Contents'),
default: defaultTooltipLabel,
renderTrigger: true,
choices: [
[EchartsFunnelLabelTypeType.Key, t('Category Name')],
[EchartsFunnelLabelTypeType.Value, t('Value')],
[EchartsFunnelLabelTypeType.Percent, t('Percentage')],
[EchartsFunnelLabelTypeType.KeyValue, t('Category and Value')],
[
EchartsFunnelLabelTypeType.KeyPercent,
t('Category and Percentage'),
],
[
EchartsFunnelLabelTypeType.KeyValuePercent,
t('Category, Value and Percentage'),
],
],
description: t('What should be shown as the tooltip label'),
},
},
],
Expand Down Expand Up @@ -132,6 +159,18 @@ const config: ControlPanelConfig = {
},
},
],
[
{
name: 'show_tooltip_labels',
config: {
type: 'CheckboxControl',
label: t('Show Tooltip Labels'),
renderTrigger: true,
default: showLabels,
description: t('Whether to display the tooltip labels.'),
},
},
],
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function formatFunnelLabel({
const name = sanitizeName ? sanitizeHtml(rawName) : rawName;
const formattedValue = numberFormatter(value as number);
const formattedPercent = percentFormatter((percent as number) / 100);

switch (labelType) {
case EchartsFunnelLabelTypeType.Key:
return name;
Expand Down Expand Up @@ -93,7 +94,6 @@ export default function transformProps(
queriesData,
width,
theme,
inContextMenu,
emitCrossFilters,
datasource,
} = chartProps;
Expand All @@ -107,13 +107,16 @@ export default function transformProps(
gap,
labelLine,
labelType,
tooltipLabelType,
legendMargin,
legendOrientation,
legendType,
metric = '',
numberFormat,
currencyFormat,
showLabels,
inContextMenu,
showTooltipLabels,
showLegend,
sliceId,
}: EchartsFunnelFormData = {
Expand Down Expand Up @@ -227,13 +230,13 @@ export default function transformProps(
},
tooltip: {
...getDefaultTooltip(refs),
show: !inContextMenu,
show: !inContextMenu && showTooltipLabels,
trigger: 'item',
formatter: (params: any) =>
formatFunnelLabel({
params,
numberFormatter,
labelType: EchartsFunnelLabelTypeType.KeyValuePercent,
labelType: tooltipLabelType,
}),
},
legend: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export type EchartsFunnelFormData = QueryFormData &
groupby: QueryFormData[];
labelLine: boolean;
labelType: EchartsFunnelLabelTypeType;
tooltipLabelType: EchartsFunnelLabelTypeType;
metric?: string;
showLabels: boolean;
showTooltipLabels: boolean;
numberFormat: string;
gap: number;
sort: 'descending' | 'ascending' | 'none' | undefined;
Expand All @@ -62,6 +64,7 @@ export const DEFAULT_FORM_DATA: EchartsFunnelFormData = {
groupby: [],
labelLine: false,
labelType: EchartsFunnelLabelTypeType.Key,
defaultTooltipLabel: EchartsFunnelLabelTypeType.KeyValuePercent,
legendOrientation: LegendOrientation.Top,
legendType: LegendType.Scroll,
numberFormat: 'SMART_NUMBER',
Expand Down
Loading