remove angular from Vis (#50402)

This commit is contained in:
Peter Pisljar 2019-11-14 07:34:20 -05:00 committed by GitHub
parent b5a0d4b03d
commit 4f888196b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 273 additions and 323 deletions

View file

@ -21,7 +21,7 @@ import chrome from 'ui/chrome';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
// @ts-ignore
import { VisProvider } from '../../../../ui/public/visualize/loader/vis';
import { Vis } from '../../../../ui/public/visualize/loader/vis';
import { Visualization } from '../../../../ui/public/visualize/components';
export const visualization = () => ({
@ -33,8 +33,6 @@ export const visualization = () => ({
const visType = config.visType || visConfig.type;
const $injector = await chrome.dangerouslyGetActiveInjector();
const $rootScope = $injector.get('$rootScope') as any;
const Private = $injector.get('Private') as any;
const Vis = Private(VisProvider);
if (handlers.vis) {
// special case in visualize, we need to render first (without executing the expression), for maps to work

View file

@ -57,7 +57,7 @@ import {
subscribeWithScope,
tabifyAggResponse,
vislibSeriesResponseHandlerProvider,
VisProvider,
Vis,
SavedObjectSaveModal,
} from '../kibana_services';
@ -190,7 +190,6 @@ function discoverController(
localStorage,
uiCapabilities
) {
const Vis = Private(VisProvider);
const responseHandler = vislibSeriesResponseHandlerProvider().handler;
const getUnhashableStates = Private(getUnhashableStatesProvider);
const shareContextMenuExtensions = Private(ShareContextMenuExtensionsRegistryProvider);

View file

@ -114,7 +114,7 @@ export { tabifyAggResponse } from 'ui/agg_response/tabify';
export { vislibSeriesResponseHandlerProvider } from 'ui/vis/response_handlers/vislib';
// EXPORT types
export { VisProvider } from 'ui/vis';
export { Vis } from 'ui/vis';
export { StaticIndexPattern, IndexPatterns, IndexPattern, FieldType } from 'ui/index_patterns';
export { SearchSource } from 'ui/courier';
export { ElasticSearchHit } from 'ui/registry/doc_views_types';

View file

@ -25,7 +25,7 @@
* NOTE: It's a type of SavedObject, but specific to visualizations.
*/
import { VisProvider } from 'ui/vis';
import { Vis } from 'ui/vis';
import { uiModules } from 'ui/modules';
import { updateOldState } from 'ui/vis/vis_update_state';
import { VisualizeConstants } from '../visualize_constants';
@ -39,7 +39,6 @@ import {
uiModules
.get('app/visualize')
.factory('SavedVis', function (Promise, savedSearches, Private) {
const Vis = Private(VisProvider);
const SavedObject = Private(SavedObjectProvider);
createLegacyClass(SavedVis).inherits(SavedObject);
function SavedVis(opts) {

View file

@ -22,7 +22,7 @@ import ngMock from 'ng_mock';
import _ from 'lodash';
import ChoroplethLayer from '../choropleth_layer';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import * as visModule from 'ui/vis';
import { Vis } from 'ui/vis';
import { ImageComparator } from 'test_utils/image_comparator';
import worldJson from './world.json';
import EMS_CATALOGUE from '../../../../ui/public/vis/__tests__/map/ems_mocks/sample_manifest.json';
@ -50,7 +50,6 @@ const PIXEL_DIFF = 96;
describe('RegionMapsVisualizationTests', function () {
let domNode;
let RegionMapsVisualization;
let Vis;
let indexPattern;
let vis;
let dependencies;
@ -113,7 +112,6 @@ describe('RegionMapsVisualizationTests', function () {
visualizationsSetup.types.registerVisualization(() => createRegionMapTypeDefinition(dependencies));
}
Vis = Private(visModule.VisProvider);
RegionMapsVisualization = createRegionMapVisualization(dependencies);
indexPattern = Private(LogstashIndexPatternStubProvider);

View file

@ -20,7 +20,7 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import * as visModule from 'ui/vis';
import { Vis } from 'ui/vis';
import { ImageComparator } from 'test_utils/image_comparator';
import dummyESResponse from './dummy_es_response.json';
import initial from './initial.png';
@ -65,7 +65,6 @@ let visRegComplete = false;
describe('CoordinateMapsVisualizationTest', function () {
let domNode;
let CoordinateMapsVisualization;
let Vis;
let indexPattern;
let vis;
let dependencies;
@ -91,7 +90,6 @@ describe('CoordinateMapsVisualizationTest', function () {
}
Vis = Private(visModule.VisProvider);
CoordinateMapsVisualization = createTileMapVisualization(dependencies);
indexPattern = Private(LogstashIndexPatternStubProvider);

View file

@ -21,7 +21,7 @@ import $ from 'jquery';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { VisProvider } from 'ui/vis';
import { Vis } from 'ui/vis';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import { createMetricVisTypeDefinition } from '../metric_vis_type';
@ -34,7 +34,6 @@ describe('metric_vis - createMetricVisTypeDefinition', () => {
beforeEach(
ngMock.inject(Private => {
setup = () => {
const Vis = Private(VisProvider);
const metricVisType = createMetricVisTypeDefinition();
const indexPattern = Private(LogstashIndexPatternStubProvider);

View file

@ -21,7 +21,7 @@ import $ from 'jquery';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
import { VisProvider } from 'ui/vis';
import { Vis } from 'ui/vis';
import { VisFactoryProvider } from 'ui/vis/vis_factory';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { AppStateProvider } from 'ui/state_management/app_state';
@ -36,7 +36,6 @@ describe('Table Vis - Controller', async function () {
let Private;
let $scope;
let $el;
let Vis;
let fixtures;
let AppState;
let tableAggResponse;
@ -63,7 +62,6 @@ describe('Table Vis - Controller', async function () {
$compile = $injector.get('$compile');
fixtures = require('fixtures/fake_hierarchical_data');
AppState = Private(AppStateProvider);
Vis = Private(VisProvider);
tableAggResponse = legacyResponseHandlerProvider().handler;
})
);

View file

@ -25,7 +25,7 @@ import fixtures from 'fixtures/fake_hierarchical_data';
import sinon from 'sinon';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { VisProvider } from 'ui/vis';
import { Vis } from 'ui/vis';
import { tabifyAggResponse } from 'ui/agg_response/tabify';
import { round } from 'lodash';
@ -36,7 +36,6 @@ import { setup as visualizationsSetup } from '../../../../visualizations/public/
describe('Table Vis - AggTable Directive', function () {
let $rootScope;
let $compile;
let Vis;
let indexPattern;
let settings;
let tableAggResponse;
@ -113,7 +112,6 @@ describe('Table Vis - AggTable Directive', function () {
ngMock.inject(function ($injector, Private, config) {
tableAggResponse = legacyResponseHandlerProvider().handler;
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
Vis = Private(VisProvider);
settings = config;
$rootScope = $injector.get('$rootScope');

View file

@ -23,13 +23,12 @@ import expect from '@kbn/expect';
import fixtures from 'fixtures/fake_hierarchical_data';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { VisProvider } from 'ui/vis';
import { Vis } from 'ui/vis';
import { tabifyAggResponse } from 'ui/agg_response/tabify';
describe('Table Vis - AggTableGroup Directive', function () {
let $rootScope;
let $compile;
let Vis;
let indexPattern;
let tableAggResponse;
const tabifiedData = {};
@ -69,7 +68,6 @@ describe('Table Vis - AggTableGroup Directive', function () {
tableAggResponse = legacyResponseHandlerProvider().handler;
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
Vis = Private(VisProvider);
$rootScope = $injector.get('$rootScope');
$compile = $injector.get('$compile');

View file

@ -20,7 +20,7 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import * as visModule from 'ui/vis';
import { Vis } from 'ui/vis';
import { ImageComparator } from 'test_utils/image_comparator';
import { TagCloudVisualization } from '../tag_cloud_visualization';
import basicdrawPng from './basicdraw.png';
@ -33,7 +33,6 @@ const PIXEL_DIFF = 64;
describe('TagCloudVisualizationTest', function () {
let domNode;
let Vis;
let indexPattern;
let vis;
let imageComparator;
@ -57,7 +56,6 @@ describe('TagCloudVisualizationTest', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject((Private) => {
Vis = Private(visModule.VisProvider);
indexPattern = Private(LogstashIndexPatternStubProvider);
}));

View file

@ -44,8 +44,7 @@ const APP_NAME = 'VisEditor';
export class VisEditor extends Component {
constructor(props) {
super(props);
const { vis } = props;
this.appState = vis.API.getAppState();
this.appState = props.appState;
this.localStorage = new Storage(window.localStorage);
this.state = {
model: props.visParams,
@ -183,7 +182,6 @@ export class VisEditor extends Component {
dirty={this.state.dirty}
autoApply={this.state.autoApply}
model={model}
appState={this.appState}
savedObj={this.props.savedObj}
timeRange={this.props.timeRange}
uiState={this.uiState}
@ -239,4 +237,5 @@ VisEditor.propTypes = {
isEditorMode: PropTypes.bool,
savedObj: PropTypes.object,
timeRange: PropTypes.object,
appState: PropTypes.object,
};

View file

@ -23,7 +23,7 @@ import ngMock from 'ng_mock';
import $ from 'jquery';
import { createVegaVisualization } from '../vega_visualization';
import LogstashIndexPatternStubProvider from 'fixtures/stubbed_logstash_index_pattern';
import * as visModule from 'ui/vis';
import { Vis } from 'ui/vis';
import { ImageComparator } from 'test_utils/image_comparator';
import vegaliteGraph from '!!raw-loader!./vegalite_graph.hjson';
@ -50,7 +50,6 @@ const PIXEL_DIFF = 30;
describe('VegaVisualizations', () => {
let domNode;
let VegaVisualization;
let Vis;
let indexPattern;
let vis;
let imageComparator;
@ -73,7 +72,6 @@ describe('VegaVisualizations', () => {
);
}
Vis = Private(visModule.VisProvider);
VegaVisualization = createVegaVisualization(vegaVisualizationDependencies);
indexPattern = Private(LogstashIndexPatternStubProvider);

View file

@ -39,7 +39,6 @@ export { DefaultEditorSize } from 'ui/vis/editor_size';
import * as types from 'ui/vis/vis';
export type Vis = types.Vis;
export type VisParams = types.VisParams;
export type VisProvider = types.VisProvider;
export type VisState = types.VisState;
export { VisualizationController } from 'ui/vis/vis_types/vis_type';
export { Status } from 'ui/vis/update_status';

View file

@ -20,15 +20,13 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { tabifyGetColumns } from '../_get_columns';
import { VisProvider } from '../../../vis';
import { Vis } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
describe('get columns', function () {
let Vis;
let indexPattern;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -22,16 +22,14 @@ import fixtures from 'fixtures/fake_hierarchical_data';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { tabifyAggResponse } from '../tabify';
import { VisProvider } from '../../../vis';
import { Vis } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
describe('tabifyAggResponse Integration', function () {
let Vis;
let indexPattern;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -20,11 +20,10 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { TabbedAggResponseWriter } from '../_response_writer';
import { VisProvider } from '../../../vis';
import { Vis } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
describe('TabbedAggResponseWriter class', function () {
let Vis;
let Private;
let indexPattern;
@ -32,7 +31,6 @@ describe('TabbedAggResponseWriter class', function () {
beforeEach(ngMock.inject(function ($injector) {
Private = $injector.get('Private');
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -20,7 +20,7 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { buildOtherBucketAgg, mergeOtherBucketAggResponse, updateMissingBucket } from '../../buckets/_terms_other_bucket_helper';
import { VisProvider } from '../../../vis';
import { Vis } from '../../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
const visConfigSingleTerm = {
@ -158,7 +158,6 @@ describe('Terms Agg Other bucket helper', () => {
function init(aggConfig) {
ngMock.module('kibana');
ngMock.inject((Private) => {
const Vis = Private(VisProvider);
const indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
vis = new Vis(indexPattern, aggConfig);

View file

@ -20,7 +20,7 @@
import sinon from 'sinon';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { VisProvider } from '..';
import { Vis } from '..';
import { AggType } from '../../agg_types/agg_type';
import { AggConfig } from '../../agg_types/agg_config';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
@ -28,12 +28,10 @@ import { fieldFormats } from '../../registry/field_formats';
describe('AggConfig', function () {
let Vis;
let indexPattern;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -22,7 +22,7 @@ import sinon from 'sinon';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { AggConfig } from '../../agg_types/agg_config';
import { VisProvider } from '..';
import { Vis } from '..';
import { AggConfigs } from '../../agg_types/agg_configs';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Schemas } from '../editors/default/schemas';
@ -30,13 +30,11 @@ import { AggGroupNames } from '../editors/default/agg_groups';
describe('AggConfigs', function () {
let Vis;
let indexPattern;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
// load main deps
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -20,13 +20,12 @@
import _ from 'lodash';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import { VisProvider } from '..';
import { Vis } from '..';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { start as visualizations } from '../../../../core_plugins/visualizations/public/np_ready/public/legacy';
describe('Vis Class', function () {
let indexPattern;
let Vis;
let visTypes;
let vis;
@ -43,7 +42,6 @@ describe('Vis Class', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
visTypes = visualizations.types;
}));

View file

@ -18,5 +18,5 @@
*/
export { AggConfig } from '../agg_types/agg_config';
export { Vis, VisProvider, VisParams, VisState } from './vis';
export { Vis, VisParams, VisState } from './vis';
export { VisualizationController, VisType } from './vis_types/vis_type';

View file

@ -17,4 +17,4 @@
* under the License.
*/
export { VisProvider } from './vis';
export { Vis } from './vis';

View file

@ -30,8 +30,6 @@ export interface Vis {
[key: string]: any;
}
export type VisProvider = (...dependencies: any[]) => Vis;
export interface VisParams {
[key: string]: any;
}

View file

@ -38,181 +38,178 @@ import { start as visualizations } from '../../../core_plugins/visualizations/pu
import '../directives/bind';
export function VisProvider(Private, getAppState) {
const visTypes = visualizations.types;
const visTypes = visualizations.types;
class Vis extends EventEmitter {
constructor(indexPattern, visState) {
super();
visState = visState || {};
class Vis extends EventEmitter {
constructor(indexPattern, visState) {
super();
visState = visState || {};
if (_.isString(visState)) {
visState = {
type: visState
};
}
this.indexPattern = indexPattern;
this._setUiState(new PersistedState());
this.setCurrentState(visState);
this.setState(this.getCurrentState(), false);
// Session state is for storing information that is transitory, and will not be saved with the visualization.
// For instance, map bounds, which depends on the view port, browser window size, etc.
this.sessionState = {};
this.API = {
SearchSource: SearchSource,
events: {
filter: data => this.eventsSubject.next({ name: 'filterBucket', data }),
brush: data => this.eventsSubject.next({ name: 'brush', data }),
},
getAppState,
if (_.isString(visState)) {
visState = {
type: visState
};
}
this.indexPattern = indexPattern;
this._setUiState(new PersistedState());
this.setCurrentState(visState);
this.setState(this.getCurrentState(), false);
setCurrentState(state) {
this.title = state.title || '';
const type = state.type || this.type;
if (_.isString(type)) {
this.type = visTypes.get(type);
if (!this.type) {
throw new Error(`Invalid type "${type}"`);
}
} else {
this.type = type;
}
this.params = _.defaults({},
_.cloneDeep(state.params || {}),
_.cloneDeep(this.type.visConfig.defaults || {})
);
updateVisualizationConfig(state.params, this.params);
if (state.aggs || !this.aggs) {
this.aggs = new AggConfigs(this.indexPattern, state.aggs ? state.aggs.aggs || state.aggs : [], this.type.schemas.all);
// Session state is for storing information that is transitory, and will not be saved with the visualization.
// For instance, map bounds, which depends on the view port, browser window size, etc.
this.sessionState = {};
this.API = {
SearchSource: SearchSource,
events: {
filter: data => this.eventsSubject.next({ name: 'filterBucket', data }),
brush: data => this.eventsSubject.next({ name: 'brush', data }),
},
};
}
setCurrentState(state) {
this.title = state.title || '';
const type = state.type || this.type;
if (_.isString(type)) {
this.type = visTypes.get(type);
if (!this.type) {
throw new Error(`Invalid type "${type}"`);
}
} else {
this.type = type;
}
setState(state, updateCurrentState = true) {
this._state = _.cloneDeep(state);
if (updateCurrentState) {
this.setCurrentState(this._state);
}
}
this.params = _.defaults({},
_.cloneDeep(state.params || {}),
_.cloneDeep(this.type.visConfig.defaults || {})
);
updateState() {
this.setState(this.getCurrentState(true));
this.emit('update');
}
updateVisualizationConfig(state.params, this.params);
forceReload() {
this.emit('reload');
}
getCurrentState(includeDisabled) {
return {
title: this.title,
type: this.type.name,
params: _.cloneDeep(this.params),
aggs: this.aggs.aggs
.map(agg => agg.toJSON())
.filter(agg => includeDisabled || agg.enabled)
.filter(Boolean)
};
}
getSerializableState(state) {
return {
title: state.title,
type: state.type,
params: _.cloneDeep(state.params),
aggs: state.aggs.aggs
.map(agg => agg.toJSON())
.filter(agg => agg.enabled)
.filter(Boolean)
};
}
copyCurrentState(includeDisabled = false) {
const state = this.getCurrentState(includeDisabled);
state.aggs = new AggConfigs(this.indexPattern, state.aggs.aggs || state.aggs, this.type.schemas.all);
return state;
}
getStateInternal(includeDisabled) {
return {
title: this._state.title,
type: this._state.type,
params: this._state.params,
aggs: this._state.aggs
.filter(agg => includeDisabled || agg.enabled)
};
}
getEnabledState() {
return this.getStateInternal(false);
}
getAggConfig() {
return this.aggs.clone({ enabledOnly: true });
}
getState() {
return this.getStateInternal(true);
}
isHierarchical() {
if (_.isFunction(this.type.hierarchicalData)) {
return !!this.type.hierarchicalData(this);
} else {
return !!this.type.hierarchicalData;
}
}
hasSchemaAgg(schemaName, aggTypeName) {
const aggs = this.aggs.bySchemaName(schemaName) || [];
return aggs.some(function (agg) {
if (!agg.type || !agg.type.name) return false;
return agg.type.name === aggTypeName;
});
}
hasUiState() {
return !!this.__uiState;
}
/***
* this should not be used outside of visualize
* @param uiState
* @private
*/
_setUiState(uiState) {
if (uiState instanceof PersistedState) {
this.__uiState = uiState;
}
}
getUiState() {
return this.__uiState;
}
/**
* Currently this is only used to extract map-specific information
* (e.g. mapZoom, mapCenter).
*/
uiStateVal(key, val) {
if (this.hasUiState()) {
if (_.isUndefined(val)) {
return this.__uiState.get(key);
}
return this.__uiState.set(key, val);
}
return val;
if (state.aggs || !this.aggs) {
this.aggs = new AggConfigs(this.indexPattern, state.aggs ? state.aggs.aggs || state.aggs : [], this.type.schemas.all);
}
}
Vis.prototype.type = 'histogram';
setState(state, updateCurrentState = true) {
this._state = _.cloneDeep(state);
if (updateCurrentState) {
this.setCurrentState(this._state);
}
}
return Vis;
updateState() {
this.setState(this.getCurrentState(true));
this.emit('update');
}
forceReload() {
this.emit('reload');
}
getCurrentState(includeDisabled) {
return {
title: this.title,
type: this.type.name,
params: _.cloneDeep(this.params),
aggs: this.aggs.aggs
.map(agg => agg.toJSON())
.filter(agg => includeDisabled || agg.enabled)
.filter(Boolean)
};
}
getSerializableState(state) {
return {
title: state.title,
type: state.type,
params: _.cloneDeep(state.params),
aggs: state.aggs.aggs
.map(agg => agg.toJSON())
.filter(agg => agg.enabled)
.filter(Boolean)
};
}
copyCurrentState(includeDisabled = false) {
const state = this.getCurrentState(includeDisabled);
state.aggs = new AggConfigs(this.indexPattern, state.aggs.aggs || state.aggs, this.type.schemas.all);
return state;
}
getStateInternal(includeDisabled) {
return {
title: this._state.title,
type: this._state.type,
params: this._state.params,
aggs: this._state.aggs
.filter(agg => includeDisabled || agg.enabled)
};
}
getEnabledState() {
return this.getStateInternal(false);
}
getAggConfig() {
return this.aggs.clone({ enabledOnly: true });
}
getState() {
return this.getStateInternal(true);
}
isHierarchical() {
if (_.isFunction(this.type.hierarchicalData)) {
return !!this.type.hierarchicalData(this);
} else {
return !!this.type.hierarchicalData;
}
}
hasSchemaAgg(schemaName, aggTypeName) {
const aggs = this.aggs.bySchemaName(schemaName) || [];
return aggs.some(function (agg) {
if (!agg.type || !agg.type.name) return false;
return agg.type.name === aggTypeName;
});
}
hasUiState() {
return !!this.__uiState;
}
/***
* this should not be used outside of visualize
* @param uiState
* @private
*/
_setUiState(uiState) {
if (uiState instanceof PersistedState) {
this.__uiState = uiState;
}
}
getUiState() {
return this.__uiState;
}
/**
* Currently this is only used to extract map-specific information
* (e.g. mapZoom, mapCenter).
*/
uiStateVal(key, val) {
if (this.hasUiState()) {
if (_.isUndefined(val)) {
return this.__uiState.get(key);
}
return this.__uiState.set(key, val);
}
return val;
}
}
Vis.prototype.type = 'histogram';
export { Vis };

View file

@ -21,7 +21,7 @@ import $ from 'jquery';
import _ from 'lodash';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { VisProvider } from '../../vis';
import { Vis } from '../../vis';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
describe('visualize_legend directive', function () {
@ -29,7 +29,6 @@ describe('visualize_legend directive', function () {
let $compile;
let $timeout;
let $el;
let Vis;
let indexPattern;
let fixtures;
@ -39,7 +38,6 @@ describe('visualize_legend directive', function () {
$compile = $injector.get('$compile');
$timeout = $injector.get('$timeout');
fixtures = require('fixtures/fake_hierarchical_data');
Vis = Private(VisProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));

View file

@ -24,7 +24,7 @@ import _ from 'lodash';
import fixtures from 'fixtures/fake_hierarchical_data';
import $ from 'jquery';
import FixturesVislibVisFixtureProvider from 'fixtures/vislib/_vis_fixture';
import { VisProvider } from '../../../vis';
import { Vis } from '../../../vis';
import '../../../persisted_state';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { vislibSlicesResponseHandlerProvider } from '../../../vis/response_handlers/vislib';
@ -113,7 +113,6 @@ describe('No global chart settings', function () {
addTooltip: true
};
let chart1;
let Vis;
let persistedState;
let indexPattern;
let responseHandler;
@ -123,7 +122,6 @@ describe('No global chart settings', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private, $injector) {
chart1 = Private(FixturesVislibVisFixtureProvider)(visLibParams1);
Vis = Private(VisProvider);
persistedState = new ($injector.get('PersistedState'))();
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
responseHandler = vislibSlicesResponseHandlerProvider().handler;
@ -203,7 +201,6 @@ describe('Vislib PieChart Class Test Suite', function () {
addTooltip: true
};
let vis;
let Vis;
let persistedState;
let indexPattern;
let data;
@ -213,7 +210,6 @@ describe('Vislib PieChart Class Test Suite', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private, $injector) {
vis = Private(FixturesVislibVisFixtureProvider)(visLibParams);
Vis = Private(VisProvider);
persistedState = new ($injector.get('PersistedState'))();
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
responseHandler = vislibSlicesResponseHandlerProvider().handler;

View file

@ -33,114 +33,109 @@ import { PersistedState } from '../../persisted_state';
import { start as visualizations } from '../../../../core_plugins/visualizations/public/np_ready/public/legacy';
export function VisProvider(getAppState) {
const visTypes = visualizations.types;
const visTypes = visualizations.types;
class Vis extends EventEmitter {
constructor(visState = { type: 'histogram' }) {
super();
export class Vis extends EventEmitter {
constructor(visState = { type: 'histogram' }) {
super();
this._setUiState(new PersistedState());
this.setState(visState);
this._setUiState(new PersistedState());
this.setState(visState);
// Session state is for storing information that is transitory, and will not be saved with the visualization.
// For instance, map bounds, which depends on the view port, browser window size, etc.
this.sessionState = {};
// Session state is for storing information that is transitory, and will not be saved with the visualization.
// For instance, map bounds, which depends on the view port, browser window size, etc.
this.sessionState = {};
this.API = {
events: {
filter: data => {
if (!this.eventsSubject) return;
this.eventsSubject.next({ name: 'filterBucket', data });
},
brush: data => {
if (!this.eventsSubject) return;
this.eventsSubject.next({ name: 'brush', data });
},
this.API = {
events: {
filter: data => {
if (!this.eventsSubject) return;
this.eventsSubject.next({ name: 'filterBucket', data });
},
getAppState,
};
}
brush: data => {
if (!this.eventsSubject) return;
this.eventsSubject.next({ name: 'brush', data });
},
},
};
}
setState(state) {
this.title = state.title || '';
const type = state.type || this.type;
if (_.isString(type)) {
this.type = visTypes.get(type);
if (!this.type) {
throw new Error(`Invalid type "${type}"`);
}
} else {
this.type = type;
setState(state) {
this.title = state.title || '';
const type = state.type || this.type;
if (_.isString(type)) {
this.type = visTypes.get(type);
if (!this.type) {
throw new Error(`Invalid type "${type}"`);
}
this.params = _.defaultsDeep({},
_.cloneDeep(state.params || {}),
_.cloneDeep(this.type.visConfig.defaults || {})
);
} else {
this.type = type;
}
setCurrentState(state) {
this.setState(state);
}
this.params = _.defaultsDeep({},
_.cloneDeep(state.params || {}),
_.cloneDeep(this.type.visConfig.defaults || {})
);
}
getState() {
return {
title: this.title,
type: this.type.name,
params: _.cloneDeep(this.params),
};
}
setCurrentState(state) {
this.setState(state);
}
updateState() {
this.emit('update');
}
getState() {
return {
title: this.title,
type: this.type.name,
params: _.cloneDeep(this.params),
};
}
forceReload() {
this.emit('reload');
}
updateState() {
this.emit('update');
}
isHierarchical() {
if (_.isFunction(this.type.hierarchicalData)) {
return !!this.type.hierarchicalData(this);
} else {
return !!this.type.hierarchicalData;
}
}
forceReload() {
this.emit('reload');
}
hasUiState() {
return !!this.__uiState;
}
/***
* this should not be used outside of visualize
* @param uiState
* @private
*/
_setUiState(uiState) {
if (uiState instanceof PersistedState) {
this.__uiState = uiState;
}
}
getUiState() {
return this.__uiState;
}
/**
* Currently this is only used to extract map-specific information
* (e.g. mapZoom, mapCenter).
*/
uiStateVal(key, val) {
if (this.hasUiState()) {
if (_.isUndefined(val)) {
return this.__uiState.get(key);
}
return this.__uiState.set(key, val);
}
return val;
isHierarchical() {
if (_.isFunction(this.type.hierarchicalData)) {
return !!this.type.hierarchicalData(this);
} else {
return !!this.type.hierarchicalData;
}
}
return Vis;
hasUiState() {
return !!this.__uiState;
}
/***
* this should not be used outside of visualize
* @param uiState
* @private
*/
_setUiState(uiState) {
if (uiState instanceof PersistedState) {
this.__uiState = uiState;
}
}
getUiState() {
return this.__uiState;
}
/**
* Currently this is only used to extract map-specific information
* (e.g. mapZoom, mapCenter).
*/
uiStateVal(key, val) {
if (this.hasUiState()) {
if (_.isUndefined(val)) {
return this.__uiState.get(key);
}
return this.__uiState.set(key, val);
}
return val;
}
}