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

[Lens] metric bar miscolored when max is 0 #172331

Open
drewdaemon opened this issue Nov 30, 2023 · 4 comments
Open

[Lens] metric bar miscolored when max is 0 #172331

drewdaemon opened this issue Nov 30, 2023 · 4 comments
Labels
bug Fixes for quality problems that affect the customer experience Feature:Lens impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. Team:Visualizations Visualization editors, elastic-charts and infrastructure

Comments

@drewdaemon
Copy link
Contributor

STR

  • enable dynamic coloring (status palette for example)
  • add max dimension (defaults to 0)

Result: bar is green
Expected: bar is red

Screen.Recording.2023-11-30.at.3.25.18.PM.mov
@drewdaemon drewdaemon added bug Fixes for quality problems that affect the customer experience Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Nov 30, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@nickofthyme
Copy link
Contributor

I think this is the same as #172297 😆

@drewdaemon
Copy link
Contributor Author

drewdaemon commented Dec 1, 2023

Great minds think alike! But, in #172297 the bars disappear, right? Whereas here, they're getting an incorrect palette color. You think it's still the same underlying cause?

@nickofthyme
Copy link
Contributor

nickofthyme commented Dec 1, 2023

Are you using color ranges as percentage value? If so, does the issue go away if you set the max value to the default? Otherwise do you know what triggers with behavior other than using the dynamic color ranges?

Update: Discuss this with Drew offline and we found this to be a related but separate issue to #172297. This issue is concerning bad color scaling of max values around 0. Both likely due to code here...

/**
* When stops are empty, it is assumed a predefined palette, so colors are distributed uniformly in the whole data range
* When stops are passed, then rangeMin/rangeMax are used as reference for user defined limits:
* continuity is defined over rangeMin/rangeMax, not these stops values (rangeMin/rangeMax are computed from user's stop inputs)
*/
export function workoutColorForValue(
value: number | undefined,
params: CustomPaletteState,
minMax: { min: number; max: number }
) {
if (value == null) {
return;
}
const { colors, stops, range = 'percent', continuity = 'above', rangeMax, rangeMin } = params;
const isMinContinuity = checkIsMinContinuity(continuity);
const isMaxContinuity = checkIsMaxContinuity(continuity);
// ranges can be absolute numbers or percentages
// normalized the incoming value to the same format as range to make easier comparisons
const normalizedValue = getNormalizedValueByRange(value, params, minMax);
const [min, max]: [number, number] = range === 'percent' ? [0, 100] : [minMax.min, minMax.max];
const minRange = getNormalizedMinRange({ stops, rangeMin }, isMinContinuity, min);
const maxRange = getNormalizedMaxRange({ stops, colors, rangeMax }, isMaxContinuity, [min, max]);
const comparisonFn = (v: number, threshold: number) => v - threshold;
if (comparisonFn(normalizedValue, minRange) < 0) {
if (isMinContinuity) {
return colors[0];
}
return;
}
if (comparisonFn(normalizedValue, maxRange) > 0) {
if (isMaxContinuity) {
return colors[colors.length - 1];
}
return;
}
if (stops.length) {
return findColorsByStops(normalizedValue, comparisonFn, colors, stops);
}
return findColorSegment(normalizedValue, comparisonFn, colors, min, max);
}

@nickofthyme nickofthyme added the impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Lens impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. Team:Visualizations Visualization editors, elastic-charts and infrastructure
Projects
None yet
Development

No branches or pull requests

4 participants