stephenLYZ commented on code in PR #20555:
URL: https://github.com/apache/superset/pull/20555#discussion_r911585507


##########
superset-frontend/packages/superset-ui-chart-controls/src/utils/getColorFormatters.ts:
##########
@@ -37,16 +37,24 @@ export const getOpacity = (
   extremeValue: number,
   minOpacity = MIN_OPACITY_BOUNDED,
   maxOpacity = MAX_OPACITY,
-) =>
-  extremeValue === cutoffPoint
-    ? maxOpacity
-    : round(
-        Math.abs(
-          ((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
-            (value - cutoffPoint),
-        ) + minOpacity,
-        2,
-      );
+) => {
+  if (extremeValue === cutoffPoint) {
+    return maxOpacity;
+  }
+  const result = round(
+    Math.abs(
+      ((maxOpacity - minOpacity) / (extremeValue - cutoffPoint)) *
+        (value - cutoffPoint),
+    ) + minOpacity,
+    2,
+  );
+
+  if (result < minOpacity) {
+    return minOpacity;
+  }
+
+  return result > maxOpacity ? maxOpacity : result;

Review Comment:
   We could probably use one line of code
   ```javascript
   // Make sure that the opacity is within the bounds
   return Math.min(Math.max(result, minOpacity), maxOpacity)
   ```



-- 
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]

Reply via email to