-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chart_expressions_xy-reference-line
# Conflicts: # src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis.test.ts # src/plugins/chart_expressions/expression_xy/common/expression_functions/xy_vis_fn.ts
- Loading branch information
Showing
41 changed files
with
452 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
*/ | ||
|
||
export { appendLayerIds, getAccessors } from './layers'; | ||
export { normalizeTable } from './table'; |
47 changes: 47 additions & 0 deletions
47
src/plugins/chart_expressions/expression_xy/common/helpers/table.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import { Datatable } from '@kbn/expressions-plugin'; | ||
import { normalizeTable } from './table'; | ||
import { createSampleDatatableWithRows } from '../__mocks__'; | ||
|
||
describe('#normalizeTable', () => { | ||
it('should convert row values from date string to number if xAccessor related to `date` column', () => { | ||
const xAccessor = 'c'; | ||
const data = createSampleDatatableWithRows([ | ||
{ a: 1, b: 2, c: '2022-05-07T06:25:00.000', d: 'Foo' }, | ||
{ a: 1, b: 2, c: '2022-05-08T06:25:00.000', d: 'Foo' }, | ||
{ a: 1, b: 2, c: '2022-05-09T06:25:00.000', d: 'Foo' }, | ||
]); | ||
const newData = { | ||
...data, | ||
type: 'datatable', | ||
|
||
columns: data.columns.map((c) => | ||
c.id !== 'c' | ||
? c | ||
: { | ||
...c, | ||
meta: { | ||
type: 'date', | ||
}, | ||
} | ||
), | ||
} as Datatable; | ||
const expectedData = { | ||
...newData, | ||
rows: newData.rows.map((row) => ({ | ||
...row, | ||
[xAccessor as string]: moment(row[xAccessor as string]).valueOf(), | ||
})), | ||
}; | ||
const normalizedTable = normalizeTable(newData, xAccessor); | ||
expect(normalizedTable).toEqual(expectedData); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
src/plugins/chart_expressions/expression_xy/common/helpers/table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import { getColumnByAccessor } from '@kbn/visualizations-plugin/common/utils'; | ||
import type { Datatable } from '@kbn/expressions-plugin/common'; | ||
import { ExpressionValueVisDimension } from '@kbn/visualizations-plugin/common/expression_functions'; | ||
|
||
export function normalizeTable(data: Datatable, xAccessor?: string | ExpressionValueVisDimension) { | ||
const xColumn = xAccessor && getColumnByAccessor(xAccessor, data.columns); | ||
if (xColumn && xColumn?.meta.type === 'date') { | ||
const xColumnId = xColumn.id; | ||
const rows = data.rows.reduce<Datatable['rows']>((normalizedRows, row) => { | ||
return [ | ||
...normalizedRows, | ||
{ | ||
...row, | ||
[xColumnId]: | ||
typeof row[xColumnId] === 'string' ? moment(row[xColumnId]).valueOf() : row[xColumnId], | ||
}, | ||
]; | ||
}, []); | ||
return { ...data, rows }; | ||
} | ||
|
||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.