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

GaugePanel: Setting the neutral-point of a gauge #53989

Merged
merged 33 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2073179
GraphPanel: Setting the neutral-point of a gauge
sfranzis Aug 20, 2022
aac8708
GraphPanel: Setting the neutral-point of a gauge
sfranzis Aug 20, 2022
a3e0a9d
Update gauge docs
sfranzis Aug 20, 2022
d1312e2
Setting the neutral-point of a gauge. make it default behaviour and a…
sfranzis Oct 15, 2022
329e299
Setting the neutral-point of a gauge. make it default behaviour and a…
sfranzis Oct 15, 2022
7796d46
Remove hint to set min/max as the neutral point is now set automatically
sfranzis Oct 15, 2022
5cafa46
Merge branch 'grafana:main' into #38273
sfranzis Oct 15, 2022
35ab692
Merge branch 'grafana:main' into #38273
sfranzis Oct 15, 2022
5204857
Merge branch 'grafana:main' into #38273
sfranzis Oct 16, 2022
b31bbdb
zero option
sfranzis Nov 10, 2022
de5e0bd
Revert "zero option"
sfranzis Nov 10, 2022
bb23215
zero option
sfranzis Nov 10, 2022
2cc9021
Merge branch 'grafana:main' into #38273
sfranzis Nov 10, 2022
755c8c9
Merge branch 'grafana:main' into feature/zero-option
sfranzis Nov 10, 2022
4931892
threshold value for zero
sfranzis Nov 10, 2022
236a854
fix merge
sfranzis Nov 10, 2022
59f4c0c
remove space
sfranzis Nov 10, 2022
4d0b736
add newline at eof
sfranzis Nov 10, 2022
24d295a
remove category
sfranzis Nov 10, 2022
2b0525c
remove space
sfranzis Nov 10, 2022
2a9e5ea
remove newline
sfranzis Nov 10, 2022
441c898
add newline
sfranzis Nov 10, 2022
c85d7ca
draw neutral threshold value
sfranzis Nov 10, 2022
264b4fe
draw neutral threshold value
sfranzis Nov 11, 2022
bf3ffda
Merge branch 'feature/zero-option' of https://github.com/sfranzis/gra…
sfranzis Nov 11, 2022
8b44b1f
Make neutral value configurable
sfranzis Nov 15, 2022
586f7d8
fixing merge glitch
sfranzis Nov 15, 2022
80038be
fixed type check
sfranzis Nov 15, 2022
cacadc9
Merge branch 'grafana:main' into #38273
sfranzis Nov 15, 2022
13876b0
implement suggestions from review
sfranzis Nov 16, 2022
fb7c215
implement suggestions from review
sfranzis Nov 16, 2022
eac63f2
run make gen-cue
sfranzis Nov 16, 2022
145bba3
move neutral to custom field config
sfranzis Nov 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/grafana-ui/src/components/Gauge/Gauge.test.tsx
Expand Up @@ -19,6 +19,9 @@ const field: FieldConfig = {
mode: ThresholdsMode.Absolute,
steps: [{ value: -Infinity, color: '#7EB26D' }],
},
custom: {
neeutral: 0,
},
};

