Bob124 opened a new issue, #45949:
URL: https://github.com/apache/superset/issues/45949
### Bug description
### Summary
On the three Big Number charts (Big Number, Big Number with Trendline, Big
Number Period over Period),
the chart-level "Number format" control (y_axis_format) has no effect when
the saved metric used by the
chart already has a D3 format defined on the dataset. The dataset metric
format always wins, which is the
opposite priority of every other chart and is a regression from 4.0.2.
### Steps to reproduce
1. Create (or pick) a dataset and define a saved metric, e.g. `count(*)`,
with D3 Format = `$,.2f`
(Dataset -> Edit -> Metrics -> D3 Format).
2. Create a "Big Number" chart using that metric. The value renders as
`$1,234.00`.
3. In the chart editor, set Chart Options -> Number format (y_axis_format)
to a clearly different format,
e.g. `,d` or `.2%`.
4. Click "Update chart".
Expected behavior:
The rendered value uses the format selected in the chart control (`,d` =>
`1,234`), because an explicit
chart-level setting should override the dataset-level metric format. This is
how it worked in 4.0.2 and
how it still works for other ECharts charts (Pie, Gauge, Treemap, Funnel,
Heatmap, Sunburst), which pass
only the control value to getValueFormatter.
Actual behavior:
The value keeps the dataset metric format (`$1,234.00`) and the chart
control is silently ignored. Changing
the control only works after clearing the D3 format on the dataset metric.
### Root cause
BigNumberTotal/transformProps.ts:
const numberFormatter = getValueFormatter(
metric,
currencyFormats,
columnFormats,
metricEntry?.d3format || yAxisFormat, // <-- dataset metric format
takes precedence
...
);
The same pattern exists in BigNumberWithTrendline/transformProps.ts and
BigNumberPeriodOverPeriod/transformProps.ts.
In 4.0.2 the 4th argument was just `yAxisFormat`:
https://github.com/apache/superset/blob/4.0.2/superset-frontend/plugins/plugin-chart-echarts/src/BigNumber/BigNumberTotal/transformProps.ts
Inside getValueFormatter the 4th argument is used as `d3Format ??
savedColumnFormats[metric]`
(packages/superset-ui-core/src/currency-format/utils.ts), so passing
metricEntry?.d3format first makes
it unbeatable from the UI. Note that y_axis_format defaults to SMART_NUMBER
(a truthy string), so the
fallback to yAxisFormat basically never happens.
### Suggested fix
Restore the control's precedence, e.g. only fall back to the metric format
while the control is untouched:
const numberFormat =
yAxisFormat && yAxisFormat !== DEFAULT_NUMBER_FORMAT
? yAxisFormat
: metricEntry?.d3format || yAxisFormat;
or simply pass `yAxisFormat` as in 4.0.2 / the other ECharts plugins.
Happy to open a PR if the maintainers agree on the expected precedence.
### Screenshots/recordings
_No response_
### Superset version
master / latest-dev
### Python version
3.11
### Node version
16
### Browser
Chrome
### Additional context
_No response_
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to
my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug
report.
- [x] I have checked Superset's logs for errors and if I found a relevant
Python stacktrace, I included it here as text in the "additional context"
section.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]