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
GaugePanel: Setting the neutral-point of a gauge #53989
Conversation
If min and max of a gauge panel are opposite numbers, e.g. min=-500, max=500 then the neutral point of the gauge is put at 12 o'clock. Negative values are plotted to the left side, positive values to the right side. See Gitlab discussions #38273
remove unneded const angularModules
I'm happy to see this feature. Though, limiting to inverse min/max scenario seems arbitrary. Why not expose a setting for "fill from zero" regardless of the angle of the zero point? Perhaps this should even be default behavior of a gauge. I can't think of an example where painting from a negative min to a positive value would be desired since a gauge is meant to show relative magnitudes, which implies painting from zero to represent magnitude correctly. |
@sfranzis thank you for this contribution! I've moved this to the to the User Essentials dev project for review and comments |
An additional setting would require changes on the data model and more. For this I'm not yet deep enough in the code. This is my first change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some phrasing changes that could make the docs addition clearer and require less domain knowledge to apply.
|
||
Adjust various options. | ||
|
||
- **Min/Max -** If the values of min and max are additive inverse numbers (e.g. min=-500, max=500), then the neutral point of the gauge is put at 12 o'clock. Negative values are plotted to the left side, positive values to the right side. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aiming for clarity with plainer language here, while understanding the limitations in the comments:
- **Min/Max -** If the values of min and max are additive inverse numbers (e.g. min=-500, max=500), then the neutral point of the gauge is put at 12 o'clock. Negative values are plotted to the left side, positive values to the right side. | |
- **Min/Max -** Define a range to gauge, with the neutral point plotted at the center of the gauge. Values higher or lower than the neutral point plotted to the left or right of center, respectfully. The values of min and max must be opposite numbers; for instance, if the min is -500, the max must be 500. |
c1, // line color | ||
1, // line width | ||
c1, // fill color | ||
blur); | ||
} | ||
|
||
|
||
/** | ||
* if gauge min is negative and has the absolute value of min and max are the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* if gauge min is negative and has the absolute value of min and max are the same | |
* if gauge min is negative and the absolute value of min and max are the same |
## Standard options | ||
|
||
Adjust various options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With only one setting listed, "various options" doesn't work well here. If I understand the comments, this is changing a default behavior of gauges, so would "Adjust default gauge behaviors" work instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @gguillotte-grafana thanks for your review.
/** | ||
* if gauge min is negative and has the absolute value of min and max are the same | ||
* then calculate a1 and a2 in a way, that zero is at 12 o'clock | ||
* | ||
* @method calculateAnglesForGauge | ||
* @param {Object} gaugeOptionsi the options of the gauge | ||
* @returns {Object} | ||
*/ | ||
function calculateAnglesForGauge(gaugeOptionsi, layout, data) { | ||
let angles = {}; | ||
var setNorth = (gaugeOptionsi.gauge.min + gaugeOptionsi.gauge.max) == 0.0 | ||
|
||
angles.a1 = gaugeOptionsi.gauge.startAngle; | ||
angles.a2 = calculateAngle(gaugeOptionsi, layout, data); | ||
|
||
if(setNorth && angles.a2<=1.5) { | ||
angles.a1 = angles.a2; | ||
angles.a2 = 1.5; | ||
} | ||
if(setNorth && angles.a2>1.5) { | ||
angles.a1 = 1.5; | ||
} | ||
|
||
return angles; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @sfranzis thank you for contributing to Grafana! 🎉
I have to agree with the sentence "limiting to inverse min/max scenario seems arbitrary", I think it would end up being almost a "hidden feature" that if you set min and max to the same absolute value you get this extra feature on the Gauges that have negative numbers.
I think ideally this should always happen if the minimum of the gauge is < 0, and then we should be able to see some kind of indication of where 0 is as well, maybe with a dotted line or with the actual number 0 next to that point.
So I feel like in order for us to merge this it would need a little bit more work. This is my suggestion for what this function should look like:
/**
* Calcualte the angles for the gauge, depending on if there are
* negative numbers or not.
*
* @method calculateAnglesForGauge
* @param {Object} gaugeOptionsi the options of the gauge
* @param {Number} data the value of the gauge
* @returns {Object}
*/
function calculateAnglesForGauge(gaugeOptionsi, layout, data) {
let angles = {};
var hasNegative = gaugeOptionsi.gauge.min < 0.0
var isNegative = data < 0.0
if (hasNegative) {
if (isNegative) {
angles.a1 = calculateAngle(gaugeOptionsi, layout, data);
angles.a2 = calculateAngle(gaugeOptionsi, layout, 0.0);
} else {
angles.a1 = calculateAngle(gaugeOptionsi, layout, 0.0);
angles.a2 = calculateAngle(gaugeOptionsi, layout, data);
}
} else {
angles.a1 = gaugeOptionsi.gauge.startAngle;
angles.a2 = calculateAngle(gaugeOptionsi, layout, data);
}
return angles;
}
What do you think? Then the only thing left would be to find a way to represent where the 0 is when the min is negative. Would you like to give that a go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @JoaoSilvaGrafana thanks for your suggestion. I'm fine with it. 👍
Thanks for the pull request. Just my 2 cents: I would prefer to be able to override the neutral point to set it to any arbitrary value. The current implementation would be fine for the default, i.e. the neutral point is always at min, unless the user overrides it. |
Hey @sfranzis sorry for the delay, been on holiday 😄
Thanks for working on this! |
Hey @LarsStegman , just trying to understand your point. Could you give an example of what you expected to happen with some values? By neutral point do you mean the point in the middle of the Gauge? |
Hi, I would like the "zero point" settable. For example:
The gauge would then be drawn from -1 to 3 This could be useful to show how far away from a setpoint the current value is, e.g. a speed setting and the actual speed. |
Oh fantastic! |
Ok, I will do it later today when I have no disturbance. :-) |
Hey @JoaoSilvaGrafana, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this! I showed your work to some colleagues and they really like the NumberInput option you created! 🎉 Just left some comments on it
I'm not really sure how to implement overrides no... I had a quick look around and couldn't get it to work properly. I think what we have right now in this PR is already really valuable for us to merge it, and then if you figure out the overrides you can do it as a separate PR what do you think? 😄 |
Go for it 👍 I'm looking forward to seeing the current change in an official release. 😊 |
@JoaoSilvaGrafana found the override thing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this, we really appreciate all the work you've put into it 👏
(cherry picked from commit e823a90)
What this PR does / why we need it:
The neutral or zero point of a gauge is at the left of the panel. When I set the range from e.g. Min=-5 to Max = 5 then the display of negative values looks not natural.
I would like the neutral-point to be configurable in the standard field options (where we have Min, Max, ...).
Example use case: a solar battery inverter, which shows positive values when charging and negative values when discharging.
Fixes #38273
Usage: If min and max of a gauge panel are additive inverse numbers, e.g. min=-500, max=500 then the neutral point of the gauge is put at 12 o'clock. Negative values are plotted to the left side, positive values to the right side.