BarChart: Fix threshold lines rendering for horizontal orientation (#95737)

* Use different threshold x/y coordinates depending on orientation

* invert wording / semantics

---------

Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
Kristina 2024-11-08 10:43:23 -06:00 committed by GitHub
parent 7bb1b352e1
commit 95692b3d68
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,7 +2,7 @@ import tinycolor from 'tinycolor2';
import uPlot from 'uplot';
import { GrafanaTheme2, Threshold, ThresholdsConfig, ThresholdsMode } from '@grafana/data';
import { GraphThresholdsStyleConfig, GraphThresholdsStyleMode } from '@grafana/schema';
import { GraphThresholdsStyleConfig, GraphThresholdsStyleMode, ScaleOrientation } from '@grafana/schema';
import { getGradientRange, scaleGradient } from './gradientFills';
@ -58,10 +58,13 @@ export function getThresholdsDrawHook(options: UPlotThresholdOptions) {
color.setAlpha(0.7);
}
let x0 = Math.round(u.bbox.left);
let y0 = Math.round(u.valToPos(step.value, yScaleKey, true));
let x1 = Math.round(u.bbox.left + u.bbox.width);
let y1 = Math.round(u.valToPos(step.value, yScaleKey, true));
const isHorizontal = u.scales.x!.ori === ScaleOrientation.Horizontal;
const scaleVal = u.valToPos(step.value, yScaleKey, true);
let x0 = Math.round(isHorizontal ? u.bbox.left : scaleVal);
let y0 = Math.round(isHorizontal ? scaleVal : u.bbox.top);
let x1 = Math.round(isHorizontal ? u.bbox.left + u.bbox.width : scaleVal);
let y1 = Math.round(isHorizontal ? scaleVal : u.bbox.top + u.bbox.height);
ctx.beginPath();
ctx.moveTo(x0, y0);