mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
9bf1906a90
commit
06e4388b95
3 changed files with 29 additions and 12 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue