Skip to content

Commit

Permalink
[Precision] Experimenting with precision...
Browse files Browse the repository at this point in the history
  • Loading branch information
panda01 committed Apr 11, 2016
1 parent 9ac4961 commit d7b3cb5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/plugins/kbn_vislib_vis_types/public/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana/public/visualize/editor/agg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/kibana/public/visualize/editor/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/public/agg_response/geo_json/geo_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
};
Expand Down
43 changes: 38 additions & 5 deletions src/ui/public/agg_types/buckets/geo_hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/vislib/visualizations/tile_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit d7b3cb5

Please sign in to comment.