-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TSVB] Filter by clicking on the timeseries chart #97426
Changes from all commits
b7e9178
8239f51
4ebdc5c
d76b9d9
2811767
9df82a8
0361a09
8ad57b0
c38f93a
08f18f0
da99718
ba3adc3
ea6896e
837db57
01bf898
3d40138
2bf2fae
84ea244
92ad097
eb75702
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,51 +6,74 @@ | |
* Side Public License, v 1. | ||
*/ | ||
import { IndexPattern } from 'src/plugins/data/public'; | ||
import { | ||
Datatable, | ||
DatatableRow, | ||
DatatableColumn, | ||
DatatableColumnType, | ||
} from 'src/plugins/expressions/public'; | ||
import { DatatableRow, DatatableColumn, DatatableColumnType } from 'src/plugins/expressions/public'; | ||
import { Query } from 'src/plugins/data/common'; | ||
import { TimeseriesVisParams } from '../../../types'; | ||
import type { PanelData } from '../../../../common/types'; | ||
import { BUCKET_TYPES } from '../../../../common/enums'; | ||
import { fetchIndexPattern } from '../../../../common/index_patterns_utils'; | ||
import { getDataStart } from '../../../services'; | ||
import { X_ACCESSOR_INDEX } from '../../visualizations/constants'; | ||
import type { TSVBTables } from './types'; | ||
|
||
interface TSVBTables { | ||
[key: string]: Datatable; | ||
interface FilterParams { | ||
filter?: Query; | ||
label?: string; | ||
field?: string; | ||
} | ||
|
||
interface TSVBColumns { | ||
id: number; | ||
name: string; | ||
isSplit: boolean; | ||
isMetric: boolean; | ||
type: string; | ||
params?: FilterParams[]; | ||
} | ||
|
||
export const addMetaToColumns = ( | ||
columns: TSVBColumns[], | ||
indexPattern: IndexPattern, | ||
metricsType: string | ||
indexPattern: IndexPattern | ||
): DatatableColumn[] => { | ||
return columns.map((column) => { | ||
const field = indexPattern.getFieldByName(column.name); | ||
const type = (field?.spec.type as DatatableColumnType) || 'number'; | ||
|
||
let params: unknown = { | ||
field: field?.spec.name, | ||
}; | ||
if (column.type === BUCKET_TYPES.FILTERS && column.params) { | ||
const filters = column.params.map((col) => ({ | ||
input: col.filter, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I think if you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed eb75702 |
||
label: col.label, | ||
})); | ||
params = { | ||
filters, | ||
}; | ||
} else if (column.type === 'date_histogram') { | ||
const { query } = getDataStart(); | ||
const timeRange = query.timefilter.timefilter.getTime(); | ||
params = { | ||
timeRange, | ||
}; | ||
} | ||
|
||
const cleanedColumn = { | ||
id: column.id.toString(), | ||
name: column.name, | ||
meta: { | ||
type, | ||
field: column.name, | ||
field: field?.spec.name, | ||
index: indexPattern.title, | ||
source: 'esaggs', | ||
sourceParams: { | ||
enabled: true, | ||
indexPatternId: indexPattern?.id, | ||
type: type === 'date' ? 'date_histogram' : column.isSplit ? 'terms' : metricsType, | ||
type: column.type, | ||
schema: column.isMetric ? 'metric' : 'group', | ||
params, | ||
}, | ||
}, | ||
}; | ||
} as DatatableColumn; | ||
return cleanedColumn; | ||
}); | ||
}; | ||
|
@@ -73,30 +96,58 @@ export const convertSeriesToDataTable = async ( | |
usedIndexPattern = indexPattern; | ||
} | ||
} | ||
const isGroupedByTerms = layer.split_mode === 'terms'; | ||
const isGroupedByTerms = layer.split_mode === BUCKET_TYPES.TERMS; | ||
const isGroupedByFilters = layer.split_mode === BUCKET_TYPES.FILTERS; | ||
const seriesPerLayer = series.filter((s) => s.seriesId === layer.id); | ||
let id = X_ACCESSOR_INDEX; | ||
|
||
const columns: TSVBColumns[] = [ | ||
{ id, name: usedIndexPattern.timeFieldName || '', isSplit: false }, | ||
{ | ||
id, | ||
name: usedIndexPattern.timeFieldName || '', | ||
isMetric: false, | ||
type: 'date_histogram', | ||
}, | ||
]; | ||
|
||
if (seriesPerLayer.length) { | ||
id++; | ||
columns.push({ id, name: seriesPerLayer[0].splitByLabel, isSplit: false }); | ||
// Adds an extra column, if the layer is split by terms aggregation | ||
const metrics = layer.metrics; | ||
columns.push({ | ||
id, | ||
name: metrics[metrics.length - 1].field || seriesPerLayer[0].splitByLabel, | ||
isMetric: true, | ||
type: metrics[metrics.length - 1].type, | ||
}); | ||
|
||
// Adds an extra column, if the layer is split by terms or filters aggregation | ||
if (isGroupedByTerms) { | ||
id++; | ||
columns.push({ id, name: layer.terms_field || '', isSplit: true }); | ||
columns.push({ | ||
id, | ||
name: layer.terms_field || '', | ||
isMetric: false, | ||
type: BUCKET_TYPES.TERMS, | ||
}); | ||
} else if (isGroupedByFilters) { | ||
id++; | ||
columns.push({ | ||
id, | ||
name: BUCKET_TYPES.FILTERS, | ||
isMetric: false, | ||
params: layer?.split_filters as FilterParams[], | ||
type: BUCKET_TYPES.FILTERS, | ||
}); | ||
} | ||
} | ||
const columnsWithMeta = addMetaToColumns(columns, usedIndexPattern, layer.metrics[0].type); | ||
|
||
const columnsWithMeta = addMetaToColumns(columns, usedIndexPattern); | ||
const filtersColumn = columns.find((col) => col.type === BUCKET_TYPES.FILTERS); | ||
let rows: DatatableRow[] = []; | ||
for (let j = 0; j < seriesPerLayer.length; j++) { | ||
const data = seriesPerLayer[j].data.map((rowData) => { | ||
const row: DatatableRow = [rowData[0], rowData[1]]; | ||
// If the layer is split by terms aggregation, the data array should also contain the split value. | ||
if (isGroupedByTerms) { | ||
if (isGroupedByTerms || filtersColumn) { | ||
row.push(seriesPerLayer[j].label); | ||
} | ||
return row; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether it matters, but this isn't correct for filters - it will assume type as
number
because there is no field in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flash1293 this is now the case on viz, here is the example of the meta on a filters column (taken by xy axis)
type === number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, guess we should fix this on esaggs side as well. Anyway, for consistency reasons it makes sense to keep it for now 👍