forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backports PR elastic#9039 **Commit 1:** support scripted fields * Original sha: 4a6e9fe * Authored by nreese <[email protected]> on 2016-11-10T22:35:23Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:30:53Z **Commit 2:** update column_chart test to check brush for ordered data * Original sha: 97aab8a * Authored by nreese <[email protected]> on 2016-11-10T23:06:29Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:32:28Z **Commit 3:** brush histogram * Original sha: 3b6652f * Authored by nreese <[email protected]> on 2016-10-18T20:42:23Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:33:27Z **Commit 4:** incorporate changes request by cjcenizal * Original sha: 0f7e70a * Authored by nreese <[email protected]> on 2016-11-01T22:08:38Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:33:43Z **Commit 5:** fixed typo * Original sha: 48e5bd6 * Authored by nreese <[email protected]> on 2016-11-02T03:39:41Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:33:52Z **Commit 6:** support scripted fields * Original sha: 4a27881 * Authored by nreese <[email protected]> on 2016-11-10T22:35:23Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:34:00Z **Commit 7:** update column_chart test to check brush for ordered data * Original sha: 77c295a * Authored by nreese <[email protected]> on 2016-11-10T23:06:29Z * Committed by CJ Cenizal <[email protected]> on 2016-11-10T23:35:31Z **Commit 8:** Fix init_x_axis unit tests. * Original sha: 32d9ce1 * Authored by CJ Cenizal <[email protected]> on 2016-11-11T22:13:06Z **Commit 9:** add brush_event test * Original sha: 22807f2 * Authored by nreese <[email protected]> on 2016-11-16T03:56:35Z * Committed by CJ Cenizal <[email protected]> on 2016-11-16T18:34:28Z **Commit 10:** Fix small timezone bug in brushEvent tests. Polish test descriptions. * Original sha: 28c8a6a * Authored by CJ Cenizal <[email protected]> on 2016-11-16T19:20:43Z
- Loading branch information
1 parent
2b04dde
commit d8fda1e
Showing
10 changed files
with
289 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import _ from 'lodash'; | ||
import expect from 'expect.js'; | ||
import moment from 'moment'; | ||
import ngMock from 'ng_mock'; | ||
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern'; | ||
import UtilsBrushEventProvider from 'ui/utils/brush_event'; | ||
|
||
describe('brushEvent', function () { | ||
let brushEventFn; | ||
let timefilter; | ||
|
||
beforeEach(ngMock.module('kibana')); | ||
beforeEach(ngMock.inject(function (Private, $injector, _timefilter_) { | ||
brushEventFn = Private(UtilsBrushEventProvider); | ||
timefilter = _timefilter_; | ||
})); | ||
|
||
it('is a function that returns a function', function () { | ||
expect(brushEventFn).to.be.a(Function); | ||
expect(brushEventFn({})).to.be.a(Function); | ||
}); | ||
|
||
describe('returned function', function () { | ||
let $state; | ||
let brushEvent; | ||
|
||
const baseState = { | ||
filters:[], | ||
}; | ||
|
||
const baseEvent = { | ||
data: { | ||
fieldFormatter: _.constant({}), | ||
}, | ||
}; | ||
|
||
beforeEach(ngMock.inject(function (Private, $injector) { | ||
baseEvent.data.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider); | ||
$state = _.cloneDeep(baseState); | ||
brushEvent = brushEventFn($state); | ||
})); | ||
|
||
it('should be a function', function () { | ||
expect(brushEvent).to.be.a(Function); | ||
}); | ||
|
||
it('ignores event when data.xAxisField not provided', function () { | ||
const event = _.cloneDeep(baseEvent); | ||
brushEvent(event); | ||
expect($state) | ||
.not.have.property('$newFilters'); | ||
}); | ||
|
||
describe('handles an event when the x-axis field is a date', function () { | ||
let dateEvent; | ||
const dateField = { | ||
name: 'dateField', | ||
type: 'date' | ||
}; | ||
|
||
beforeEach(ngMock.inject(function (Private, $injector) { | ||
dateEvent = _.cloneDeep(baseEvent); | ||
dateEvent.data.xAxisField = dateField; | ||
})); | ||
|
||
it('by ignoring the event when range spans zero time', function () { | ||
const event = _.cloneDeep(dateEvent); | ||
event.range = [1388559600000, 1388559600000]; | ||
brushEvent(event); | ||
expect($state) | ||
.not.have.property('$newFilters'); | ||
}); | ||
|
||
it('by updating the timefilter', function () { | ||
const event = _.cloneDeep(dateEvent); | ||
const DAY_IN_MS = 24 * 60 * 60 * 1000; | ||
event.range = [1388559600000, 1388559600000 + DAY_IN_MS]; | ||
brushEvent(event); | ||
expect(timefilter.time.mode).to.be('absolute'); | ||
expect(moment.isMoment(timefilter.time.from)) | ||
.to.be(true); | ||
// Set to a baseline timezone for comparison. | ||
expect(timefilter.time.from.utcOffset(0).format('YYYY-MM-DD')) | ||
.to.equal('2014-01-01'); | ||
expect(moment.isMoment(timefilter.time.to)) | ||
.to.be(true); | ||
// Set to a baseline timezone for comparison. | ||
expect(timefilter.time.to.utcOffset(0).format('YYYY-MM-DD')) | ||
.to.equal('2014-01-02'); | ||
}); | ||
}); | ||
|
||
describe('handles an event when the x-axis field is a number', function () { | ||
let numberEvent; | ||
const numberField = { | ||
name: 'numberField', | ||
type: 'number' | ||
}; | ||
|
||
beforeEach(ngMock.inject(function (Private, $injector) { | ||
numberEvent = _.cloneDeep(baseEvent); | ||
numberEvent.data.xAxisField = numberField; | ||
})); | ||
|
||
it('by ignoring the event when range does not span at least 2 values', function () { | ||
const event = _.cloneDeep(numberEvent); | ||
event.range = [1]; | ||
brushEvent(event); | ||
expect($state) | ||
.not.have.property('$newFilters'); | ||
}); | ||
|
||
it('by creating a new filter', function () { | ||
const event = _.cloneDeep(numberEvent); | ||
event.range = [1,2,3,4]; | ||
brushEvent(event); | ||
expect($state) | ||
.to.have.property('$newFilters'); | ||
expect($state.filters.length) | ||
.to.equal(0); | ||
expect($state.$newFilters.length) | ||
.to.equal(1); | ||
expect($state.$newFilters[0].range.numberField.gte) | ||
.to.equal(1); | ||
expect($state.$newFilters[0].range.numberField.lt) | ||
.to.equal(4); | ||
}); | ||
|
||
it('by updating the existing range filter', function () { | ||
const event = _.cloneDeep(numberEvent); | ||
event.range = [3,7]; | ||
$state.filters.push({ | ||
meta: { | ||
key: 'numberField' | ||
}, | ||
range: {gte: 1, lt: 4} | ||
}); | ||
brushEvent(event); | ||
expect($state) | ||
.not.have.property('$newFilters'); | ||
expect($state.filters.length) | ||
.to.equal(1); | ||
expect($state.filters[0].range.numberField.gte) | ||
.to.equal(3); | ||
expect($state.filters[0].range.numberField.lt) | ||
.to.equal(7); | ||
}); | ||
|
||
it('by updating the existing scripted filter', function () { | ||
const event = _.cloneDeep(numberEvent); | ||
event.range = [3,7]; | ||
$state.filters.push({ | ||
meta: { | ||
key: 'numberField' | ||
}, | ||
script: { | ||
script: { | ||
params: { | ||
gte: 1, | ||
lt: 4 | ||
} | ||
} | ||
} | ||
}); | ||
brushEvent(event); | ||
expect($state) | ||
.not.have.property('$newFilters'); | ||
expect($state.filters.length) | ||
.to.equal(1); | ||
expect($state.filters[0].script.script.params.gte) | ||
.to.equal(3); | ||
expect($state.filters[0].script.script.params.lt) | ||
.to.equal(7); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,51 @@ | ||
import _ from 'lodash'; | ||
import moment from 'moment'; | ||
import buildRangeFilter from 'ui/filter_manager/lib/range'; | ||
export default function brushEventProvider(timefilter) { | ||
return function (event) { | ||
let from = moment(event.range[0]); | ||
let to = moment(event.range[1]); | ||
return $state => { | ||
return event => { | ||
if (!event.data.xAxisField) { | ||
return; | ||
} | ||
|
||
if (to - from === 0) return; | ||
switch (event.data.xAxisField.type) { | ||
case 'date': | ||
let from = moment(event.range[0]); | ||
let to = moment(event.range[1]); | ||
|
||
timefilter.time.from = from; | ||
timefilter.time.to = to; | ||
timefilter.time.mode = 'absolute'; | ||
if (to - from === 0) return; | ||
|
||
timefilter.time.from = from; | ||
timefilter.time.to = to; | ||
timefilter.time.mode = 'absolute'; | ||
break; | ||
|
||
case 'number': | ||
if (event.range.length <= 1) return; | ||
|
||
const existingFilter = $state.filters.find(filter => ( | ||
filter.meta && filter.meta.key === event.data.xAxisField.name | ||
)); | ||
|
||
const min = event.range[0]; | ||
const max = event.range[event.range.length - 1]; | ||
const range = {gte: min, lt: max}; | ||
if (_.has(existingFilter, 'range')) { | ||
existingFilter.range[event.data.xAxisField.name] = range; | ||
} else if (_.has(existingFilter, 'script.script.params.gte') | ||
&& _.has(existingFilter, 'script.script.params.lt')) { | ||
existingFilter.script.script.params.gte = min; | ||
existingFilter.script.script.params.lt = max; | ||
} else { | ||
const newFilter = buildRangeFilter( | ||
event.data.xAxisField, | ||
range, | ||
event.data.indexPattern, | ||
event.data.xAxisFormatter); | ||
$state.$newFilters = [newFilter]; | ||
} | ||
break; | ||
} | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.