diff --git a/src/ui/public/utils/brush_event.js b/src/ui/public/utils/brush_event.js index dac7c02ee6ea7..c8921611c7d34 100644 --- a/src/ui/public/utils/brush_event.js +++ b/src/ui/public/utils/brush_event.js @@ -1,36 +1,43 @@ import moment from 'moment'; import buildRangeFilter from 'ui/filter_manager/lib/range'; export default function brushEventProvider(timefilter) { - return function ($state) { - return function (event) { - if (event.data.xAxisField && event.data.xAxisField.type === 'date') { - 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'; - } else if (event.data.xAxisField && event.data.xAxisField.type === 'number') { - let existingFilter = null; - $state.filters.forEach(function (it) { - if (it.meta && it.meta.key === event.data.xAxisField.name) { - existingFilter = it; - } - }); + if (to - from === 0) return; + + timefilter.time.from = from; + timefilter.time.to = to; + timefilter.time.mode = 'absolute'; + break; - const range = {gte: event.range[0], lt: event.range[event.range.length - 1]}; - if (existingFilter) { - existingFilter.range[event.data.xAxisField.name] = range; - } else { - const newFilter = buildRangeFilter( - event.data.xAxisField, - range, - event.data.indexPattern, - event.data.xAxisFormatter); - $state.$newFilters = [newFilter]; - } + case 'number': + if (event.range.length <= 1) return; + + const existingFilter = $state.filters.find(filter => ( + filter.meta && filter.meta.key === event.data.xAxisField.name + )); + + const range = {gte: event.range[0], lt: event.range[event.range.length - 1]}; + if (existingFilter) { + existingFilter.range[event.data.xAxisField.name] = range; + } else { + const newFilter = buildRangeFilter( + event.data.xAxisField, + range, + event.data.indexPattern, + event.data.xAxisFormatter); + $state.$newFilters = [newFilter]; + } + break; } }; }; diff --git a/src/ui/public/vislib/lib/dispatch.js b/src/ui/public/vislib/lib/dispatch.js index 2a2edeab29e39..0427045b0be1a 100644 --- a/src/ui/public/vislib/lib/dispatch.js +++ b/src/ui/public/vislib/lib/dispatch.js @@ -191,7 +191,8 @@ export default function DispatchClass(Private, config) { function simulateClickWithBrushEnabled(d, i) { if (!validBrushClick(d3.event)) return; - if (xScale.invert) { + + if (isQuantitativeScale(xScale)) { const bar = d3.select(this); const startX = d3.mouse(svg.node()); const startXInv = xScale.invert(startX[0]); @@ -213,7 +214,6 @@ export default function DispatchClass(Private, config) { return this.addEvent('mousedown', simulateClickWithBrushEnabled); }; - /** * Mouseover Behavior * @@ -309,6 +309,22 @@ export default function DispatchClass(Private, config) { }; } + /** + * Determine if d3.Scale is quantitative + * + * @param element {d3.Scale} + * @method isQuantitativeScale + * @returns {boolean} + */ + function isQuantitativeScale(scale) { + //Invert is a method that only exists on quantiative scales + if (scale.invert) { + return true; + } else { + return false; + } + } + function validBrushClick(event) { return event.button === 0; }