rusackas commented on code in PR #41311:
URL: https://github.com/apache/superset/pull/41311#discussion_r3459832386
##########
superset-frontend/plugins/plugin-chart-echarts/src/utils/forecast.ts:
##########
@@ -98,15 +98,24 @@ export const formatForecastTooltipSeries = ({
}): string[] => {
const name = `${marker}${sanitizeHtml(seriesName)}`;
let value = typeof observation === 'number' ? formatter(observation) : '';
- if (forecastTrend || forecastLower || forecastUpper) {
+ // Use finite-number checks rather than truthiness so that legitimate
+ // zero values (e.g. a forecast that crosses zero, or a confidence bound of
+ // exactly 0) are not dropped from the tooltip, while non-finite values
+ // (NaN/Infinity) are still excluded.
+ const isFiniteNumber = (val: number | undefined): val is number =>
+ typeof val === 'number' && Number.isFinite(val);
+ const hasTrend = isFiniteNumber(forecastTrend);
+ const hasLower = isFiniteNumber(forecastLower);
+ const hasUpper = isFiniteNumber(forecastUpper);
+ if (hasTrend || hasLower || hasUpper) {
// forecast values take the form of "20, y = 30 (10, 40)"
// where the first part is the observation, the second part is the
forecast trend
// and the third part is the lower and upper bounds
- if (forecastTrend) {
+ if (isFiniteNumber(forecastTrend)) {
if (value) value += ', ';
value += `ŷ = ${formatter(forecastTrend)}`;
}
- if (forecastLower && forecastUpper) {
+ if (isFiniteNumber(forecastLower) && isFiniteNumber(forecastUpper)) {
Review Comment:
Yep, cleaner — swapped both inner checks to reuse
`hasTrend`/`hasLower`/`hasUpper`. Thanks.
--
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]