TimeSeries: Preserve null/undefined values when performing negative y transform (#46584)

This commit is contained in:
Dominik Prokop 2022-03-16 01:05:37 -07:00 committed by GitHub
parent 31d141b267
commit 5ae3e3f6f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 1 deletions

View File

@ -88,6 +88,87 @@ describe('preparePlotData', () => {
]
`);
});
it('negative-y transform with null/undefined values', () => {
const df = new MutableDataFrame({
fields: [
{ name: 'time', type: FieldType.time, values: [9997, 9998, 9999] },
{ name: 'a', values: [-10, 20, 10, 30] },
{ name: 'b', values: [10, 10, 10, null] },
{ name: 'c', values: [null, 20, 20, 20], config: { custom: { transform: GraphTransform.NegativeY } } },
{ name: 'd', values: [20, 20, 20, null], config: { custom: { transform: GraphTransform.NegativeY } } },
{ name: 'e', values: [20, null, 20, 20], config: { custom: { transform: GraphTransform.NegativeY } } },
{ name: 'f', values: [10, 10, 10, undefined] },
{ name: 'g', values: [undefined, 20, 20, 20], config: { custom: { transform: GraphTransform.NegativeY } } },
{ name: 'h', values: [20, 20, 20, undefined], config: { custom: { transform: GraphTransform.NegativeY } } },
{ name: 'i', values: [20, undefined, 20, 20], config: { custom: { transform: GraphTransform.NegativeY } } },
],
});
expect(preparePlotData([df])).toMatchInlineSnapshot(`
Array [
Array [
9997,
9998,
9999,
undefined,
],
Array [
-10,
20,
10,
30,
],
Array [
10,
10,
10,
null,
],
Array [
null,
-20,
-20,
-20,
],
Array [
-20,
-20,
-20,
null,
],
Array [
-20,
null,
-20,
-20,
],
Array [
10,
10,
10,
undefined,
],
Array [
undefined,
-20,
-20,
-20,
],
Array [
-20,
-20,
-20,
undefined,
],
Array [
-20,
undefined,
-20,
-20,
],
]
`);
});
it('constant transform', () => {
const df = new MutableDataFrame({
fields: [

View File

@ -64,8 +64,9 @@ export function preparePlotData(
const customConfig: GraphFieldConfig = f.config.custom || {};
const values = f.values.toArray();
if (customConfig.transform === GraphTransform.NegativeY) {
result.push(values.map((v) => v * -1));
result.push(values.map((v) => (v == null ? v : v * -1)));
} else if (customConfig.transform === GraphTransform.Constant) {
result.push(new Array(values.length).fill(values[0]));
} else {