Skip to content
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

fix map resize + small improvement suggestions #13230

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/core_plugins/tile_map/public/maps_visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState
return new Promise(async(resolve) => {

await this._kibanaMapReady;

if (status.resize) {
console.log('resize');
this._kibanaMap.resize();
} else {
console.log('no resize', status.resize);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reorder to ensure map always resizes, even if no data on map

if (status.params || status.aggs) await this._updateParams();

if (esResponse && typeof esResponse.geohashGridAgg === 'undefined') {
Expand All @@ -54,10 +62,6 @@ export function MapsVisualizationProvider(serviceSettings, Notifier, getAppState
if (status.uiState) {
this._kibanaMap.useUiStateFromVisualization(this.vis);
}
if (status.resize) {
this._kibanaMap.resize();
}

this._doRenderComplete(resolve);

});
Expand Down
24 changes: 18 additions & 6 deletions src/ui/public/vis/update_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ function serializer() {
}

const getUpdateStatus = ($scope) => {
if (!$scope._oldStatus) $scope._oldStatus = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_oldStatus should be string-map iso array i think


if (!$scope._oldStatus) {
$scope._oldStatus = {};
}
const hasChanged = (name, value) => {
const currentValue = JSON.stringify(value, serializer());
if (currentValue !== $scope._oldStatus[name]) {
Expand All @@ -33,15 +34,26 @@ const getUpdateStatus = ($scope) => {
return false;
};

const status = {
function hasSizeChanged(oldStatus, newSize) {
if (!newSize) {
return true;
}
if (!oldStatus.size) {//initialize
oldStatus.size = newSize.slice();
return true;
}
const hasChanged = oldStatus.size[0] !== newSize[0] || oldStatus.size[1] !== newSize[1];
oldStatus.size = newSize.slice();
return hasChanged;
}

return {
aggs: hasChanged('aggs', $scope.vis.aggs),
data: hasChanged('data', $scope.visData),
params: hasChanged('param', $scope.vis.params),
resize: hasChanged('resize', $scope.vis.size),
resize: hasSizeChanged($scope._oldStatus, $scope.vis.size),
uiState: hasChanged('uiState', $scope.uiState)
};

return status;
};

module.exports = { getUpdateStatus };
15 changes: 12 additions & 3 deletions src/ui/public/visualize/visualization.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,21 @@ uiModules
template: visualizationTemplate,
link: function ($scope, $el) {
const minVisChartHeight = 180;
const resizeChecker = new ResizeChecker($el);
const visualizationPlusEditorResizeChecker = new ResizeChecker($el);

//todo: lets make this a simple function call.
const getVisEl = jQueryGetter('.visualize-chart');
const getVisContainer = jQueryGetter('.vis-container');
const getSpyContainer = jQueryGetter('.visualize-spy-container');

const visElement = getVisEl();
const chartResizeChecker = new ResizeChecker(visElement);
chartResizeChecker.on('resize', _.debounce(()=>{
$scope.vis.size = [visElement.width(), visElement.height()];
$scope.$emit('render');
}, 200));


// Show no results message when isZeroHits is true and it requires search
$scope.showNoResultsMessage = function () {
const requiresSearch = _.get($scope, 'vis.type.requiresSearch');
Expand Down Expand Up @@ -124,8 +132,9 @@ uiModules
});

$scope.$on('$destroy', () => {
resizeChecker.destroy();
visualizationPlusEditorResizeChecker.destroy();
visualization.destroy();
chartResizeChecker.destroy();
});

if (!$scope.vis.visualizeScope) {
Expand All @@ -138,7 +147,7 @@ uiModules
if (!resizeInit) return resizeInit = true;
$scope.$emit('render');
}, 200);
resizeChecker.on('resize', resizeFunc);
visualizationPlusEditorResizeChecker.on('resize', resizeFunc);
}

function jQueryGetter(selector) {
Expand Down
5 changes: 1 addition & 4 deletions src/ui/public/visualize/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ uiModules
});
}

let resizeInit = false;
const resizeFunc = _.debounce(() => {
if (!resizeInit) return resizeInit = true;
$scope.vis.size = [$el.width(), $el.height()];
$scope.$broadcast('render');
}, 200);
resizeChecker.on('resize', resizeFunc);

// visualize needs to know about timeFilter
// visualize needs to know about timeFilter
$scope.$listen(timefilter, 'fetch', $scope.fetch);
$scope.$on('renderComplete', () => {
$el.trigger('renderComplete');
Expand Down