mirror of
https://github.com/apache/superset.git
synced 2026-04-23 01:55:09 +00:00
feat: Implement currencies formatter for saved metrics (#24517)
This commit is contained in:
committed by
GitHub
parent
e402c94a9f
commit
83ff4cd86a
@@ -19,9 +19,9 @@
|
||||
import {
|
||||
ColorFormatters,
|
||||
getColorFormatters,
|
||||
Metric,
|
||||
} from '@superset-ui/chart-controls';
|
||||
import {
|
||||
getNumberFormatter,
|
||||
GenericDataType,
|
||||
getMetricLabel,
|
||||
extractTimegrain,
|
||||
@@ -30,12 +30,20 @@ import {
|
||||
import { BigNumberTotalChartProps, BigNumberVizProps } from '../types';
|
||||
import { getDateFormatter, parseMetricValue } from '../utils';
|
||||
import { Refs } from '../../types';
|
||||
import { getValueFormatter } from '../../utils/valueFormatter';
|
||||
|
||||
export default function transformProps(
|
||||
chartProps: BigNumberTotalChartProps,
|
||||
): BigNumberVizProps {
|
||||
const { width, height, queriesData, formData, rawFormData, hooks } =
|
||||
chartProps;
|
||||
const {
|
||||
width,
|
||||
height,
|
||||
queriesData,
|
||||
formData,
|
||||
rawFormData,
|
||||
hooks,
|
||||
datasource: { currencyFormats = {}, columnFormats = {} },
|
||||
} = chartProps;
|
||||
const {
|
||||
headerFontSize,
|
||||
metric = 'value',
|
||||
@@ -54,7 +62,7 @@ export default function transformProps(
|
||||
const bigNumber =
|
||||
data.length === 0 ? null : parseMetricValue(data[0][metricName]);
|
||||
|
||||
let metricEntry;
|
||||
let metricEntry: Metric | undefined;
|
||||
if (chartProps.datasource?.metrics) {
|
||||
metricEntry = chartProps.datasource.metrics.find(
|
||||
metricItem => metricItem.metric_name === metric,
|
||||
@@ -67,12 +75,19 @@ export default function transformProps(
|
||||
metricEntry?.d3format,
|
||||
);
|
||||
|
||||
const numberFormatter = getValueFormatter(
|
||||
metric,
|
||||
currencyFormats,
|
||||
columnFormats,
|
||||
yAxisFormat,
|
||||
);
|
||||
|
||||
const headerFormatter =
|
||||
coltypes[0] === GenericDataType.TEMPORAL ||
|
||||
coltypes[0] === GenericDataType.STRING ||
|
||||
forceTimestampFormatting
|
||||
? formatTime
|
||||
: getNumberFormatter(yAxisFormat ?? metricEntry?.d3format ?? undefined);
|
||||
: numberFormatter;
|
||||
|
||||
const { onContextMenu } = hooks;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user