-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filter geohash_grid aggregation to map view box with collar #12806
Changes from all commits
5416bd2
4f8c8d5
b077117
073272d
15bc2cc
88407f0
07fe8da
93cb54a
99180a5
5ab61d0
8742f23
75de435
17a76b3
4059aac
c04367f
6bfe87f
a4009e2
cb27ed0
58cc57f
98cc386
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,18 @@ import $ from 'jquery'; | |
import _ from 'lodash'; | ||
import { KibanaMap } from './kibana_map'; | ||
import { GeohashLayer } from './geohash_layer'; | ||
import { SearchSourceProvider } from 'ui/courier/data_source/search_source'; | ||
import { VisAggConfigProvider } from 'ui/vis/agg_config'; | ||
// import './lib/service_settings'; | ||
import 'ui/vis/map/service_settings'; | ||
import './styles/_tilemap.less'; | ||
|
||
|
||
export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState) { | ||
export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState, Private) { | ||
|
||
const AggConfig = Private(VisAggConfigProvider); | ||
const notify = new Notifier({ location: 'Coordinate Map' }); | ||
const SearchSource = Private(SearchSourceProvider); | ||
|
||
class MapsVisualization { | ||
|
||
|
@@ -43,6 +47,7 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
if (esResponse && typeof esResponse.geohashGridAgg === 'undefined') { | ||
return resolve(); | ||
} | ||
|
||
if (status.data) { | ||
this._recreateGeohashLayer(esResponse); | ||
} | ||
|
@@ -52,6 +57,7 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
if (status.resize) { | ||
this._kibanaMap.resize(); | ||
} | ||
|
||
this._doRenderComplete(resolve); | ||
|
||
}); | ||
|
@@ -82,6 +88,8 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
options.center = centerFromUIState ? centerFromUIState : this.vis.type.visConfig.defaults.mapCenter; | ||
|
||
this._kibanaMap = new KibanaMap(containerElement, options); | ||
uiState.set('mapZoom', this._kibanaMap.getZoomLevel()); | ||
uiState.set('mapBounds', this._kibanaMap.getUntrimmedBounds()); | ||
this._kibanaMap.addDrawControl(); | ||
this._kibanaMap.addFitControl(); | ||
this._kibanaMap.addLegendControl(); | ||
|
@@ -92,7 +100,10 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
this._kibanaMap.on('zoomchange', () => { | ||
precisionChange = (previousPrecision !== this._kibanaMap.getAutoPrecision()); | ||
previousPrecision = this._kibanaMap.getAutoPrecision(); | ||
this.vis.aggs[1].params.precision = previousPrecision; | ||
const agg = this._getGeoHashAgg(); | ||
if (agg) { | ||
agg.params.precision = previousPrecision; | ||
} | ||
}); | ||
this._kibanaMap.on('zoomend', () => { | ||
|
||
|
@@ -233,6 +244,8 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
valueFormatter: this._chartData ? this._chartData.valueFormatter : null, | ||
tooltipFormatter: this._chartData ? this._chartData.tooltipFormatter : null, | ||
mapType: newParams.mapType, | ||
isFilteredByCollar: this._isFilteredByCollar(), | ||
fetchBounds: this.getGeohashBounds.bind(this), | ||
heatmap: { | ||
heatBlur: newParams.heatBlur, | ||
heatMaxZoom: newParams.heatMaxZoom, | ||
|
@@ -266,10 +279,47 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState | |
this.vis.updateState(); | ||
} | ||
|
||
} | ||
async getGeohashBounds() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this. Each layer should determine its bounds. We're throwing that away when creating this function that needs to be supplied to the FitControl. I'd move this method to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is now passed to the geohash_layer. I did this instead of migrating the code to geohash_layer because several dependencies are not available in geohash_layer, like Private and vis index pattern. |
||
const agg = this._getGeoHashAgg(); | ||
if (agg) { | ||
const searchSource = new SearchSource(); | ||
searchSource.index(this.vis.indexPattern); | ||
searchSource.size(0); | ||
searchSource.aggs(function () { | ||
const geoBoundsAgg = new AggConfig(agg.vis, { | ||
type: 'geo_bounds', | ||
enabled:true, | ||
params: { | ||
field: agg.getField() | ||
}, | ||
schema: 'metric' | ||
}); | ||
return { | ||
'1': geoBoundsAgg.toDsl() | ||
}; | ||
}); | ||
const esResp = await searchSource.fetch(); | ||
return _.get(esResp, 'aggregations.1.bounds'); | ||
} | ||
} | ||
|
||
_getGeoHashAgg() { | ||
return this.vis.aggs.find((agg) => { | ||
return agg.type.dslName === 'geohash_grid'; | ||
}); | ||
} | ||
|
||
_isFilteredByCollar() { | ||
const DEFAULT = false; | ||
|
||
const agg = this._getGeoHashAgg(); | ||
if (agg) { | ||
return _.get(agg, 'params.isFilteredByCollar', DEFAULT); | ||
} else { | ||
return DEFAULT; | ||
} | ||
} | ||
} | ||
|
||
return MapsVisualization; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new guard is breaking these tests: https://github.com/thomasneirynck/kibana/blob/bf63cac183e54f64a054eb781ffba5708270710e/src/ui/public/agg_types/__tests__/buckets/_geo_hash.js#L52-L52
In that mock
vis
object in the test, will need to add mock aggregation.