Skip to content

Commit

Permalink
removes vislib_vis_type (elastic#45874) (elastic#46103)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar committed Sep 19, 2019
1 parent c8a0a3f commit dfb7545
Show file tree
Hide file tree
Showing 21 changed files with 248 additions and 461 deletions.
15 changes: 9 additions & 6 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { visFactory } from 'ui/vis/vis_factory';
import { i18n } from '@kbn/i18n';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggGroupNames } from 'ui/vis/editors/default';
Expand All @@ -33,19 +33,19 @@ import {
ThresholdLineStyles,
getConfigCollections,
} from './utils/collections';
import { getAreaOptionTabs, getCountLabel } from './utils/common_config';
import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { palettes } from '@elastic/eui/lib/services';
import { vislibVisController } from './controller';

export default function PointSeriesVisType(Private) {
const VisFactory = Private(VisFactoryProvider);
const countLabel = getCountLabel();
export default function PointSeriesVisType() {

return VisFactory.createVislibVisualization({
return visFactory.createBaseVisualization({
name: 'area',
title: i18n.translate('kbnVislibVisTypes.area.areaTitle', { defaultMessage: 'Area' }),
icon: 'visArea',
description: i18n.translate(
'kbnVislibVisTypes.area.areaDescription', { defaultMessage: 'Emphasize the quantity beneath a line chart' }),
visualization: vislibVisController,
visConfig: {
defaults: {
type: 'area',
Expand Down Expand Up @@ -124,6 +124,9 @@ export default function PointSeriesVisType(Private) {
labels: {}
},
},
events: {
brush: { disabled: false },
},
editorConfig: {
collections: getConfigCollections(),
optionTabs: getAreaOptionTabs(),
Expand Down
117 changes: 117 additions & 0 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/


import $ from 'jquery';
import { CUSTOM_LEGEND_VIS_TYPES } from '../../../ui/public/vis/vis_types/vislib_vis_legend';
import { VislibVisProvider } from '../../../ui/public/vislib/vis';
import chrome from '../../../ui/public/chrome';

const legendClassName = {
top: 'visLib--legend-top',
bottom: 'visLib--legend-bottom',
left: 'visLib--legend-left',
right: 'visLib--legend-right',
};


export class vislibVisController {
constructor(el, vis) {
this.el = el;
this.vis = vis;
this.$scope = null;

this.container = document.createElement('div');
this.container.className = 'visLib';
this.el.appendChild(this.container);

this.chartEl = document.createElement('div');
this.chartEl.className = 'visLib__chart';
this.container.appendChild(this.chartEl);
}

render(esResponse, visParams) {
if (this.vis.vislibVis) {
this.destroy();
}

return new Promise(async (resolve) => {
if (!this.vislib) {
const $injector = await chrome.dangerouslyGetActiveInjector();
const Private = $injector.get('Private');
this.Vislib = Private(VislibVisProvider);
this.$compile = $injector.get('$compile');
this.$rootScope = $injector.get('$rootScope');
}

if (this.el.clientWidth === 0 || this.el.clientHeight === 0) {
return resolve();
}

this.vis.vislibVis = new this.Vislib(this.chartEl, visParams);
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 (visParams.addLegend) {
$(this.container).attr('class', (i, cls) => {
return cls.replace(/visLib--legend-\S+/g, '');
}).addClass(legendClassName[visParams.legendPosition]);

this.$scope = this.$rootScope.$new();
this.$scope.refreshLegend = 0;
this.$scope.vis = this.vis;
this.$scope.visData = esResponse;
this.$scope.visParams = visParams;
this.$scope.uiState = this.$scope.vis.getUiState();
const legendHtml = this.$compile('<vislib-legend></vislib-legend>')(this.$scope);
this.container.appendChild(legendHtml[0]);
this.$scope.$digest();
}

this.vis.vislibVis.render(esResponse, this.vis.getUiState());

// 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 (visParams.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());
}
});
}

destroy() {
if (this.vis.vislibVis) {
this.vis.vislibVis.off('brush', this.vis.API.events.brush);
this.vis.vislibVis.off('click', this.vis.API.events.filter);
this.vis.vislibVis.destroy();
delete this.vis.vislibVis;
}
$(this.container).find('vislib-legend').remove();
if (this.$scope) {
this.$scope.$destroy();
this.$scope = null;
}
}
}
13 changes: 5 additions & 8 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/gauge.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
*/

import { i18n } from '@kbn/i18n';
import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { visFactory } from 'ui/vis/vis_factory';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { colorSchemas } from 'ui/vislib/components/color/colormaps';
import { GaugeOptions } from './components/options';
import { vislibVisController } from './controller';

export default function GaugeVisType(Private) {
const VisFactory = Private(VisFactoryProvider);

return VisFactory.createVislibVisualization({
export default function GaugeVisType() {
return visFactory.createBaseVisualization({
name: 'gauge',
title: i18n.translate('kbnVislibVisTypes.gauge.gaugeTitle', { defaultMessage: 'Gauge' }),
icon: 'visGauge',
Expand Down Expand Up @@ -79,9 +78,7 @@ export default function GaugeVisType(Private) {
}
},
},
events: {
brush: { disabled: true },
},
visualization: vislibVisController,
editorConfig: {
collections: {
gaugeTypes: [
Expand Down
12 changes: 5 additions & 7 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/goal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@
* under the License.
*/

import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { i18n } from '@kbn/i18n';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { colorSchemas } from 'ui/vislib/components/color/colormaps';
import { GaugeOptions } from './components/options';
import { vislibVisController } from './controller';
import { visFactory } from '../../../ui/public/vis/vis_factory';

export default function GoalVisType(Private) {
const VisFactory = Private(VisFactoryProvider);
export default function GoalVisType() {

return VisFactory.createVislibVisualization({
return visFactory.createBaseVisualization({
name: 'goal',
title: i18n.translate('kbnVislibVisTypes.goal.goalTitle', { defaultMessage: 'Goal' }),
icon: 'visGoal',
description: i18n.translate('kbnVislibVisTypes.goal.goalDescription', {
defaultMessage: 'A goal chart indicates how close you are to your final goal.'
}),
visualization: vislibVisController,
visConfig: {
defaults: {
addTooltip: true,
Expand Down Expand Up @@ -75,9 +76,6 @@ export default function GoalVisType(Private) {
}
},
},
events: {
brush: { disabled: true },
},
editorConfig: {
collections: {
gaugeTypes: [
Expand Down
13 changes: 9 additions & 4 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
* under the License.
*/

import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { visFactory } from '../../../ui/public/vis/vis_factory';
import { i18n } from '@kbn/i18n';
import { Schemas } from 'ui/vis/editors/default/schemas';
import heatmapTemplate from './editors/heatmap.html';
import { vislibColorMaps } from 'ui/vislib/components/color/colormaps';
import { vislibVisController } from './controller';
import './controls/heatmap_options';

export default function HeatmapVisType(Private) {
const VisFactory = Private(VisFactoryProvider);
export default function HeatmapVisType() {

return VisFactory.createVislibVisualization({
return visFactory.createBaseVisualization({
name: 'heatmap',
title: i18n.translate('kbnVislibVisTypes.heatmap.heatmapTitle', { defaultMessage: 'Heat Map' }),
icon: 'visHeatmap',
description: i18n.translate('kbnVislibVisTypes.heatmap.heatmapDescription', { defaultMessage: 'Shade cells within a matrix' }),
visualization: vislibVisController,
visConfig: {
defaults: {
type: 'heatmap',
Expand Down Expand Up @@ -62,6 +64,9 @@ export default function HeatmapVisType(Private) {
}]
},
},
events: {
brush: { disabled: false },
},
editorConfig: {
collections: {
legendPositions: [{
Expand Down
15 changes: 9 additions & 6 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { visFactory } from '../../../ui/public/vis/vis_factory';
import { i18n } from '@kbn/i18n';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggGroupNames } from 'ui/vis/editors/default';
Expand All @@ -32,20 +32,20 @@ import {
ThresholdLineStyles,
getConfigCollections,
} from './utils/collections';
import { getAreaOptionTabs, getCountLabel } from './utils/common_config';
import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { palettes } from '@elastic/eui/lib/services';
import { vislibVisController } from './controller';

export default function PointSeriesVisType(Private) {
const VisFactory = Private(VisFactoryProvider);
const countLabel = getCountLabel();
export default function PointSeriesVisType() {

return VisFactory.createVislibVisualization({
return visFactory.createBaseVisualization({
name: 'histogram',
title: i18n.translate('kbnVislibVisTypes.histogram.histogramTitle', { defaultMessage: 'Vertical Bar' }),
icon: 'visBarVertical',
description: i18n.translate('kbnVislibVisTypes.histogram.histogramDescription',
{ defaultMessage: 'Assign a continuous variable to each axis' }
),
visualization: vislibVisController,
visConfig: {
defaults: {
type: 'histogram',
Expand Down Expand Up @@ -125,6 +125,9 @@ export default function PointSeriesVisType(Private) {
}
},
},
events: {
brush: { disabled: false },
},
editorConfig: {
collections: getConfigCollections(),
optionTabs: getAreaOptionTabs(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { VisFactoryProvider } from 'ui/vis/vis_factory';
import { visFactory } from '../../../ui/public/vis/vis_factory';
import { i18n } from '@kbn/i18n';
import { Schemas } from 'ui/vis/editors/default/schemas';
import { AggGroupNames } from 'ui/vis/editors/default';
Expand All @@ -32,20 +32,20 @@ import {
ThresholdLineStyles,
getConfigCollections,
} from './utils/collections';
import { getAreaOptionTabs, getCountLabel } from './utils/common_config';
import { getAreaOptionTabs, countLabel } from './utils/common_config';
import { palettes } from '@elastic/eui/lib/services';
import { vislibVisController } from './controller';

export default function PointSeriesVisType(Private) {
const VisFactory = Private(VisFactoryProvider);
const countLabel = getCountLabel();
export default function PointSeriesVisType() {

return VisFactory.createVislibVisualization({
return visFactory.createBaseVisualization({
name: 'horizontal_bar',
title: i18n.translate('kbnVislibVisTypes.horizontalBar.horizontalBarTitle', { defaultMessage: 'Horizontal Bar' }),
icon: 'visBarHorizontal',
description: i18n.translate('kbnVislibVisTypes.horizontalBar.horizontalBarDescription',
{ defaultMessage: 'Assign a continuous variable to each axis' }
),
visualization: vislibVisController,
visConfig: {
defaults: {
type: 'histogram',
Expand Down Expand Up @@ -124,6 +124,9 @@ export default function PointSeriesVisType(Private) {
},
},
},
events: {
brush: { disabled: false },
},
editorConfig: {
collections: getConfigCollections(),
optionTabs: getAreaOptionTabs(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { VisTypesRegistryProvider } from 'ui/registry/vis_types';
import './controls/line_interpolation_option';

import histogramVisTypeProvider from './histogram';
import lineVisTypeProvider from './line';
Expand Down
Loading

0 comments on commit dfb7545

Please sign in to comment.