kibana-riya
Version:
Kibana is an open source (Apache Licensed), browser based analytics and search dashboard for Elasticsearch. Kibana is a snap to setup and start using. Kibana strives to be easy to get started with, while also being flexible and powerful, just like Elastic
48 lines (39 loc) • 1.28 kB
JavaScript
/**
* Provides vislib configuration, throws error if invalid property is accessed without providing defaults
*/
import _ from 'lodash';
import VisTypesProvider from './types';
import VislibLibDataProvider from './data';
export default function VisConfigFactory(Private) {
const Data = Private(VislibLibDataProvider);
const visTypes = Private(VisTypesProvider);
const DEFAULT_VIS_CONFIG = {
style: {
margin : { top: 10, right: 3, bottom: 5, left: 3 }
},
alerts: [],
categoryAxes: [],
valueAxes: []
};
class VisConfig {
constructor(visConfigArgs, data, uiState, el) {
this.data = new Data(data, uiState);
const visType = visTypes[visConfigArgs.type];
const typeDefaults = visType(visConfigArgs, this.data);
this._values = _.defaultsDeep({}, typeDefaults, DEFAULT_VIS_CONFIG);
this._values.el = el;
}
get(property, defaults) {
if (_.has(this._values, property) || typeof defaults !== 'undefined') {
return _.get(this._values, property, defaults);
} else {
throw new Error(`Accessing invalid config property: ${property}`);
return defaults;
}
}
set(property, value) {
return _.set(this._values, property, value);
}
}
return VisConfig;
}