bito-code-review[bot] commented on code in PR #41311:
URL: https://github.com/apache/superset/pull/41311#discussion_r3458823154
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>Semantic duplication in diff</b></div>
<div id="fix">
Lines 114 and 118 call `isFiniteNumber()` directly instead of using the
`hasTrend`, `hasLower`, `hasUpper` variables defined at lines 107-109. This
duplicates the finite check logic and creates inconsistency — line 110
correctly uses these variables, but inner conditions re-check the same values.
Use the existing boolean variables for consistency.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
// and the third part is the lower and upper bounds
if (hasTrend) {
if (value) value += ', ';
value += `ŷ = ${formatter(forecastTrend)}`;
}
if (hasLower && hasUpper) {
````
</div>
</details>
</div>
<small><i>Code Review Run #ff7f95</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]