Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Heatmap] Color with 0% opacity fallbacks to "default" red color #1263

Closed
dej611 opened this issue Jul 21, 2021 · 6 comments · Fixed by #1274
Closed

[Heatmap] Color with 0% opacity fallbacks to "default" red color #1263

dej611 opened this issue Jul 21, 2021 · 6 comments · Fixed by #1274
Assignees
Labels
bug Something isn't working good first issue Good for newcomers :heatmap Heatmap/Swimlane chart related issue Impact:High kibana cross issue Has a Kibana issue counterpart :Lens Kibana Lens related issue

Comments

@dej611
Copy link
Contributor

dej611 commented Jul 21, 2021

Describe the bug
When passing a 8 digits HEX color (classic HEX 6-digits + alpha channel), when the alpha channel is 0 the color seems to be ignored and the fallback red color is used.

To Reproduce

  1. Pass the following colors={} props to the Heatmap component: ["#6092c000", "#6092c000", "#a8bfda", "#ebeff5", "#ecb385", "#e7664c"]
  2. Watch the first 2 buckets get colored in red

Apparently the bug does not appear when using the rgba notation.

Expected behaviour

Transparent color should appear.

Screenshots

Screenshot 2021-07-21 at 15 52 36

Kibana Cross Issues
elastic/kibana#106419

@dej611 dej611 added bug Something isn't working kibana cross issue Has a Kibana issue counterpart :Lens Kibana Lens related issue :heatmap Heatmap/Swimlane chart related issue labels Jul 21, 2021
@nickofthyme
Copy link
Collaborator

Interesting. So you'd expect it to allow a transparent color or prevent transparent color selection?

@dej611
Copy link
Contributor Author

dej611 commented Jul 21, 2021

I think it should allow the transparent color.
But more in general be consistent with the different notations: rgba transparent is accepted but hex transparent is replaced 😅

@markov00 markov00 added the good first issue Good for newcomers label Jul 21, 2021
@markov00 markov00 added this to To do in Heatmap Beta Jul 21, 2021
@nickofthyme
Copy link
Collaborator

Totally! Got it thanks!

@nickofthyme
Copy link
Collaborator

It appears that the getColor function cannot handle hex values color strings with an alpha channel. Might be a related issue.

getColor('#00000000') // => {r: NaN, g: NaN, b: NaN, opacity: 0}
getColor('#000000') // =>  {r: 0, g: 0, b: 0, opacity: 1}

/**
* Returns color as RgbObject or default fallback.
*
* Handles issue in d3-color for hsla and rgba colors with alpha value of `0`
*
* @param cssColorSpecifier
*/
function getColor(cssColorSpecifier: string = ''): RgbObject {
const endRegEx = /,\s*0+(\.0*)?\s*\)$/;
// TODO: make this check more robust
const color: D3RGBColor =
/^(rgba|hsla)\(/i.test(cssColorSpecifier) && endRegEx.test(cssColorSpecifier)
? {
...d3Rgb(cssColorSpecifier.replace(endRegEx, ',1)')),
opacity: 0,
}
: d3Rgb(cssColorSpecifier);
return validateColor(color) ?? defaultColor;
}

@dej611
Copy link
Contributor Author

dej611 commented Jul 26, 2021

Maybe related to this d3/d3-color#52

The only solution I found is to pass thru chroma-js to extract the rgba raw values and use then the d3Rgb call to have the correct result: d3Rgb(chroma(cssColorSpecifier).rgba()).

Otherwise a special detection branch to return the transparent color.

@nickofthyme nickofthyme self-assigned this Jul 28, 2021
@nickofthyme nickofthyme moved this from To do to In progress in Heatmap Beta Jul 28, 2021
@nickofthyme
Copy link
Collaborator

nickofthyme commented Jul 28, 2021

This appears to be broken in 33.0.2 but I cannot reproduce it in our master branch. I'll run a release and make sure the latest release fixes before closing.

https://codesandbox.io/s/lucid-cache-6zlmm?file=/src/App.tsx


UPDATE: It's still bad in 33.1.0 somehow. I'll continue to investigate.

@markov00 markov00 moved this from In progress to To do in Heatmap Beta Jul 28, 2021
@nickofthyme nickofthyme moved this from To do to In progress in Heatmap Beta Jul 28, 2021
Heatmap Beta automation moved this from In progress to Done Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers :heatmap Heatmap/Swimlane chart related issue Impact:High kibana cross issue Has a Kibana issue counterpart :Lens Kibana Lens related issue
Projects
No open projects
Heatmap Beta
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants