mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
TimeSeries: Fix stacking when first value is negative zero (#57257)
* TimeSeries: Fix stacking when first value is negative zero * More test + refactor
This commit is contained in:
parent
2c9526fdf7
commit
7f3b567657
@ -1059,6 +1059,11 @@ describe('auto stacking groups', () => {
|
||||
values: [0, 0, 0],
|
||||
config: { custom: { stacking: { mode: StackingMode.Normal } } },
|
||||
},
|
||||
{
|
||||
name: 'd',
|
||||
values: [-0, -10, -20],
|
||||
config: { custom: { stacking: { mode: StackingMode.Normal } } },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@ -1068,6 +1073,7 @@ describe('auto stacking groups', () => {
|
||||
"dir": -1,
|
||||
"series": Array [
|
||||
1,
|
||||
4,
|
||||
],
|
||||
},
|
||||
Object {
|
||||
@ -1100,6 +1106,11 @@ describe('auto stacking groups', () => {
|
||||
values: [0, 0, 0],
|
||||
config: { custom: { stacking: { mode: StackingMode.Normal } } },
|
||||
},
|
||||
{
|
||||
name: 'd',
|
||||
values: [-0, null, 3],
|
||||
config: { custom: { stacking: { mode: StackingMode.Normal }, transform: GraphTransform.NegativeY } },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
@ -1111,6 +1122,7 @@ describe('auto stacking groups', () => {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
],
|
||||
},
|
||||
]
|
||||
|
@ -117,18 +117,7 @@ export function getStackingGroups(frame: DataFrame) {
|
||||
let vals = values.toArray();
|
||||
let transform = custom.transform;
|
||||
let firstValue = vals.find((v) => v != null);
|
||||
let stackDir =
|
||||
transform === GraphTransform.Constant
|
||||
? firstValue >= 0
|
||||
? StackDirection.Pos
|
||||
: StackDirection.Neg
|
||||
: transform === GraphTransform.NegativeY
|
||||
? firstValue >= 0
|
||||
? StackDirection.Neg
|
||||
: StackDirection.Pos
|
||||
: firstValue >= 0
|
||||
? StackDirection.Pos
|
||||
: StackDirection.Neg;
|
||||
let stackDir = getStackDirection(transform, firstValue);
|
||||
|
||||
let drawStyle = custom.drawStyle as GraphDrawStyle;
|
||||
let drawStyle2 =
|
||||
@ -352,6 +341,15 @@ export function findMidPointYPosition(u: uPlot, idx: number) {
|
||||
return y;
|
||||
}
|
||||
|
||||
function getStackDirection(transform: GraphTransform, firstValue: number) {
|
||||
// Check if first value is negative zero. This can happen with a binary operation transform.
|
||||
const isNegativeZero = Object.is(firstValue, -0);
|
||||
if (transform === GraphTransform.NegativeY) {
|
||||
return !isNegativeZero && firstValue >= 0 ? StackDirection.Neg : StackDirection.Pos;
|
||||
}
|
||||
return !isNegativeZero && firstValue >= 0 ? StackDirection.Pos : StackDirection.Neg;
|
||||
}
|
||||
|
||||
// Dev helpers
|
||||
|
||||
/** @internal */
|
||||
|
Loading…
Reference in New Issue
Block a user