You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/07/01 03:24:51 UTC

[GitHub] [superset] stephenLYZ commented on a diff in pull request #20555: fix: Respecting max/min opacities, and adding tests.

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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org