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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a huge fan of that syntax, that we need to pass in a rowIndex even in cases we might not have it, but I see, that addFilter(data, { columnIndex, rowIndex, cellValue }) might also not be the best solution (especially since we know we need the columnIndex and addFilter(data, columnIndex, { rowIndex, cellValue }) for sure looks even more weird...

So just wanted to point that out, even without having a proper good solution (but maybe @markov00 or so has an idea).

Could we at least give cellValue = null a default value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As written few seconds ago on my review, are we sure that this is the right behaviour? if we don't have data, why we want to filter for a region with no data?
What if we avoid the click and mouseover on regions with no data at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the behaviour we had before ... and i think it makes sense ...

using makelogs data:

  • create region map, select term as geo.src, leave size at 5 ....
  • you see the top 5 countries ... however you can now click on something like germany for example (which does not have color applied at the moment as its not top 5) and a filter will apply and you will see the color on germany.

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