TimeSeries: use positive stacks for 0-valued series (#48197)

This commit is contained in:
Leon Sorokin 2022-04-25 11:46:00 -05:00 committed by GitHub
parent ebe34ddcba
commit 0ca32f0c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 53 deletions

View File

@ -230,29 +230,29 @@ describe('preparePlotData2', () => {
],
});
expect(preparePlotData2(df, getStackingGroups(df))).toMatchInlineSnapshot(`
Array [
Array [
9997,
9998,
9999,
],
Array [
-10,
20,
10,
],
Array [
10,
10,
10,
],
Array [
20,
20,
20,
],
]
`);
Array [
Array [
9997,
9998,
9999,
],
Array [
-10,
20,
10,
],
Array [
10,
10,
10,
],
Array [
20,
20,
20,
],
]
`);
});
it('standard', () => {
@ -289,14 +289,14 @@ describe('preparePlotData2', () => {
10,
],
Array [
0,
30,
20,
10,
10,
10,
],
Array [
20,
50,
40,
30,
30,
30,
],
]
`);
@ -345,19 +345,19 @@ describe('preparePlotData2', () => {
10,
],
Array [
10,
10,
10,
],
Array [
-30,
0,
30,
20,
-10,
],
Array [
-40,
-10,
-20,
-20,
-20,
],
Array [
-30,
-30,
-30,
],
]
`);
@ -413,14 +413,14 @@ describe('preparePlotData2', () => {
10,
],
Array [
0,
30,
20,
10,
10,
10,
],
Array [
20,
50,
40,
30,
30,
30,
],
Array [
1,
@ -580,13 +580,13 @@ describe('auto stacking groups', () => {
"dir": -1,
"series": Array [
1,
3,
],
},
Object {
"dir": 1,
"series": Array [
2,
3,
],
},
]
@ -622,11 +622,6 @@ describe('auto stacking groups', () => {
"series": Array [
1,
2,
],
},
Object {
"dir": -1,
"series": Array [
3,
],
},

View File

@ -115,16 +115,17 @@ export function getStackingGroups(frame: DataFrame) {
// will this be stacked up or down after any transforms applied
let vals = values.toArray();
let transform = custom.transform;
let firstValue = vals.find((v) => v != null);
let stackDir =
transform === GraphTransform.Constant
? vals[0] > 0
? firstValue >= 0
? StackDirection.Pos
: StackDirection.Neg
: transform === GraphTransform.NegativeY
? vals.some((v) => v > 0)
? firstValue >= 0
? StackDirection.Neg
: StackDirection.Pos
: vals.some((v) => v > 0)
: firstValue >= 0
? StackDirection.Pos
: StackDirection.Neg;