Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
52 changes: 44 additions & 8 deletions src/ui/public/vis/__tests__/_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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');
});
});

});
11 changes: 9 additions & 2 deletions src/ui/public/vis/vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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 });
Expand Down