const props: Props = {
Expand Down
1 change: 1 addition & 0 deletions packages/grafana-ui/src/components/Gauge/Gauge.tsx
Expand Up @@ -98,6 +98,7 @@ export class Gauge extends PureComponent<Props> {
gauge: {
min,
max,
neutralValue: field.custom?.neutral,
background: { color: backgroundColor },
border: { color: null },
shadow: { show: false },
Expand Down
15 changes: 13 additions & 2 deletions public/app/plugins/panel/gauge/module.tsx
Expand Up @@ -9,11 +9,22 @@ import { PanelOptions, defaultPanelOptions } from './models.gen';
import { GaugeSuggestionsSupplier } from './suggestions';

export const plugin = new PanelPlugin<PanelOptions>(GaugePanel)
.useFieldConfig()
.useFieldConfig({
useCustomConfig: (builder) => {
builder.addNumberInput({
path: 'neutral',
name: 'Neutral',
description: 'Leave empty to use Min as neutral point',
category: ['Gauge'],
settings: {
placeholder: 'auto',
},
});
},
})
.setPanelOptions((builder) => {
addStandardDataReduceOptions(builder);
addOrientationOption(builder);

builder
.addBooleanSwitch({
path: 'showThresholdLabels',
Expand Down
78 changes: 70 additions & 8 deletions public/vendor/flot/jquery.flot.gauge.js
Expand Up @@ -325,9 +325,9 @@
*/
Gauge.prototype.drawGauge = function(gaugeOptionsi, layout, cellLayout, label, data) {


var blur = gaugeOptionsi.gauge.shadow.show ? gaugeOptionsi.gauge.shadow.blur : 0;

var color = getColor(gaugeOptionsi, data);
var angles = calculateAnglesForGauge(gaugeOptionsi, layout, data);

// draw gauge frame
drawArcWithShadow(
Expand All @@ -343,19 +343,74 @@
blur);

// draw gauge
var c1 = getColor(gaugeOptionsi, data);
var a2 = calculateAngle(gaugeOptionsi, layout, data);
drawArcWithShadow(
cellLayout.cx, // center x
cellLayout.cy, // center y
layout.radius - 1,
layout.width - 2,
toRad(gaugeOptionsi.gauge.startAngle),
toRad(a2),
c1, // line color
toRad(angles.a1),
toRad(angles.a2),
color,
1, // line width
c1, // fill color
color, // fill color
blur);

if(gaugeOptionsi.gauge.neutralValue != null) {
drawZeroMarker(gaugeOptionsi, layout, cellLayout, color);
}
}

/**
* 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 neutral = gaugeOptionsi.gauge.neutralValue;

if (neutral != null) {
if (data < neutral) {
angles.a1 = calculateAngle(gaugeOptionsi, layout, data);
angles.a2 = calculateAngle(gaugeOptionsi, layout, neutral);
} else {
angles.a1 = calculateAngle(gaugeOptionsi, layout, neutral);
angles.a2 = calculateAngle(gaugeOptionsi, layout, data);
}
} else {
angles.a1 = gaugeOptionsi.gauge.startAngle;
angles.a2 = calculateAngle(gaugeOptionsi, layout, data);
}

return angles;
}

/**
* Draw zero marker for Gauge with negative values
*
* @method drawZeroMarker
* @param {Object} gaugeOptionsi the options of the gauge
* @param {Object} layout the layout properties
* @param {Object} cellLayout the cell layout properties
* @param {String} color line color
*/
function drawZeroMarker(gaugeOptionsi, layout, cellLayout, color) {
var diff = (gaugeOptionsi.gauge.max - gaugeOptionsi.gauge.min) / 600;

drawArc(context,
cellLayout.cx,
cellLayout.cy,
layout.radius - 2,
layout.width - 4,
toRad(calculateAngle(gaugeOptionsi, layout, gaugeOptionsi.gauge.neutralValue-diff)),
toRad(calculateAngle(gaugeOptionsi, layout, gaugeOptionsi.gauge.neutralValue+diff)),
color,
2,
gaugeOptionsi.gauge.background.color);
}

/**
Expand Down Expand Up @@ -529,6 +584,13 @@
drawThresholdValue(gaugeOptionsi, layout, cellLayout, i + "_" + j, threshold.value, a);
}
}

var neutral = gaugeOptionsi.gauge.neutralValue;
if (neutral != null &&
neutral>gaugeOptionsi.gauge.min &&
neutral<gaugeOptionsi.gauge.max) {
drawThresholdValue(gaugeOptionsi, layout, cellLayout, "Neutral" + i, neutral, calculateAngle(gaugeOptionsi, layout, neutral));
}
}

/**
Expand Down