zhaoyongjie commented on code in PR #19587:
URL: https://github.com/apache/superset/pull/19587#discussion_r845762914
##########
superset-frontend/packages/superset-ui-core/src/color/utils.ts:
##########
@@ -75,7 +75,16 @@ export function getAnalogousColors(colors: string[],
results: number) {
}
export function addAlpha(color: string, opacity: number): string {
- // coerce values so ti is between 0 and 1.
- const rounded = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
- return color + rounded.toString(16).toUpperCase();
+ // opacity value should be between 0 and 1.
+ if (opacity > 1 || opacity < 0) {
+ throw new Error(
+ `The alpha channel should between 0 and 1, but got: ${opacity}`,
+ );
+ }
+ // the alpha value is between 00 - FF
+ const alpha = `0${Math.round(opacity * 255)
+ .toString(16)
+ .toUpperCase()}`.slice(-2);
+
+ return `${color}${alpha}`;
Review Comment:
bycatch: fix codes coverage.
--
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]