@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
187 lines (186 loc) • 9.76 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import React from 'react';
import { observer } from 'mobx-react';
import { computed } from 'mobx';
import { Popover } from 'antd';
import { SettingOutlined } from '@ant-design/icons';
import { size, clone } from 'lodash';
import errorBoundary from '../../../../../hocs/errorBoundary';
import BasicComponent from '../../../../Base/BasicComponent';
import { BucketItem, SetValueStyle, DeleteIcon, AddIcon } from '../../../../Base';
import { Form, Selector } from '../../../../Common';
import { formatString } from '../../../../../services';
import { defaultDataConfig } from '../../../../../constants/metric-panel-style';
import { OtherLocale } from '../../../../../constants/language/other/type';
import { BaseLocale } from '../../../../../constants/language/base/type';
import bind from '../../../../../utils/bind';
import * as styles from './style.mless';
var Item = Form.Item;
var DataElement = /** @class */ (function (_super) {
__extends(DataElement, _super);
function DataElement() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(DataElement.prototype, "metricValue", {
get: function () {
var _a = this.props.chartStyleService, currentMetrics = _a.currentMetrics, metricDataConfigs = _a.metricDataConfigs;
return currentMetrics.map(function (metric, index) {
var dataConfig = size(metricDataConfigs) > index
? metricDataConfigs[index]
: defaultDataConfig;
return { metric: metric, dataConfig: dataConfig };
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(DataElement.prototype, "fieldsSelectOptions", {
get: function () {
return this.props.dataset.fields.map(function (e) { return e.key; });
},
enumerable: false,
configurable: true
});
DataElement.prototype.handleMetricChange = function (value, index) {
var _a = this.props.chartStyleService, currentMetrics = _a.currentMetrics, setCurrentMetrics = _a.setCurrentMetrics;
var metrics = __spread(currentMetrics);
metrics[index] = value;
setCurrentMetrics(metrics);
};
DataElement.prototype.handleChangeDataConfig = function (key, value, index) {
var _a;
var _b = this.props.chartStyleService, metricDataConfigs = _b.metricDataConfigs, setMetricDataConfigs = _b.setMetricDataConfigs;
var configs = clone(metricDataConfigs);
configs.splice(index, -1, __assign(__assign({}, metricDataConfigs[index]), (_a = {}, _a[key] = value, _a)));
setMetricDataConfigs(configs);
};
DataElement.prototype.handleAddMetric = function () {
var _a = this.props.chartStyleService, currentMetrics = _a.currentMetrics, setCurrentMetrics = _a.setCurrentMetrics, metricDataConfigs = _a.metricDataConfigs, setMetricDataConfigs = _a.setMetricDataConfigs;
setCurrentMetrics(__spread(currentMetrics, ['']));
setMetricDataConfigs(__spread(metricDataConfigs, [defaultDataConfig]));
};
DataElement.prototype.handleDelete = function (index) {
var _a = this.props.chartStyleService, currentMetrics = _a.currentMetrics, setCurrentMetrics = _a.setCurrentMetrics, metricDataConfigs = _a.metricDataConfigs, setMetricDataConfigs = _a.setMetricDataConfigs;
currentMetrics.splice(index, 1);
metricDataConfigs.splice(index, 1);
setCurrentMetrics(__spread(currentMetrics));
setMetricDataConfigs(__spread(metricDataConfigs));
};
DataElement.prototype.render = function () {
var _this = this;
var _a = this.props.chartStyleService, currentBuckets = _a.currentBuckets, setCurrentBuckets = _a.setCurrentBuckets;
return (React.createElement(React.Fragment, null,
React.createElement(Item, { label: BaseLocale.metric },
this.metricValue.map(function (value, index) {
var metric = value.metric, dataConfig = value.dataConfig;
var unit = dataConfig.unit, precision = dataConfig.precision;
return (React.createElement("div", { className: styles.container, key: "" + metric + index },
React.createElement("div", { className: styles.selectorContainer },
React.createElement(Selector, { className: styles.selector, value: metric, onChange: function (value) {
return _this.handleMetricChange(value.toString(), index);
}, options: _this.fieldsSelectOptions, showSearch: true }),
React.createElement("div", { className: styles.settingView },
React.createElement(Popover, { getPopupContainer: _this.props.getPopupContainer, content: React.createElement(SetValueStyle, { unit: unit, setUnit: function (value) {
return _this.handleChangeDataConfig('unit', value, index);
}, precision: precision, setPrecision: function (value) {
return _this.handleChangeDataConfig('precision', value, index);
} }) },
React.createElement(SettingOutlined, { className: styles.icon })))),
React.createElement(DeleteIcon, { onClick: function () { return _this.handleDelete(index); } })));
}),
React.createElement(AddIcon, { onClick: this.handleAddMetric, title: formatString(OtherLocale.status.add_metric) })),
React.createElement(BucketItem, { isMultipleMode: true, bucketOptions: this.fieldsSelectOptions, currentBucket: currentBuckets, onChange: setCurrentBuckets })));
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], DataElement.prototype, "metricValue", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], DataElement.prototype, "fieldsSelectOptions", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Number]),
__metadata("design:returntype", void 0)
], DataElement.prototype, "handleMetricChange", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object, Number]),
__metadata("design:returntype", void 0)
], DataElement.prototype, "handleChangeDataConfig", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], DataElement.prototype, "handleAddMetric", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number]),
__metadata("design:returntype", void 0)
], DataElement.prototype, "handleDelete", null);
DataElement = __decorate([
observer
], DataElement);
return DataElement;
}(BasicComponent));
export { DataElement };
export default errorBoundary(DataElement);