Skip to content

Commit

Permalink
redraw layers when vis params updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Oct 28, 2016
1 parent e1c8030 commit 1a69f15
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
6 changes: 6 additions & 0 deletions public/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ define(function (require) {
}

return {
getGeoExtents: function(visData) {
return {
min: visData.geoJson.properties.min,
max: visData.geoJson.properties.max
}
},
/*
* @param bounds {LatLngBounds}
* @param scale {number}
Expand Down
70 changes: 36 additions & 34 deletions public/visController.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define(function (require) {
const ResizeChecker = Private(require('ui/vislib/lib/resize_checker'));
let map = null;
let collar = null;
let chartData = null;
appendMap();
modifyToDsl();

Expand All @@ -46,8 +47,13 @@ define(function (require) {
}
});
console.log("geogrids: " + numGeoBuckets);
if(numGeoBuckets === 0) return;
return this.buildChartData(resp);
if(numGeoBuckets === 0) return null;

const chartData = this.buildChartData(resp);
const geoMinMax = utils.getGeoExtents(chartData);
chartData.geoJson.properties.allmin = geoMinMax.min;
chartData.geoJson.properties.allmax = geoMinMax.max;
return chartData;
},
vis: $scope.vis
}
Expand Down Expand Up @@ -83,42 +89,21 @@ define(function (require) {
return filter;
}

function getGeoExtents(visData) {
return {
min: visData.geoJson.properties.min,
max: visData.geoJson.properties.max
$scope.$watch('vis.aggs', function (resp) {
//'apply changes' creates new vis.aggs object - ensure toDsl is overwritten again
if(!_.has($scope.vis.aggs, "origToDsl")) {
modifyToDsl();
}
}
});

$scope.$watch('vis.params', function (resp) {
draw();
});

$scope.$watch('esResponse', function (resp) {
if(_.has(resp, 'aggregations')) {
/*
* 'apply changes' creates new vis.aggs object
* Modify toDsl function and refetch data.
*/
if(!_.has($scope.vis.aggs, "origToDsl")) {
modifyToDsl();
courier.fetch();
return;
}
const chartData = respProcessor.process(resp);
if(!chartData) return;
const geoMinMax = getGeoExtents(chartData);
chartData.geoJson.properties.allmin = geoMinMax.min;
chartData.geoJson.properties.allmax = geoMinMax.max;
const agg = _.get(chartData, 'geohashGridAgg');
if (agg) {
map.addFilters(getGeoFilters(agg.fieldName()));
}
if (_.get($scope.vis.params, 'overlay.wms.enabled')) {
addWmsOverlays();
}
map.addMarkers(
chartData,
$scope.vis.params,
Private(require('ui/agg_response/geo_json/_tooltip_formatter')),
_.get(chartData, 'valueFormatter', _.identity),
collar);
chartData = respProcessor.process(resp);
draw();
}
});

Expand All @@ -128,6 +113,23 @@ define(function (require) {
if (map) map.destroy();
});

function draw() {
if(!chartData) return;
const agg = _.get(chartData, 'geohashGridAgg');
if (agg) {
map.addFilters(getGeoFilters(agg.fieldName()));
}
if (_.get($scope.vis.params, 'overlay.wms.enabled')) {
addWmsOverlays();
}
map.addMarkers(
chartData,
$scope.vis.params,
Private(require('ui/agg_response/geo_json/_tooltip_formatter')),
_.get(chartData, 'valueFormatter', _.identity),
collar);
}

function getGeoFilters(field) {
let filters = [];
_.flatten([queryFilter.getAppFilters(), queryFilter.getGlobalFilters()]).forEach(function (it) {
Expand Down

0 comments on commit 1a69f15

Please sign in to comment.