mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Feat: Cast datatable to pointseries (#28872)
* feat: allow casting datatable to pointseries * fix: use correct column type for pointseries columns are an object, not an array
This commit is contained in:
parent
2bea9afbfe
commit
1038c77e84
2 changed files with 29 additions and 2 deletions
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { map, zipObject } from 'lodash';
|
||||
import { map, pick, zipObject } from 'lodash';
|
||||
|
||||
export const datatable = () => ({
|
||||
name: 'datatable',
|
||||
|
@ -78,5 +78,32 @@ export const datatable = () => ({
|
|||
},
|
||||
};
|
||||
},
|
||||
pointseries: datatable => {
|
||||
// datatable columns are an array that looks like [{ name: "one", type: "string" }, { name: "two", type: "string" }]
|
||||
// rows look like [{ one: 1, two: 2}, { one: 3, two: 4}, ...]
|
||||
const validFields = ['x', 'y', 'color', 'size', 'text'];
|
||||
const columns = datatable.columns.filter(column => validFields.includes(column.name));
|
||||
const rows = datatable.rows.map(row => pick(row, validFields));
|
||||
|
||||
return {
|
||||
type: 'pointseries',
|
||||
columns: columns.reduce((acc, column) => {
|
||||
/* pointseries columns are an object that looks like this
|
||||
* {
|
||||
* x: { type: "string", expression: "x", role: "dimension" },
|
||||
* y: { type: "string", expression: "y", role: "dimension" }
|
||||
* }
|
||||
*/
|
||||
acc[column.name] = {
|
||||
type: column.type,
|
||||
expression: column.name,
|
||||
role: 'dimension',
|
||||
};
|
||||
|
||||
return acc;
|
||||
}, {}),
|
||||
rows,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ export const pointseries = () => ({
|
|||
return {
|
||||
type: 'pointseries',
|
||||
rows: [],
|
||||
columns: [],
|
||||
columns: {},
|
||||
};
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue