@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
61 lines (60 loc) • 2.28 kB
JavaScript
import { isEqual, isUndefined, uniqWith } from 'lodash';
import moment from 'moment';
import { DrillDownType } from '../../constants/drill-down';
export var DEFAULT_SPAN = '5m';
/**
* 提供图表下钻相关的服务:
* 1. 封装根据点击元素生成约定Event的逻辑
* 2. 设置下钻相关的token,可作为模板变量使用
*/
var ChartDrillDownService = /** @class */ (function () {
function ChartDrillDownService(type) {
this.type = type;
}
// 除searchAuto外暂用不到
ChartDrillDownService.prototype.toCommonEvent = function () {
return undefined;
};
ChartDrillDownService.prototype.toEvent = function (params) {
switch (this.type) {
case DrillDownType.ToSearchAuto:
return this.toSearchAutoEvent(params);
default:
return this.toCommonEvent();
}
};
ChartDrillDownService.prototype.generateBucket = function (fieldname, value, fields) {
var field = fields.find(function (item) { return item.key === fieldname; });
var type = (field && field.fieldType) || '';
return {
field: fieldname,
type: type,
span: type === 'Time' ? DEFAULT_SPAN : '',
value: type === 'Time' && value && moment(value).isValid()
? moment(value).valueOf()
: value
};
};
ChartDrillDownService.prototype.generateMetric = function (fieldname, value) {
return {
field: fieldname,
value: value
};
};
ChartDrillDownService.prototype.generateValidResults = function (res) {
var _this = this;
return {
buckets: uniqWith((res.buckets || []).filter(function (bucket) {
return _this.isFieldValid(bucket.field, bucket.value);
}), isEqual),
metrics: uniqWith((res.metrics || []).filter(function (metric) {
return _this.isFieldValid(metric.field, metric.value);
}), isEqual)
};
};
ChartDrillDownService.prototype.isFieldValid = function (fieldname, value) {
return !!fieldname && !isUndefined(value);
};
return ChartDrillDownService;
}());
export default ChartDrillDownService;