From e6dbd8cd1a04cc1b1ba6aba2e6213cb55b2a775e Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Thu, 7 Apr 2016 14:04:58 -0400 Subject: [PATCH 01/13] [MapZoom] map zoom, and location works if you save the vis --- src/plugins/kbn_vislib_vis_types/public/tile_map.js | 12 ++++-------- src/ui/public/vislib/visualizations/_map.js | 9 ++++----- src/ui/public/vislib/visualizations/tile_map.js | 6 ++++-- 3 files changed, 12 insertions(+), 15 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 acc7e4591848..54c7bdecd0f0 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -27,6 +27,8 @@ export default function TileMapVisType(Private, getAppState, courier, config) { heatRadius: 25, heatBlur: 15, heatNormalizeData: true, + mapZoom: 2, + mapCenter: [15, 5], wms: config.get('visualization:tileMap:WMSdefaults') }, mapTypes: ['Scaled Circle Markers', 'Shaded Circle Markers', 'Shaded Geohash Grid', 'Heatmap'], @@ -50,17 +52,11 @@ export default function TileMapVisType(Private, getAppState, courier, config) { const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg) return; - agg.params.mapZoom = event.zoom; - agg.params.mapCenter = [event.center.lat, event.center.lng]; - const editableVis = agg.vis.getEditableVis(); if (!editableVis) return; - const editableAgg = editableVis.aggs.byId[agg.id]; - if (editableAgg) { - editableAgg.params.mapZoom = event.zoom; - editableAgg.params.mapCenter = [event.center.lat, event.center.lng]; - } + editableVis.params.mapCenter = event.center; + editableVis.params.mapZoom = event.zoom; }, mapZoomEnd: function (event) { const agg = _.get(event, 'chart.geohashGridAgg'); diff --git a/src/ui/public/vislib/visualizations/_map.js b/src/ui/public/vislib/visualizations/_map.js index 0d4625fbc016..7a812881e029 100644 --- a/src/ui/public/vislib/visualizations/_map.js +++ b/src/ui/public/vislib/visualizations/_map.js @@ -47,6 +47,8 @@ export default function MapFactory(Private) { this._valueFormatter = params.valueFormatter || _.identity; this._tooltipFormatter = params.tooltipFormatter || _.identity; this._geoJson = _.get(this._chartData, 'geoJson'); + this._mapZoom = params.zoom || defaultMapZoom; + this._mapCenter = params.center || defaultMapCenter; this._attr = params.attr || {}; var mapOptions = { @@ -211,7 +213,8 @@ export default function MapFactory(Private) { this.map.on('moveend', function setZoomCenter(ev) { if (!self.map) return; // update internal center and zoom references - self._mapCenter = self.map.getCenter(); + const uglyCenter = self.map.getCenter(); + self._mapCenter = [uglyCenter.lat, uglyCenter.lng]; self._mapZoom = self.map.getZoom(); self._addMarkers(); @@ -264,10 +267,6 @@ export default function MapFactory(Private) { TileMapMap.prototype._createMap = function (mapOptions) { if (this.map) this.destroy(); - // get center and zoom from mapdata, or use defaults - this._mapCenter = _.get(this._geoJson, 'properties.center') || defaultMapCenter; - this._mapZoom = _.get(this._geoJson, 'properties.zoom') || defaultMapZoom; - // add map tiles layer, using the mapTiles object settings if (this._attr.wms && this._attr.wms.enabled) { this._tileLayer = L.tileLayer.wms(this._attr.wms.url, this._attr.wms.options); diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index db0d324d6869..be7f107e306d 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -99,10 +99,12 @@ export default function TileMapFactory(Private) { */ TileMap.prototype._appendMap = function (selection) { var container = $(selection).addClass('tilemap'); + // Lol couldn't think of another way to access this object... + const params = this._chartData.geohashGridAgg.vis.params; var map = new TileMapMap(container, this._chartData, { - // center: this._attr.mapCenter, - // zoom: this._attr.mapZoom, + center: params.mapCenter, + zoom: params.mapZoom, events: this.events, markerType: this._attr.mapType, tooltipFormatter: this.tooltipFormatter, From 9ac496112c4f31acde82d59c5ba47a1dc363c508 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Fri, 8 Apr 2016 09:29:26 -0400 Subject: [PATCH 02/13] [MapZoom] giving vislib event access to the uiState, getting the map zoom from the previous uiState --- .../kbn_vislib_vis_types/public/tile_map.js | 67 +++++++++++-------- .../kibana/public/visualize/editor/editor.js | 2 +- .../public/agg_response/geo_json/geo_json.js | 4 +- src/ui/public/vislib/lib/handler/handler.js | 2 +- .../public/vislib/visualizations/tile_map.js | 8 ++- 5 files changed, 51 insertions(+), 32 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 54c7bdecd0f0..577d7aa749a9 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -11,6 +11,30 @@ export default function TileMapVisType(Private, getAppState, courier, config) { const Schemas = Private(VisSchemasProvider); const geoJsonConverter = Private(AggResponseGeoJsonGeoJsonProvider); + // 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 + }; + return new VislibVisType({ name: 'tile_map', title: 'Tile map', @@ -48,46 +72,35 @@ export default function TileMapVisType(Private, getAppState, courier, config) { pushFilter(filter, false, indexPatternName); }, - mapMoveEnd: function (event) { + mapMoveEnd: function (event, uiState) { + uiState.set('vis.params.mapCenter', event.center); + uiState.set('vis.params.mapZoom', event.zoom); + const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg) return; + agg.params.mapZoom = event.zoom; + agg.params.mapCenter = event.center; const editableVis = agg.vis.getEditableVis(); if (!editableVis) return; - editableVis.params.mapCenter = event.center; - editableVis.params.mapZoom = event.zoom; + // editableVis.params.mapCenter = event.center; + // editableVis.params.mapZoom = event.zoom; + + const editableAgg = editableVis.aggs.byId[agg.id]; + if (editableAgg) { + editableAgg.params.mapZoom = event.zoom; + editableAgg.params.mapCenter = event.center; + editableAgg.params.precision = zoomPrecision[event.zoom]; + } }, mapZoomEnd: function (event) { const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg || !agg.params.autoPrecision) return; - // 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 - }; - 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/editor.js b/src/plugins/kibana/public/visualize/editor/editor.js index 2b9341f86a88..550b7236bd42 100644 --- a/src/plugins/kibana/public/visualize/editor/editor.js +++ b/src/plugins/kibana/public/visualize/editor/editor.js @@ -138,7 +138,7 @@ uiModules $scope.indexPattern = vis.indexPattern; $scope.editableVis = editableVis; $scope.state = $state; - $scope.uiState = $state.makeStateful('uiState'); + $scope.uiState = vis.uiState = $state.makeStateful('uiState'); $scope.timefilter = timefilter; $scope.opts = _.pick($scope, 'doSave', 'savedVis', 'shareData', 'timefilter'); 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 c0e0b9b52e4b..4b9fbcb966ea 100644 --- a/src/ui/public/agg_response/geo_json/geo_json.js +++ b/src/ui/public/agg_response/geo_json/geo_json.js @@ -34,8 +34,8 @@ export default function TileMapConverterFn(Private, timefilter, $compile, $rootS properties: { min: _.min(values), max: _.max(values), - zoom: _.get(geoAgg, 'params.mapZoom'), - center: _.get(geoAgg, 'params.mapCenter') + zoom: _.get(geoAgg, 'params.mapZoom') || vis.uiState.get('vis.params.mapZoom'), + center: _.get(geoAgg, 'params.mapCenter' || vis.uiState.get('vis.params.mapCenter')) } } }; diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index b0e4bf6d8ea5..1f1a72b91856 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -55,7 +55,7 @@ export default function HandlerBaseClass(Private) { this.getProxyHandler = _.memoize(function (event) { var self = this; return function (e) { - self.vis.emit(event, e); + self.vis.emit(event, e, vis.uiState); }; }); } diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index be7f107e306d..444ad4a7f807 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -100,7 +100,13 @@ export default function TileMapFactory(Private) { TileMap.prototype._appendMap = function (selection) { var container = $(selection).addClass('tilemap'); // Lol couldn't think of another way to access this object... - const params = this._chartData.geohashGridAgg.vis.params; + const uiStateParams = { + mapCenter: this.handler.vis.uiState.get('vis.params.mapCenter'), + mapZoom: this.handler.vis.uiState.get('vis.params.mapZoom') + }; + + const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams); + // this.handler.vis.uiState var map = new TileMapMap(container, this._chartData, { center: params.mapCenter, From d7b3cb5854cdb66b128af4f845a94bf4d5cc77c3 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Mon, 11 Apr 2016 09:41:56 -0400 Subject: [PATCH 03/13] [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, { From ad62b600a22527afcc8186f4e4f22050e29c6c20 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Wed, 13 Apr 2016 12:45:19 -0400 Subject: [PATCH 04/13] [Cleanup] finally have it all working, though very ugly --- .../kbn_vislib_vis_types/public/tile_map.js | 8 ++++++- .../public/agg_response/geo_json/geo_json.js | 4 ++-- src/ui/public/agg_types/buckets/geo_hash.js | 23 +++++-------------- 3 files changed, 15 insertions(+), 20 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 b75d1e9e7798..ce40357f8974 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -98,7 +98,13 @@ export default function TileMapVisType(Private, getAppState, courier, config) { }, mapZoomEnd: function (event, uiState) { const agg = _.get(event, 'chart.geohashGridAgg'); - // this could be a problem, conditional on autoPrecision + const mapPrecision = zoomPrecision[event.zoom]; + uiState.set('vis.params.mapZoom', event.zoom); + uiState.set('vis.params.mapPrecision', mapPrecision); + + if (!agg) return; + agg.params.mapZoom = event.zoom; + if (!agg || !agg.params.autoPrecision) return; const precision = config.get('visualization:tileMap:maxPrecision'); 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 0d6e670d26a2..c0e0b9b52e4b 100644 --- a/src/ui/public/agg_response/geo_json/geo_json.js +++ b/src/ui/public/agg_response/geo_json/geo_json.js @@ -34,8 +34,8 @@ export default function TileMapConverterFn(Private, timefilter, $compile, $rootS properties: { 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') + zoom: _.get(geoAgg, 'params.mapZoom'), + center: _.get(geoAgg, '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 6e8677544c80..a85399da87b5 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -69,28 +69,17 @@ export default function GeoHashAggDefinition(Private, config) { }, { name: 'precision', - default: defaultPrecision, editor: precisionTemplate, controller: function ($scope) { - $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) { - output.params.precision = getPrecision(aggConfig.params.precision); + let currZoom = aggConfig.vis.params.mapZoom; + if (aggConfig.params.mapZoom || aggConfig.vis.uiState) { // First iteration + currZoom = aggConfig.vis.uiState ? aggConfig.vis.uiState.get('vis.params.mapZoom') : aggConfig.params.mapZoom; + } + const autoPrecisionVal = zoomPrecision[currZoom]; + output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision); } } ] From 6cfe38d9faf8cfa079c28425ffc495ede39f194f Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Thu, 14 Apr 2016 17:42:50 -0400 Subject: [PATCH 05/13] [Cleanup] Cleaning up some code --- .../kbn_vislib_vis_types/public/tile_map.js | 40 ++----------------- src/ui/public/agg_types/buckets/geo_hash.js | 5 ++- .../public/vislib/visualizations/tile_map.js | 4 +- 3 files changed, 8 insertions(+), 41 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 ce40357f8974..9c68eeab26d1 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -11,30 +11,6 @@ export default function TileMapVisType(Private, getAppState, courier, config) { const Schemas = Private(VisSchemasProvider); const geoJsonConverter = Private(AggResponseGeoJsonGeoJsonProvider); - // 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 - }; - return new VislibVisType({ name: 'tile_map', title: 'Tile map', @@ -73,10 +49,8 @@ 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); + uiState.set('mapCenter', event.center); + uiState.set('mapZoom', event.zoom); const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg) return; @@ -93,23 +67,15 @@ export default function TileMapVisType(Private, getAppState, courier, config) { if (editableAgg) { editableAgg.params.mapZoom = event.zoom; editableAgg.params.mapCenter = event.center; - editableAgg.params.mapPrecision = mapPrecision; } }, mapZoomEnd: function (event, uiState) { const agg = _.get(event, 'chart.geohashGridAgg'); - const mapPrecision = zoomPrecision[event.zoom]; - uiState.set('vis.params.mapZoom', event.zoom); - uiState.set('vis.params.mapPrecision', mapPrecision); + uiState.set('mapZoom', event.zoom); if (!agg) return; agg.params.mapZoom = event.zoom; - if (!agg || !agg.params.autoPrecision) return; - - const precision = config.get('visualization:tileMap:maxPrecision'); - agg.params.precision = Math.min(zoomPrecision[event.zoom], precision); - courier.fetch(); } }, diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index 7bc15f3a793c..d39700bdc243 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -74,10 +74,11 @@ export default function GeoHashAggDefinition(Private, config) { }, deserialize: getPrecision, write: function (aggConfig, output) { - let currZoom = aggConfig.vis.params.mapZoom; + let currZoom = null; if (aggConfig.params.mapZoom || aggConfig.vis.uiState) { // First iteration - currZoom = aggConfig.vis.uiState ? aggConfig.vis.uiState.get('vis.params.mapZoom') : aggConfig.params.mapZoom; + currZoom = aggConfig.vis.uiState ? aggConfig.vis.uiState.get('mapZoom') : aggConfig.params.mapZoom; } + currZoom = currZoom || aggConfig.vis.params.mapZoom; const autoPrecisionVal = zoomPrecision[currZoom]; output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision); } diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index 94be068f76b0..67a352226277 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -101,8 +101,8 @@ export default function TileMapFactory(Private) { const container = $(selection).addClass('tilemap'); // Lol couldn't think of another way to access this object... const uiStateParams = { - mapCenter: this.handler.vis.uiState.get('vis.params.mapCenter'), - mapZoom: this.handler.vis.uiState.get('vis.params.mapZoom') + mapCenter: this.handler.vis.uiState.get('mapCenter'), + mapZoom: this.handler.vis.uiState.get('mapZoom') }; const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams); From bff827691b9743f7036aa19b1a1c37ee11cee46b Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Fri, 15 Apr 2016 14:56:00 -0400 Subject: [PATCH 06/13] [Remove] Commit to cleanup --- src/plugins/kbn_vislib_vis_types/public/tile_map.js | 5 ----- .../kibana/public/dashboard/components/panel/panel.js | 3 +++ src/ui/public/agg_types/buckets/geo_hash.js | 2 +- 3 files changed, 4 insertions(+), 6 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 9c68eeab26d1..feb5779f912f 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -50,22 +50,17 @@ export default function TileMapVisType(Private, getAppState, courier, config) { }, mapMoveEnd: function (event, uiState) { uiState.set('mapCenter', event.center); - uiState.set('mapZoom', event.zoom); const agg = _.get(event, 'chart.geohashGridAgg'); if (!agg) return; - agg.params.mapZoom = event.zoom; agg.params.mapCenter = event.center; const editableVis = agg.vis.getEditableVis(); if (!editableVis) return; - // editableVis.params.mapCenter = event.center; - // editableVis.params.mapZoom = event.zoom; const editableAgg = editableVis.aggs.byId[agg.id]; if (editableAgg) { - editableAgg.params.mapZoom = event.zoom; editableAgg.params.mapCenter = event.center; } }, diff --git a/src/plugins/kibana/public/dashboard/components/panel/panel.js b/src/plugins/kibana/public/dashboard/components/panel/panel.js index 4befb5c353bc..cc71a1cc4436 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/panel.js +++ b/src/plugins/kibana/public/dashboard/components/panel/panel.js @@ -55,6 +55,9 @@ uiModules // create child ui state from the savedObj const uiState = panelConfig.uiState || {}; $scope.uiState = $scope.parentUiState.createChild(getPanelId(panelConfig.panel), uiState, true); + if (panelConfig.uiState) { + panelConfig.uiState = $scope.uiState; + } $scope.filter = function (field, value, operator) { const index = $scope.savedObj.searchSource.get('index').id; diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index d39700bdc243..078c7e717489 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -70,9 +70,9 @@ export default function GeoHashAggDefinition(Private, config) { { name: 'precision', editor: precisionTemplate, + deserialize: getPrecision, controller: function ($scope) { }, - deserialize: getPrecision, write: function (aggConfig, output) { let currZoom = null; if (aggConfig.params.mapZoom || aggConfig.vis.uiState) { // First iteration From 3366e8135f8b2c957f4677b5ef9508de8a450e0c Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Mon, 25 Apr 2016 14:04:39 -0400 Subject: [PATCH 07/13] [UiState] Some cleanup of the uiState, and making it easier to access fromt eh vis --- .../components/panel/lib/visualization.js | 1 + .../dashboard/components/panel/panel.js | 3 +++ .../kibana/public/visualize/editor/editor.js | 3 ++- src/ui/public/agg_types/buckets/geo_hash.js | 4 ++-- src/ui/public/vis/vis.js | 22 ++++++++++++++++++- src/ui/public/vislib/lib/handler/handler.js | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js b/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js index 87b04bc1cb53..6965ee2da581 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js +++ b/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js @@ -16,6 +16,7 @@ export default function visualizationLoader(savedVisualizations, Private) { // I savedObj: savedVis, panel: panel, uiState: savedVis.uiStateJSON ? JSON.parse(savedVis.uiStateJSON) : {}, + setUiState(uiState) { savedVis.vis.setUiState(uiState); }, editUrl: savedVisualizations.urlFor(panel.id) }; }); diff --git a/src/plugins/kibana/public/dashboard/components/panel/panel.js b/src/plugins/kibana/public/dashboard/components/panel/panel.js index cc71a1cc4436..57bf78455047 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/panel.js +++ b/src/plugins/kibana/public/dashboard/components/panel/panel.js @@ -58,6 +58,9 @@ uiModules if (panelConfig.uiState) { panelConfig.uiState = $scope.uiState; } + if (panelConfig.setUiState) { + panelConfig.setUiState($scope.uiState); + } $scope.filter = function (field, value, operator) { const index = $scope.savedObj.searchSource.get('index').id; diff --git a/src/plugins/kibana/public/visualize/editor/editor.js b/src/plugins/kibana/public/visualize/editor/editor.js index 550b7236bd42..9edc7bbc1a24 100644 --- a/src/plugins/kibana/public/visualize/editor/editor.js +++ b/src/plugins/kibana/public/visualize/editor/editor.js @@ -138,7 +138,8 @@ uiModules $scope.indexPattern = vis.indexPattern; $scope.editableVis = editableVis; $scope.state = $state; - $scope.uiState = vis.uiState = $state.makeStateful('uiState'); + $scope.uiState = $state.makeStateful('uiState'); + vis.setUiState($scope.uiState); $scope.timefilter = timefilter; $scope.opts = _.pick($scope, 'doSave', 'savedVis', 'shareData', 'timefilter'); diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index 078c7e717489..841fc0310a2a 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -75,8 +75,8 @@ export default function GeoHashAggDefinition(Private, config) { }, write: function (aggConfig, output) { let currZoom = null; - if (aggConfig.params.mapZoom || aggConfig.vis.uiState) { // First iteration - currZoom = aggConfig.vis.uiState ? aggConfig.vis.uiState.get('mapZoom') : aggConfig.params.mapZoom; + if (aggConfig.params.mapZoom || aggConfig.vis.hasUiState()) { // First iteration + currZoom = aggConfig.vis.hasUiState() ? aggConfig.vis.uiStateVal('mapZoom') : aggConfig.params.mapZoom; } currZoom = currZoom || aggConfig.vis.params.mapZoom; const autoPrecisionVal = zoomPrecision[currZoom]; diff --git a/src/ui/public/vis/vis.js b/src/ui/public/vis/vis.js index dbf29fe41642..77bd9a02fa9a 100644 --- a/src/ui/public/vis/vis.js +++ b/src/ui/public/vis/vis.js @@ -11,7 +11,7 @@ export default function VisFactory(Notifier, Private) { location: 'Vis' }); - function Vis(indexPattern, state) { + function Vis(indexPattern, state, uiState) { state = state || {}; if (_.isString(state)) { @@ -24,6 +24,7 @@ export default function VisFactory(Notifier, Private) { // http://aphyr.com/data/posts/317/state.gif this.setState(state); + this.__uiState = uiState; } Vis.convertOldState = function (type, oldState) { @@ -125,5 +126,24 @@ export default function VisFactory(Notifier, Private) { }); }; + Vis.prototype.hasUiState = function () { + return !!this.__uiState; + }; + Vis.prototype.setUiState = function (uiState) { + this.__uiState = uiState; + }; + Vis.prototype.getUiState = function () { + return this.__uiState; + }; + Vis.prototype.uiStateVal = function(key, val) { + if (this.hasUiState()) { + if (_.isUndefined(val)) { + return this.__uiState.get(key); + } + return this.__uiState.set(key, val); + } + return val; + }; + return Vis; }; diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index e496c1b39271..ec2f5efcd0d9 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -23,7 +23,7 @@ export default function HandlerBaseClass(Private) { return new Handler(vis, opts); } - this.data = opts.data || new Data(vis.data, vis._attr, vis.uiState); + this.data = opts.data || new Data(vis.data, vis._attr, vis.getUiState()); this.vis = vis; this.el = vis.el; this.ChartClass = vis.ChartClass; From bd4b5c6092d126b621bb29835370f400be52d81e Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Mon, 25 Apr 2016 14:52:31 -0400 Subject: [PATCH 08/13] [AggConfigParams] Some cleanup of the agg config params, and other straggling code --- .../kbn_vislib_vis_types/public/tile_map.js | 23 ++++--------------- .../dashboard/components/panel/panel.js | 3 --- .../public/agg_response/geo_json/geo_json.js | 4 ++-- src/ui/public/agg_types/buckets/geo_hash.js | 7 ++---- src/ui/public/vis/vis.js | 4 ++-- src/ui/public/vislib/lib/handler/handler.js | 2 +- .../public/vislib/visualizations/tile_map.js | 7 ++---- 7 files changed, 14 insertions(+), 36 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 feb5779f912f..e44f1f6b5952 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -50,28 +50,15 @@ export default function TileMapVisType(Private, getAppState, courier, config) { }, mapMoveEnd: function (event, uiState) { uiState.set('mapCenter', event.center); - - const agg = _.get(event, 'chart.geohashGridAgg'); - if (!agg) return; - agg.params.mapCenter = event.center; - - const editableVis = agg.vis.getEditableVis(); - if (!editableVis) return; - - - const editableAgg = editableVis.aggs.byId[agg.id]; - if (editableAgg) { - editableAgg.params.mapCenter = event.center; - } + uiState.set('mapZoom', event.zoom); }, mapZoomEnd: function (event, uiState) { - const agg = _.get(event, 'chart.geohashGridAgg'); uiState.set('mapZoom', event.zoom); - if (!agg) return; - agg.params.mapZoom = event.zoom; - - courier.fetch(); + const agg = _.get(event, 'chart.geohashGridAgg'); + if (agg && agg.params.autoPrecision) { + courier.fetch(); + } } }, responseConverter: geoJsonConverter, diff --git a/src/plugins/kibana/public/dashboard/components/panel/panel.js b/src/plugins/kibana/public/dashboard/components/panel/panel.js index 57bf78455047..06caf3b91f72 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/panel.js +++ b/src/plugins/kibana/public/dashboard/components/panel/panel.js @@ -55,9 +55,6 @@ uiModules // create child ui state from the savedObj const uiState = panelConfig.uiState || {}; $scope.uiState = $scope.parentUiState.createChild(getPanelId(panelConfig.panel), uiState, true); - if (panelConfig.uiState) { - panelConfig.uiState = $scope.uiState; - } if (panelConfig.setUiState) { panelConfig.setUiState($scope.uiState); } 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 6c01ac567792..4cdbe1cfd323 100644 --- a/src/ui/public/agg_response/geo_json/geo_json.js +++ b/src/ui/public/agg_response/geo_json/geo_json.js @@ -34,8 +34,8 @@ export default function TileMapConverterFn(Private, timefilter, $compile, $rootS properties: { min: _.min(values), max: _.max(values), - zoom: _.get(geoAgg, 'params.mapZoom'), - center: _.get(geoAgg, 'params.mapCenter') + zoom: geoAgg.vis.uiStateVal('mapZoom'), + center: geoAgg.vis.uiStateVal('mapCenter') } } }; diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index 841fc0310a2a..a38775f8fb7f 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -74,11 +74,8 @@ export default function GeoHashAggDefinition(Private, config) { controller: function ($scope) { }, write: function (aggConfig, output) { - let currZoom = null; - if (aggConfig.params.mapZoom || aggConfig.vis.hasUiState()) { // First iteration - currZoom = aggConfig.vis.hasUiState() ? aggConfig.vis.uiStateVal('mapZoom') : aggConfig.params.mapZoom; - } - currZoom = currZoom || aggConfig.vis.params.mapZoom; + const vis = aggConfig.vis; + const currZoom = vis.hasUiState() ? vis.uiStateVal('mapZoom') : vis.params.mapZoom; const autoPrecisionVal = zoomPrecision[currZoom]; output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision); } diff --git a/src/ui/public/vis/vis.js b/src/ui/public/vis/vis.js index 77bd9a02fa9a..b94ae5250833 100644 --- a/src/ui/public/vis/vis.js +++ b/src/ui/public/vis/vis.js @@ -103,7 +103,7 @@ export default function VisFactory(Notifier, Private) { }; Vis.prototype.clone = function () { - return new Vis(this.indexPattern, this.getState()); + return new Vis(this.indexPattern, this.getState(), this.getUiState()); }; Vis.prototype.requesting = function () { @@ -135,7 +135,7 @@ export default function VisFactory(Notifier, Private) { Vis.prototype.getUiState = function () { return this.__uiState; }; - Vis.prototype.uiStateVal = function(key, val) { + Vis.prototype.uiStateVal = function (key, val) { if (this.hasUiState()) { if (_.isUndefined(val)) { return this.__uiState.get(key); diff --git a/src/ui/public/vislib/lib/handler/handler.js b/src/ui/public/vislib/lib/handler/handler.js index ec2f5efcd0d9..e496c1b39271 100644 --- a/src/ui/public/vislib/lib/handler/handler.js +++ b/src/ui/public/vislib/lib/handler/handler.js @@ -23,7 +23,7 @@ export default function HandlerBaseClass(Private) { return new Handler(vis, opts); } - this.data = opts.data || new Data(vis.data, vis._attr, vis.getUiState()); + this.data = opts.data || new Data(vis.data, vis._attr, vis.uiState); this.vis = vis; this.el = vis.el; this.ChartClass = vis.ChartClass; diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index 67a352226277..aa23fc3f75bb 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -99,16 +99,13 @@ export default function TileMapFactory(Private) { */ TileMap.prototype._appendMap = function (selection) { const container = $(selection).addClass('tilemap'); - // Lol couldn't think of another way to access this object... - const uiStateParams = { + const uiStateParams = this.handler.vis ? { mapCenter: this.handler.vis.uiState.get('mapCenter'), mapZoom: this.handler.vis.uiState.get('mapZoom') - }; + } : {}; const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams); - // this.handler.vis.uiState - const map = new TileMapMap(container, this._chartData, { center: params.mapCenter, zoom: params.mapZoom, From dfdf71384383f49c3f35d27f5cee294f002c5d54 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Tue, 26 Apr 2016 13:46:39 -0400 Subject: [PATCH 09/13] [Tests] Fixing tests --- src/fixtures/vislib/mock_data/geohash/_geo_json.js | 1 + .../public/vislib/__tests__/visualizations/tile_maps/tile_map.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/fixtures/vislib/mock_data/geohash/_geo_json.js b/src/fixtures/vislib/mock_data/geohash/_geo_json.js index 04e147974e92..b0889a9ed027 100644 --- a/src/fixtures/vislib/mock_data/geohash/_geo_json.js +++ b/src/fixtures/vislib/mock_data/geohash/_geo_json.js @@ -2,6 +2,7 @@ import _ from 'lodash'; module.exports = { 'valueFormatter': _.identity, + 'geohashGridAgg': { 'vis': { 'params': {} } }, 'geoJson': { 'type': 'FeatureCollection', 'features': [ diff --git a/src/ui/public/vislib/__tests__/visualizations/tile_maps/tile_map.js b/src/ui/public/vislib/__tests__/visualizations/tile_maps/tile_map.js index d1f4c3235fd0..411b924265c4 100644 --- a/src/ui/public/vislib/__tests__/visualizations/tile_maps/tile_map.js +++ b/src/ui/public/vislib/__tests__/visualizations/tile_maps/tile_map.js @@ -81,6 +81,7 @@ describe('TileMap Tests', function () { it('should only add controls if data exists', function () { let noData = { + geohashGridAgg: { vis: { params: {} } }, geoJson: { features: [], properties: {}, From b3bc6c83f4f9b2e2d8c07a03314a9b94d0953a9b Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Thu, 5 May 2016 18:45:02 -0400 Subject: [PATCH 10/13] [Zoom] fixing bugs with inital load, and load with empty data --- src/ui/public/agg_response/geo_json/geo_json.js | 4 ++-- src/ui/public/agg_types/buckets/geo_hash.js | 4 ++-- src/ui/public/vislib/visualizations/tile_map.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) 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 4cdbe1cfd323..aac0fba22298 100644 --- a/src/ui/public/agg_response/geo_json/geo_json.js +++ b/src/ui/public/agg_response/geo_json/geo_json.js @@ -34,8 +34,8 @@ export default function TileMapConverterFn(Private, timefilter, $compile, $rootS properties: { min: _.min(values), max: _.max(values), - zoom: geoAgg.vis.uiStateVal('mapZoom'), - center: geoAgg.vis.uiStateVal('mapCenter') + zoom: geoAgg && geoAgg.vis.uiStateVal('mapZoom'), + center: geoAgg && geoAgg.vis.uiStateVal('mapCenter') } } }; diff --git a/src/ui/public/agg_types/buckets/geo_hash.js b/src/ui/public/agg_types/buckets/geo_hash.js index a38775f8fb7f..ebc96eae78c4 100644 --- a/src/ui/public/agg_types/buckets/geo_hash.js +++ b/src/ui/public/agg_types/buckets/geo_hash.js @@ -75,8 +75,8 @@ export default function GeoHashAggDefinition(Private, config) { }, write: function (aggConfig, output) { const vis = aggConfig.vis; - const currZoom = vis.hasUiState() ? vis.uiStateVal('mapZoom') : vis.params.mapZoom; - const autoPrecisionVal = zoomPrecision[currZoom]; + const currZoom = vis.hasUiState() && vis.uiStateVal('mapZoom'); + const autoPrecisionVal = zoomPrecision[(currZoom || vis.params.mapZoom)]; output.params.precision = aggConfig.params.autoPrecision ? autoPrecisionVal : getPrecision(aggConfig.params.precision); } } diff --git a/src/ui/public/vislib/visualizations/tile_map.js b/src/ui/public/vislib/visualizations/tile_map.js index aa23fc3f75bb..bc3d3bab83a7 100644 --- a/src/ui/public/vislib/visualizations/tile_map.js +++ b/src/ui/public/vislib/visualizations/tile_map.js @@ -104,7 +104,7 @@ export default function TileMapFactory(Private) { mapZoom: this.handler.vis.uiState.get('mapZoom') } : {}; - const params = _.assign({}, this._chartData.geohashGridAgg.vis.params, uiStateParams); + const params = _.assign({}, _.get(this._chartData, 'geoAgg.vis.params'), uiStateParams); const map = new TileMapMap(container, this._chartData, { center: params.mapCenter, From ff972840db8566484bbbd08e0d469cc48106a6a1 Mon Sep 17 00:00:00 2001 From: Khalah Jones-Golden Date: Tue, 10 May 2016 16:18:36 -0400 Subject: [PATCH 11/13] [Map] addressed some issues --- src/plugins/kbn_vislib_vis_types/public/tile_map.js | 4 ++-- src/ui/public/vis/vis.js | 10 +++++++--- 2 files changed, 9 insertions(+), 5 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 e44f1f6b5952..5bff93cc9996 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -55,8 +55,8 @@ export default function TileMapVisType(Private, getAppState, courier, config) { mapZoomEnd: function (event, uiState) { uiState.set('mapZoom', event.zoom); - const agg = _.get(event, 'chart.geohashGridAgg'); - if (agg && agg.params.autoPrecision) { + const autoPrecision = _.get(event, 'chart.geohashGridAgg.params.autoPrecision'); + if (autoPrecision) { courier.fetch(); } } diff --git a/src/ui/public/vis/vis.js b/src/ui/public/vis/vis.js index b94ae5250833..46cda6250201 100644 --- a/src/ui/public/vis/vis.js +++ b/src/ui/public/vis/vis.js @@ -2,6 +2,7 @@ import _ from 'lodash'; import AggTypesIndexProvider from 'ui/agg_types/index'; import RegistryVisTypesProvider from 'ui/registry/vis_types'; import VisAggConfigsProvider from 'ui/vis/agg_configs'; +import PersistedState from 'ui/persisted_state/persisted_state'; export default function VisFactory(Notifier, Private) { let aggTypes = Private(AggTypesIndexProvider); let visTypes = Private(RegistryVisTypesProvider); @@ -24,7 +25,7 @@ export default function VisFactory(Notifier, Private) { // http://aphyr.com/data/posts/317/state.gif this.setState(state); - this.__uiState = uiState; + this.setUiState(uiState); } Vis.convertOldState = function (type, oldState) { @@ -103,7 +104,8 @@ export default function VisFactory(Notifier, Private) { }; Vis.prototype.clone = function () { - return new Vis(this.indexPattern, this.getState(), this.getUiState()); + const uiJson = this.hasUiState() ? this.getUiState().toJSON() : {}; + return new Vis(this.indexPattern, this.getState(), uiJson); }; Vis.prototype.requesting = function () { @@ -130,7 +132,9 @@ export default function VisFactory(Notifier, Private) { return !!this.__uiState; }; Vis.prototype.setUiState = function (uiState) { - this.__uiState = uiState; + if (uiState instanceof PersistedState) { + this.__uiState = uiState; + } }; Vis.prototype.getUiState = function () { return this.__uiState; From fd30551cd8cb96a3525f17a1cae6140378dc3aac Mon Sep 17 00:00:00 2001 From: Khalah Jones Golden Date: Thu, 12 May 2016 19:01:55 -0400 Subject: [PATCH 12/13] [Visualize] fixing PersistentState object, Removed code from Dashboard panel --- .../public/dashboard/components/panel/lib/visualization.js | 1 - .../kibana/public/dashboard/components/panel/panel.js | 5 +++-- src/ui/public/vis/vis.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js b/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js index 6965ee2da581..87b04bc1cb53 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js +++ b/src/plugins/kibana/public/dashboard/components/panel/lib/visualization.js @@ -16,7 +16,6 @@ export default function visualizationLoader(savedVisualizations, Private) { // I savedObj: savedVis, panel: panel, uiState: savedVis.uiStateJSON ? JSON.parse(savedVis.uiStateJSON) : {}, - setUiState(uiState) { savedVis.vis.setUiState(uiState); }, editUrl: savedVisualizations.urlFor(panel.id) }; }); diff --git a/src/plugins/kibana/public/dashboard/components/panel/panel.js b/src/plugins/kibana/public/dashboard/components/panel/panel.js index 06caf3b91f72..940948d31d29 100644 --- a/src/plugins/kibana/public/dashboard/components/panel/panel.js +++ b/src/plugins/kibana/public/dashboard/components/panel/panel.js @@ -55,8 +55,9 @@ uiModules // create child ui state from the savedObj const uiState = panelConfig.uiState || {}; $scope.uiState = $scope.parentUiState.createChild(getPanelId(panelConfig.panel), uiState, true); - if (panelConfig.setUiState) { - panelConfig.setUiState($scope.uiState); + const panelSavedVis = _.get(panelConfig, 'savedObj.vis'); // Sometimes this will be a search, and undef + if (panelSavedVis) { + panelSavedVis.setUiState($scope.uiState); } $scope.filter = function (field, value, operator) { diff --git a/src/ui/public/vis/vis.js b/src/ui/public/vis/vis.js index 46cda6250201..864d221de091 100644 --- a/src/ui/public/vis/vis.js +++ b/src/ui/public/vis/vis.js @@ -2,11 +2,12 @@ import _ from 'lodash'; import AggTypesIndexProvider from 'ui/agg_types/index'; import RegistryVisTypesProvider from 'ui/registry/vis_types'; import VisAggConfigsProvider from 'ui/vis/agg_configs'; -import PersistedState from 'ui/persisted_state/persisted_state'; +import PersistedStateProvider from 'ui/persisted_state/persisted_state'; export default function VisFactory(Notifier, Private) { let aggTypes = Private(AggTypesIndexProvider); let visTypes = Private(RegistryVisTypesProvider); let AggConfigs = Private(VisAggConfigsProvider); + const PersistedState = Private(PersistedStateProvider); let notify = new Notifier({ location: 'Vis' From cb758cc1a3309c52c64c5d174f96234336299ba1 Mon Sep 17 00:00:00 2001 From: Khalah Jones Golden Date: Fri, 27 May 2016 09:16:54 -0400 Subject: [PATCH 13/13] [TileMap] Removing unnecessary zoom set --- src/plugins/kbn_vislib_vis_types/public/tile_map.js | 1 - 1 file changed, 1 deletion(-) 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 5bff93cc9996..cb6ae028cf2b 100644 --- a/src/plugins/kbn_vislib_vis_types/public/tile_map.js +++ b/src/plugins/kbn_vislib_vis_types/public/tile_map.js @@ -50,7 +50,6 @@ export default function TileMapVisType(Private, getAppState, courier, config) { }, mapMoveEnd: function (event, uiState) { uiState.set('mapCenter', event.center); - uiState.set('mapZoom', event.zoom); }, mapZoomEnd: function (event, uiState) { uiState.set('mapZoom', event.zoom);