diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx
index 9ec2111071b..854d224f20c 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/PopKPI.tsx
@@ -81,6 +81,8 @@ export default function PopKPI(props: PopKPIProps) {
currentTimeRangeFilter,
startDateOffset,
shift,
+ subtitle,
+ subtitleFontSize,
dashboardTimeRange,
} = props;
@@ -140,6 +142,16 @@ export default function PopKPI(props: PopKPIProps) {
margin-bottom: ${theme.gridUnit * 4}px;
`;
+ const SubtitleText = styled.div`
+ ${({ theme }) => `
+ font-family: ${theme.typography.families.sansSerif};
+ font-weight: ${theme.typography.weights.medium};
+ text-align: center;
+ margin-top: -10px;
+ margin-bottom: ${theme.gridUnit * 4}px;
+ `}
+ `;
+
const getArrowIndicatorColor = () => {
if (!comparisonColorEnabled || percentDifferenceNumber === 0) {
return theme.colors.grayscale.base;
@@ -195,31 +207,40 @@ export default function PopKPI(props: PopKPIProps) {
]);
const SYMBOLS_WITH_VALUES = useMemo(
- () => [
- {
- symbol: '#',
- value: prevNumber,
- tooltipText: t('Data for %s', comparisonRange || 'previous range'),
- columnKey: 'Previous value',
- },
- {
- symbol: '△',
- value: valueDifference,
- tooltipText: t('Value difference between the time periods'),
- columnKey: 'Delta',
- },
- {
- symbol: '%',
- value: percentDifferenceFormattedString,
- tooltipText: t('Percentage difference between the time periods'),
- columnKey: 'Percent change',
- },
- ],
+ () =>
+ [
+ {
+ defaultSymbol: '#',
+ value: prevNumber,
+ tooltipText: t('Data for %s', comparisonRange || 'previous range'),
+ columnKey: 'Previous value',
+ },
+ {
+ defaultSymbol: '△',
+ value: valueDifference,
+ tooltipText: t('Value difference between the time periods'),
+ columnKey: 'Delta',
+ },
+ {
+ defaultSymbol: '%',
+ value: percentDifferenceFormattedString,
+ tooltipText: t('Percentage difference between the time periods'),
+ columnKey: 'Percent change',
+ },
+ ].map(item => {
+ const config = props.columnConfig?.[item.columnKey];
+ return {
+ ...item,
+ symbol: config?.displayTypeIcon === false ? '' : item.defaultSymbol,
+ label: config?.customColumnName || item.columnKey,
+ };
+ }),
[
comparisonRange,
prevNumber,
valueDifference,
percentDifferenceFormattedString,
+ props.columnConfig,
],
);
@@ -250,6 +271,15 @@ export default function PopKPI(props: PopKPIProps) {
)}
+ {subtitle && (
+
+ {subtitle}
+
+ )}
{visibleSymbols.length > 0 && (
{visibleSymbols.map((symbol_with_value, index) => (
- 0 ? backgroundColor : defaultBackgroundColor
- }
- textColor={index > 0 ? textColor : defaultTextColor}
- >
- {symbol_with_value.symbol}
-
- {symbol_with_value.value}
+ {symbol_with_value.symbol && (
+ 0 ? backgroundColor : defaultBackgroundColor
+ }
+ textColor={index > 0 ? textColor : defaultTextColor}
+ >
+ {symbol_with_value.symbol}
+
+ )}
+ {symbol_with_value.value}{' '}
+ {props.columnConfig?.[symbol_with_value.columnKey]
+ ?.customColumnName || ''}
))}
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/controlPanel.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/controlPanel.ts
index bb285a70b0c..63c126216b2 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/controlPanel.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/controlPanel.ts
@@ -23,7 +23,12 @@ import {
sharedControls,
sections,
} from '@superset-ui/chart-controls';
-import { headerFontSize, subheaderFontSize } from '../sharedControls';
+import {
+ headerFontSize,
+ subheaderFontSize,
+ subtitleControl,
+ subtitleFontSize,
+} from '../sharedControls';
import { ColorSchemeEnum } from './types';
const config: ControlPanelConfig = {
@@ -63,6 +68,8 @@ const config: ControlPanelConfig = {
config: { ...headerFontSize.config, default: 0.2 },
},
],
+ [subtitleControl],
+ [subtitleFontSize],
[
{
...subheaderFontSize,
@@ -120,7 +127,11 @@ const config: ControlPanelConfig = {
[GenericDataType.Numeric]: [
{
tab: t('General'),
- children: [['visible']],
+ children: [
+ ['customColumnName'],
+ ['displayTypeIcon'],
+ ['visible'],
+ ],
},
],
},
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
index 9adf3e1fba7..a40f18b24c3 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/transformProps.ts
@@ -89,6 +89,8 @@ export default function transformProps(chartProps: ChartProps) {
comparisonColorScheme,
comparisonColorEnabled,
percentDifferenceFormat,
+ subtitle = '',
+ subtitleFontSize,
columnConfig,
} = formData;
const { data: dataA = [] } = queriesData[0];
@@ -183,6 +185,8 @@ export default function transformProps(chartProps: ChartProps) {
valueDifference,
percentDifferenceFormattedString: percentDifference,
boldText,
+ subtitle,
+ subtitleFontSize,
headerFontSize: getHeaderFontSize(headerFontSize),
subheaderFontSize: getComparisonFontSize(subheaderFontSize),
headerText,
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts
index 8aef509088d..bd12d1a1540 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberPeriodOverPeriod/types.ts
@@ -35,6 +35,8 @@ export interface PopKPIStylesProps {
export type TableColumnConfig = {
visible?: boolean;
+ customColumnName?: string;
+ displayTypeIcon?: boolean;
};
interface PopKPICustomizeProps {
@@ -61,6 +63,8 @@ export type PopKPIProps = PopKPIStylesProps &
metricName: string;
bigNumber: string;
prevNumber: string;
+ subtitle?: string;
+ subtitleFontSize: number;
valueDifference: string;
percentDifferenceFormattedString: string;
compType: string;
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/controlPanel.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/controlPanel.ts
index b466ae04f17..f9b53ccaacf 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/controlPanel.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/controlPanel.ts
@@ -24,7 +24,11 @@ import {
Dataset,
getStandardizedControls,
} from '@superset-ui/chart-controls';
-import { headerFontSize, subheaderFontSize } from '../sharedControls';
+import {
+ headerFontSize,
+ subtitleFontSize,
+ subtitleControl,
+} from '../sharedControls';
export default {
controlPanelSections: [
@@ -33,32 +37,13 @@ export default {
expanded: true,
controlSetRows: [['metric'], ['adhoc_filters']],
},
- {
- label: t('Display settings'),
- expanded: true,
- tabOverride: 'data',
- controlSetRows: [
- [
- {
- name: 'subheader',
- config: {
- type: 'TextControl',
- label: t('Subheader'),
- renderTrigger: true,
- description: t(
- 'Description text that shows up below your Big Number',
- ),
- },
- },
- ],
- ],
- },
{
label: t('Chart Options'),
expanded: true,
controlSetRows: [
[headerFontSize],
- [subheaderFontSize],
+ [subtitleControl],
+ [subtitleFontSize],
['y_axis_format'],
['currency_format'],
[
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts
index 757ecd3e612..c673ebd9f5e 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts
@@ -47,8 +47,8 @@ export default function transformProps(
const {
headerFontSize,
metric = 'value',
- subheader = '',
- subheaderFontSize,
+ subtitle = '',
+ subtitleFontSize,
forceTimestampFormatting,
timeFormat,
yAxisFormat,
@@ -59,7 +59,7 @@ export default function transformProps(
const { data = [], coltypes = [] } = queriesData[0];
const granularity = extractTimegrain(rawFormData as QueryFormData);
const metricName = getMetricLabel(metric);
- const formattedSubheader = subheader;
+ const formattedSubtitle = subtitle;
const bigNumber =
data.length === 0 ? null : parseMetricValue(data[0][metricName]);
@@ -105,8 +105,10 @@ export default function transformProps(
bigNumber,
headerFormatter,
headerFontSize,
- subheaderFontSize,
- subheader: formattedSubheader,
+ subtitleFontSize,
+ subtitle: formattedSubtitle,
+ subheader: '',
+ subheaderFontSize: subtitleFontSize,
onContextMenu,
refs,
colorThresholdFormatters,
diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx
index d95ae633af0..fddebc93a59 100644
--- a/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx
+++ b/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberViz.tsx
@@ -229,6 +229,40 @@ class BigNumberVis extends PureComponent
{
return null;
}
+ renderSubtitle(maxHeight: number) {
+ const { subtitle, width } = this.props;
+ let fontSize = 0;
+
+ if (subtitle) {
+ const container = this.createTemporaryContainer();
+ document.body.append(container);
+ try {
+ fontSize = computeMaxFontSize({
+ text: subtitle,
+ maxWidth: width * 0.9,
+ maxHeight,
+ className: 'subtitle-line',
+ container,
+ });
+ } finally {
+ container.remove();
+ }
+
+ return (
+
+ {subtitle}
+
+ );
+ }
+ return null;
+ }
+
renderTrendline(maxHeight: number) {
const { width, trendLineData, echartOptions, refs } = this.props;
@@ -282,6 +316,7 @@ class BigNumberVis extends PureComponent {
kickerFontSize,
headerFontSize,
subheaderFontSize,
+ subtitleFontSize,
} = this.props;
const className = this.getClassName();
@@ -306,6 +341,9 @@ class BigNumberVis extends PureComponent {
subheaderFontSize * (1 - PROPORTION.TRENDLINE) * height,
),
)}
+ {this.renderSubtitle(
+ Math.ceil(subtitleFontSize * (1 - PROPORTION.TRENDLINE) * height),
+ )}
{this.renderTrendline(chartHeight)}
@@ -318,6 +356,7 @@ class BigNumberVis extends PureComponent