From d7b3cb5854cdb66b128af4f845a94bf4d5cc77c3 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Mon, 11 Apr 2016 09:41:56 -0400 Subject: [PATCH] [Precision] Experimenting with precision... --- .../kbn_vislib_vis_types/public/tile_map.js | 8 ++-- .../kibana/public/visualize/editor/agg.js | 1 - .../kibana/public/visualize/editor/sidebar.js | 1 - .../public/agg_response/geo_json/geo_json.js | 2 +- src/ui/public/agg_types/buckets/geo_hash.js | 43 ++++++++++++++++--- .../public/vislib/visualizations/tile_map.js | 1 + 6 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/plugins/kbn_vislib_vis_types/public/tile_map.js b/src/plugins/kbn_vislib_vis_types/public/tile_map.js index 577d7aa749a9..b75d1e9e7798 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -73,8 +73,10 @@ export default function TileMapVisType(Private, getAppState, courier, config) { pushFilter(filter, false, indexPatternName); }, mapMoveEnd: function (event, uiState) { + const mapPrecision = zoomPrecision[event.zoom]; uiState.set('vis.params.mapCenter', event.center); uiState.set('vis.params.mapZoom', event.zoom); + uiState.set('vis.params.mapPrecision', mapPrecision); const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg) return; @@ -91,16 +93,16 @@ export default function TileMapVisType(Private, getAppState, courier, config) { if (editableAgg) { editableAgg.params.mapZoom = event.zoom; editableAgg.params.mapCenter = event.center; - editableAgg.params.precision = zoomPrecision[event.zoom]; + editableAgg.params.mapPrecision = mapPrecision; } }, - mapZoomEnd: function (event) { + mapZoomEnd: function (event, uiState) { const agg = _.get(event, 'chart.geohashGridAgg'); + // this could be a problem, conditional on autoPrecision if (!agg || !agg.params.autoPrecision) return; const precision = config.get('visualization:tileMap:maxPrecision'); agg.params.precision = Math.min(zoomPrecision[event.zoom], precision); - debugger; courier.fetch(); } diff --git a/src/plugins/kibana/public/visualize/editor/agg.js b/src/plugins/kibana/public/visualize/editor/agg.js index d7c2b42daca2..5cbd884e24be 100644 --- a/src/plugins/kibana/public/visualize/editor/agg.js +++ b/src/plugins/kibana/public/visualize/editor/agg.js @@ -21,7 +21,6 @@ uiModules template: aggTemplate, require: 'form', link: function ($scope, $el, attrs, kbnForm) { - $scope.$bind('outputAgg', 'outputVis.aggs.byId[agg.id]', $scope); $scope.editorOpen = !!$scope.agg.brandNew; $scope.$watch('editorOpen', function (open) { diff --git a/src/plugins/kibana/public/visualize/editor/sidebar.js b/src/plugins/kibana/public/visualize/editor/sidebar.js index e9a6541aec99..40187ba84bed 100644 --- a/src/plugins/kibana/public/visualize/editor/sidebar.js +++ b/src/plugins/kibana/public/visualize/editor/sidebar.js @@ -15,7 +15,6 @@ uiModules controllerAs: 'sidebar', controller: function ($scope) { $scope.$bind('vis', 'editableVis'); - $scope.$bind('outputVis', 'vis'); $scope.$watch('vis.type', (visType) => { if (visType) { this.showData = visType.schemas.buckets || visType.schemas.metrics; diff --git a/src/ui/public/agg_response/geo_json/geo_json.js b/src/ui/public/agg_response/geo_json/geo_json.js index 4b9fbcb966ea..0d6e670d26a2 100644 --- a/src/ui/public/agg_response/geo_json/geo_json.js +++ b/src/ui/public/agg_response/geo_json/geo_json.js @@ -35,7 +35,7 @@ export default function TileMapConverterFn(Private, timefilter, $compile, $rootS min: _.min(values), max: _.max(values), zoom: _.get(geoAgg, 'params.mapZoom') || vis.uiState.get('vis.params.mapZoom'), - center: _.get(geoAgg, 'params.mapCenter' || vis.uiState.get('vis.params.mapCenter')) + center: _.get(geoAgg, 'params.mapCenter') || vis.uiState.get('vis.params.mapCenter') } } }; diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index dcaaa1d17b79..6e8677544c80 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -6,6 +6,30 @@ export default function GeoHashAggDefinition(Private, config) { var BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider); var defaultPrecision = 2; + // zoomPrecision maps event.zoom to a geohash precision value + // event.limit is the configurable max geohash precision + // default max precision is 7, configurable up to 12 + const zoomPrecision = { + 1: 2, + 2: 2, + 3: 2, + 4: 3, + 5: 3, + 6: 4, + 7: 4, + 8: 5, + 9: 5, + 10: 6, + 11: 6, + 12: 7, + 13: 7, + 14: 8, + 15: 9, + 16: 10, + 17: 11, + 18: 12 + }; + function getPrecision(precision) { var maxPrecision = _.parseInt(config.get('visualization:tileMap:maxPrecision')); @@ -48,12 +72,21 @@ export default function GeoHashAggDefinition(Private, config) { default: defaultPrecision, editor: precisionTemplate, controller: function ($scope) { - $scope.$watchMulti([ - 'agg.params.autoPrecision', - 'outputAgg.params.precision' - ], function (cur, prev) { - if (cur[1]) $scope.agg.params.precision = cur[1]; + $scope.$watchGroup([ + 'agg.params.mapZoom', + 'agg.params.autoPrecision'], + function (curr, prev) { + const zoom = curr[0]; + const autoPrecision = curr[1]; + if (autoPrecision) { + $scope.agg.params.precision = zoomPrecision[zoom]; + } + }); + $scope.$watch('agg.params.precision', function(precision) { + // $scope.uiState.set('mapPrecision', preci }); + + $scope.agg.params.mapZoom = $scope.uiState.get('vis.params.mapZoom'); }, deserialize: getPrecision, write: function (aggConfig, output) { diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index 444ad4a7f807..84399bd113df 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -106,6 +106,7 @@ export default function TileMapFactory(Private) { }; const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams); + // this.handler.vis.uiState var map = new TileMapMap(container, this._chartData, {