Skip to content

Commit

Permalink
feat: Funnel/tooltip-customization (apache#25666)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorbinBullard authored Oct 19, 2023
1 parent da42bf2 commit dfff3c1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
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

0 comments on commit dfff3c1

Please sign in to comment.