Fix pushed down chart on multi line horizontal legends (#31466) (#32128)

This commit is contained in:
Joe Reuter 2019-03-01 11:40:28 +01:00 committed by GitHub
parent 9bf1906a90
commit 06e4388b95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 12 deletions

View file

@ -24,6 +24,7 @@ import { uiModules } from '../../modules';
import { VisFiltersProvider } from '../vis_filters';
import { htmlIdGenerator, keyCodes } from '@elastic/eui';
export const CUSTOM_LEGEND_VIS_TYPES = ['heatmap', 'gauge'];
uiModules.get('kibana')
.directive('vislibLegend', function (Private, $timeout, i18n) {
@ -106,6 +107,9 @@ uiModules.get('kibana')
};
$scope.canFilter = function (legendData) {
if (CUSTOM_LEGEND_VIS_TYPES.includes($scope.vis.vislibVis.visConfigArgs.type)) {
return false;
}
const filters = visFilters.filter({ datum: legendData, shallow: true }, { simulate: true });
return filters.length;
};
@ -151,7 +155,7 @@ uiModules.get('kibana')
$scope.open = $scope.vis.params.addLegend;
}
if (['heatmap', 'gauge'].includes(vislibVis.visConfigArgs.type)) {
if (CUSTOM_LEGEND_VIS_TYPES.includes(vislibVis.visConfigArgs.type)) {
const labels = vislibVis.getLegendLabels();
if (labels) {
$scope.labels = _.map(labels, label => {

View file

@ -23,7 +23,7 @@ import 'plugins/kbn_vislib_vis_types/controls/line_interpolation_option';
import 'plugins/kbn_vislib_vis_types/controls/heatmap_options';
import 'plugins/kbn_vislib_vis_types/controls/gauge_options';
import 'plugins/kbn_vislib_vis_types/controls/point_series';
import './vislib_vis_legend';
import { CUSTOM_LEGEND_VIS_TYPES } from './vislib_vis_legend';
import { BaseVisTypeProvider } from './base_vis_type';
import { AggResponsePointSeriesProvider } from '../../agg_response/point_series/point_series';
import VislibProvider from '../../vislib';
@ -70,6 +70,13 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
return resolve();
}
this.vis.vislibVis = new vislib.Vis(this.chartEl, this.vis.params);
this.vis.vislibVis.on('brush', this.vis.API.events.brush);
this.vis.vislibVis.on('click', this.vis.API.events.filter);
this.vis.vislibVis.on('renderComplete', resolve);
this.vis.vislibVis.initVisConfig(esResponse, this.vis.getUiState());
if (this.vis.params.addLegend) {
$(this.container).attr('class', (i, cls) => {
return cls.replace(/visLib--legend-\S+/g, '');
@ -85,15 +92,16 @@ export function VislibVisTypeProvider(Private, $rootScope, $timeout, $compile) {
this.$scope.$digest();
}
this.vis.vislibVis = new vislib.Vis(this.chartEl, this.vis.params);
this.vis.vislibVis.on('brush', this.vis.API.events.brush);
this.vis.vislibVis.on('click', this.vis.API.events.filter);
this.vis.vislibVis.on('renderComplete', resolve);
this.vis.vislibVis.render(esResponse, this.vis.getUiState());
if (this.vis.params.addLegend) {
// refreshing the legend after the chart is rendered.
// this is necessary because some visualizations
// provide data necessary for the legend only after a render cycle.
if (this.vis.params.addLegend && CUSTOM_LEGEND_VIS_TYPES.includes(this.vis.vislibVis.visConfigArgs.type)) {
this.$scope.refreshLegend++;
this.$scope.$digest();
this.vis.vislibVis.render(esResponse, this.vis.getUiState());
}
});
}

View file

@ -47,6 +47,15 @@ export function VislibVisProvider(Private) {
hasLegend() {
return this.visConfigArgs.addLegend;
}
initVisConfig(data, uiState) {
this.data = data;
this.uiState = uiState;
this.visConfig = new VisConfig(this.visConfigArgs, this.data, this.uiState, this.el);
}
/**
* Renders the visualization
*
@ -63,11 +72,7 @@ export function VislibVisProvider(Private) {
this._runOnHandler('destroy');
}
this.data = data;
this.uiState = uiState;
this.visConfig = new VisConfig(this.visConfigArgs, this.data, this.uiState, this.el);
this.initVisConfig(data, uiState);
this.handler = new Handler(this, this.visConfig);
this._runOnHandler('render');