mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
parent
930822eade
commit
0d243398e1
3 changed files with 54 additions and 11 deletions
|
@ -154,7 +154,7 @@ export function RegionMapsVisualizationProvider(Private, Notifier, config) {
|
|||
}
|
||||
|
||||
const rowIndex = this._chartData.tables[0].rows.findIndex(row => row[0] === event);
|
||||
this._vis.API.events.addFilter(this._chartData.tables[0], 0, rowIndex);
|
||||
this._vis.API.events.addFilter(this._chartData.tables[0], 0, rowIndex, event);
|
||||
});
|
||||
this._choroplethLayer.on('styleChanged', (event) => {
|
||||
const shouldShowWarning = this._vis.params.isDisplayWarning && config.get('visualization:regionmap:showWarnings');
|
||||
|
|
|
@ -44,6 +44,14 @@ describe('Vis Class', function () {
|
|||
listeners: { click: _.noop }
|
||||
};
|
||||
|
||||
// Wrap the given vis type definition in a state, that can be passed to vis
|
||||
const state = (type) => ({
|
||||
type: {
|
||||
visConfig: { defaults: {} },
|
||||
...type,
|
||||
}
|
||||
});
|
||||
|
||||
beforeEach(ngMock.module('kibana'));
|
||||
beforeEach(ngMock.inject(function (Private) {
|
||||
Vis = Private(VisProvider);
|
||||
|
@ -111,14 +119,6 @@ describe('Vis Class', function () {
|
|||
|
||||
describe('inspector', () => {
|
||||
|
||||
// Wrap the given vis type definition in a state, that can be passed to vis
|
||||
const state = (type) => ({
|
||||
type: {
|
||||
visConfig: { defaults: {} },
|
||||
...type,
|
||||
}
|
||||
});
|
||||
|
||||
describe('hasInspector()', () => {
|
||||
it('should forward to inspectors hasInspector', () => {
|
||||
const vis = new Vis(indexPattern, state({
|
||||
|
@ -256,4 +256,40 @@ describe('Vis Class', function () {
|
|||
|
||||
});
|
||||
|
||||
describe('vis addFilter method', () => {
|
||||
let aggConfig;
|
||||
let data;
|
||||
|
||||
beforeEach(() => {
|
||||
aggConfig = {
|
||||
type: { name: 'terms' },
|
||||
params: {},
|
||||
createFilter: sinon.stub()
|
||||
};
|
||||
|
||||
data = {
|
||||
columns: [{
|
||||
title: 'test',
|
||||
aggConfig
|
||||
}],
|
||||
rows: [['US']]
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
it('adds a simple filter', () => {
|
||||
const vis = new Vis(indexPattern, state({ requestHandler: 'none' }));
|
||||
vis.API.events.addFilter(data, 0, 0);
|
||||
expect(aggConfig.createFilter.callCount).to.be(1);
|
||||
expect(aggConfig.createFilter.getCall(0).args[0]).to.be('US');
|
||||
});
|
||||
|
||||
it('adds a filter if value is provided instead of row index', () => {
|
||||
const vis = new Vis(indexPattern, state({ requestHandler: 'none' }));
|
||||
vis.API.events.addFilter(data, 0, -1, 'UK');
|
||||
expect(aggConfig.createFilter.callCount).to.be(1);
|
||||
expect(aggConfig.createFilter.getCall(0).args[0]).to.be('UK');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -44,6 +44,10 @@ import { Inspector } from '../inspector';
|
|||
import { RequestAdapter, DataAdapter } from '../inspector/adapters';
|
||||
|
||||
const getTerms = (table, columnIndex, rowIndex) => {
|
||||
if (rowIndex === -1) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// get only rows where cell value matches current row for all the fields before columnIndex
|
||||
const rows = table.rows.filter(row => row.every((cell, i) => cell === table.rows[rowIndex][i] || i >= columnIndex));
|
||||
const terms = rows.map(row => row[columnIndex]);
|
||||
|
@ -94,10 +98,13 @@ export function VisProvider(Private, indexPatterns, getAppState) {
|
|||
const appState = getAppState();
|
||||
filterBarClickHandler(appState)(event);
|
||||
},
|
||||
addFilter: (data, columnIndex, rowIndex) => {
|
||||
addFilter: (data, columnIndex, rowIndex, cellValue) => {
|
||||
const agg = data.columns[columnIndex].aggConfig;
|
||||
let filter = [];
|
||||
const value = data.rows[rowIndex][columnIndex];
|
||||
const value = rowIndex > -1 ? data.rows[rowIndex][columnIndex] : cellValue;
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
if (agg.type.name === 'terms' && agg.params.otherBucket) {
|
||||
const terms = getTerms(data, columnIndex, rowIndex);
|
||||
filter = agg.createFilter(value, { terms });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue