@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
144 lines (143 loc) • 9.23 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);
};
import React from 'react';
import { computed } from 'mobx';
import { observer } from 'mobx-react';
import { get, noop, isNumber } from 'lodash';
import errorBoundary from '../../../../hocs/errorBoundary';
import BasicComponent from '../../../Base/BasicComponent';
import { NumberItem, SolidRadioItem } from '../../../Base';
import { SingleLocale } from '../../../../constants/language/single/type';
import { ChartType } from '../../../../constants';
import { BaseLocale } from '../../../../constants/language/base/type';
import bind from '../../../../utils/bind';
import { formatString } from '../../../../services';
import { formItemLayout } from '../../constants';
import TitleElement from '../TitleElement';
import { guage_axix_options, valueModeOptions } from '../constants';
import SingleEmptyValue from './SingleEmptyValue';
var SingleCircleStyleElement = /** @class */ (function (_super) {
__extends(SingleCircleStyleElement, _super);
function SingleCircleStyleElement() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(SingleCircleStyleElement.prototype, "formItemCol", {
get: function () {
var chartType = this.props.chartStyleService.chartType;
return chartType === ChartType.SingleGauge ? formItemLayout : undefined;
},
enumerable: false,
configurable: true
});
SingleCircleStyleElement.prototype.valueValidator = function (type, value) {
var _a = this.props.chartStyleService, gaugeMin = _a.gaugeMin, gaugeMax = _a.gaugeMax;
if (type === "min" /* Min */) {
return value > gaugeMax
? Promise.reject(BaseLocale.split.validate_splitter_4)
: Promise.resolve();
}
return value < gaugeMin
? Promise.reject(BaseLocale.split.validate_splitter_2)
: Promise.resolve();
};
SingleCircleStyleElement.prototype.numberValidator = function (value) {
if (!isNumber(value)) {
return Promise.reject(BaseLocale.split.validate_splitter_1);
}
return Promise.resolve();
};
SingleCircleStyleElement.prototype.gaugeMaxValidator = function (value) {
return Promise.all([
this.numberValidator(value),
this.valueValidator("max" /* Max */, value)
]).then(noop);
};
SingleCircleStyleElement.prototype.gaugeMinValidator = function (value) {
return Promise.all([
this.numberValidator(value),
this.valueValidator("min" /* Min */, value)
]).then(noop);
};
SingleCircleStyleElement.prototype.render = function () {
var _a = this.props, chartStyleService = _a.chartStyleService, _b = _a.themeOption.gauge, singleGauge = _b.singleGauge, lineStyle = _b.axisLine.lineStyle;
var chartType = chartStyleService.chartType, gaugeMin = chartStyleService.gaugeMin, setGaugeMin = chartStyleService.setGaugeMin, gaugeMax = chartStyleService.gaugeMax, setGaugeMax = chartStyleService.setGaugeMax, radiusRatio = chartStyleService.radiusRatio, setRadiusRatio = chartStyleService.setRadiusRatio, circularWidth = chartStyleService.circularWidth, setCircularWidth = chartStyleService.setCircularWidth, splitNumber = chartStyleService.splitNumber, setSplitNumber = chartStyleService.setSplitNumber, showAxisLabel = chartStyleService.showAxisLabel, setShowAxisLabel = chartStyleService.setShowAxisLabel, valueMode = chartStyleService.valueMode, setValueMode = chartStyleService.setValueMode, gaugeEmptyValueMode = chartStyleService.gaugeEmptyValueMode, setGaugeEmptyValueMode = chartStyleService.setGaugeEmptyValueMode;
return (React.createElement(React.Fragment, null,
chartType === ChartType.SingleGauge && (React.createElement(NumberItem, __assign({ label: SingleLocale.gaugeMin, value: gaugeMin === -Infinity ? '' : gaugeMin, onChange: setGaugeMin, onValidate: this.gaugeMinValidator }, this.formItemCol))),
chartType === ChartType.SingleGauge && (React.createElement(NumberItem, __assign({ label: SingleLocale.gaugeMax, value: gaugeMax === Infinity ? '' : gaugeMax, onChange: setGaugeMax, onValidate: this.gaugeMaxValidator }, this.formItemCol))),
chartType === ChartType.SingleGauge && (React.createElement(React.Fragment, null,
React.createElement(SolidRadioItem, __assign({ label: SingleLocale.axis_label, value: showAxisLabel, onChange: setShowAxisLabel, options: guage_axix_options }, this.formItemCol)),
showAxisLabel && (React.createElement(NumberItem, __assign({ label: SingleLocale.split_number.label, value: splitNumber, onChange: setSplitNumber, min: 0, max: 20, explain: formatString(SingleLocale.split_number.explain) }, this.formItemCol))))),
chartType === ChartType.SinglePercent && (React.createElement(NumberItem, { label: SingleLocale.targetValue, value: gaugeMax === Infinity ? '' : gaugeMax, onChange: setGaugeMax, min: gaugeMin })),
React.createElement(NumberItem, __assign({ label: SingleLocale.radius_ratio, value: radiusRatio || get(singleGauge, 'radiusRatio'), onChange: setRadiusRatio }, this.formItemCol)),
React.createElement(NumberItem, __assign({ label: SingleLocale.size, value: circularWidth || lineStyle.width, onChange: setCircularWidth, min: 1 }, this.formItemCol)),
chartType === ChartType.SinglePercent && (React.createElement(SolidRadioItem, { label: SingleLocale.value_show, value: valueMode, onChange: setValueMode, options: valueModeOptions })),
React.createElement(TitleElement, { themeOption: this.props.themeOption, chartStyleService: chartStyleService, getPopupContainer: this.props.getPopupContainer, formItemCol: this.formItemCol }),
chartType === ChartType.SingleGauge ? (React.createElement(SingleEmptyValue, __assign({ value: gaugeEmptyValueMode, onChange: setGaugeEmptyValueMode }, this.formItemCol))) : (React.createElement(SingleEmptyValue, { value: gaugeEmptyValueMode, onChange: setGaugeEmptyValueMode }))));
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SingleCircleStyleElement.prototype, "formItemCol", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Number]),
__metadata("design:returntype", void 0)
], SingleCircleStyleElement.prototype, "valueValidator", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleCircleStyleElement.prototype, "numberValidator", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleCircleStyleElement.prototype, "gaugeMaxValidator", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SingleCircleStyleElement.prototype, "gaugeMinValidator", null);
SingleCircleStyleElement = __decorate([
observer
], SingleCircleStyleElement);
return SingleCircleStyleElement;
}(BasicComponent));
export { SingleCircleStyleElement };
export default errorBoundary(SingleCircleStyleElement);